X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/4f31482d58fe94543f4aed58dcd8168083f2a1d6..aeb59958474fc1036ac19618fb1bdbdefd52da60:/src/librarian/covers/widgets/author.py diff --git a/src/librarian/covers/widgets/author.py b/src/librarian/covers/widgets/author.py index 5fa3528..db35949 100644 --- a/src/librarian/covers/widgets/author.py +++ b/src/librarian/covers/widgets/author.py @@ -1,3 +1,6 @@ +# This file is part of Librarian, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. +# import PIL.ImageFont from librarian import get_resource from librarian.cover import Metric @@ -18,19 +21,20 @@ class AuthorBox(Widget): author_font = PIL.ImageFont.truetype( get_resource('fonts/SourceSans3VF-Roman.ttf'), self.m.font_size, - layout_engine=PIL.ImageFont.LAYOUT_BASIC + layout_engine=PIL.ImageFont.Layout.BASIC ) author_font.set_variation_by_axes([600]) translator_font = PIL.ImageFont.truetype( get_resource('fonts/SourceSans3VF-Roman.ttf'), self.m.font_size, - layout_engine=PIL.ImageFont.LAYOUT_BASIC + layout_engine=PIL.ImageFont.Layout.BASIC ) translator_font.set_variation_by_axes([400]) authors = [a.readable() for a in self.cover.book_info.authors] translators = [a.readable() for a in self.cover.book_info.translators] + self.textboxes = [] if authors and translators: # Try with two boxes. @@ -130,7 +134,32 @@ class AuthorBox(Widget): self.textboxes = [author_box] - self.margin_top = self.textboxes[0].margin_top + elif translators: + translators_shortened = False + translator_box = None + while translator_box is None: + translator_str = 'tłum. ' + ', '.join(translators) + if translators_shortened: + translator_str += ' i in.' + try: + translator_box = TextBox( + self.width, + self.m.leading * 2, + [translator_str], + translator_font, + 1, + self.m.leading, + 0, + 1, 0 + ) + except DoesNotFit: + translators.pop() + translators_shortened = True + + self.textboxes = [translator_box] + + if self.textboxes: + self.margin_top = self.textboxes[0].margin_top def build(self, w, h): img = PIL.Image.new('RGBA', (self.width, self.m.leading * 2))