2 from librarian import get_resource
 
   3 from librarian.cover import Metric
 
   4 from ..utils.textbox import TextBox, 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]
 
  34         if authors and translators:
 
  35             author_str = ', '.join(authors)
 
  36             translator_str = '(tłum. ' + ', '.join(translators) + ')'
 
  38             parts = [author_str, translator_str]
 
  67             elif len(authors) > 2:
 
  68                 parts = [author + ',' for author in authors[:-1]] + [authors[-1]]
 
  70                 parts = split_words(authors[0])
 
  98         self.margin_top = self.textboxes[0].margin_top
 
 100     def build(self, w, h):
 
 101         img = PIL.Image.new('RGBA', (self.width, self.m.leading * 2))
 
 103         for i, tb in enumerate(self.textboxes):
 
 104             sub_img = tb.as_pil_image(self.cover.color_scheme['text'])
 
 105             img.paste(sub_img, (0, self.m.leading * i), sub_img)