2 from librarian import get_resource
3 from librarian.cover import Metric
4 from ..utils.textbox import TextBox, DoesNotFit, split_words
5 from .base import Widget
8 class AuthorBox(Widget):
12 def __init__(self, cover, width):
14 self.m = Metric(self, cover.m._scale)
15 super().__init__(cover)
18 author_font = PIL.ImageFont.truetype(
19 get_resource('fonts/SourceSans3VF-Roman.ttf'),
21 layout_engine=PIL.ImageFont.LAYOUT_BASIC
23 author_font.set_variation_by_axes([600])
25 translator_font = PIL.ImageFont.truetype(
26 get_resource('fonts/SourceSans3VF-Roman.ttf'),
28 layout_engine=PIL.ImageFont.LAYOUT_BASIC
30 translator_font.set_variation_by_axes([400])
32 authors = [a.readable() for a in self.cover.book_info.authors]
33 translators = [a.readable() for a in self.cover.book_info.translators]
35 authors_written = False
36 if authors and translators:
37 author_str = ', '.join(authors)
38 translator_str = '(tłum. ' + ', '.join(translators) + ')'
40 parts = [author_str, translator_str]
68 authors_written = True
70 if not authors_written:
74 elif len(authors) > 2:
75 parts = [author + ',' for author in authors[:-1]] + [authors[-1]]
77 parts = split_words(authors[0])
105 self.margin_top = self.textboxes[0].margin_top
107 def build(self, w, h):
108 img = PIL.Image.new('RGBA', (self.width, self.m.leading * 2))
110 for i, tb in enumerate(self.textboxes):
111 sub_img = tb.as_pil_image(self.cover.color_scheme['text'])
112 img.paste(sub_img, (0, self.m.leading * i), sub_img)