From: Radek Czajka Date: Fri, 15 Jul 2022 11:27:27 +0000 (+0200) Subject: Only write translators on cover if they fit. X-Git-Tag: 2.4.7~1 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/aceaf70338e678b35bffbb377286cf9ce3b5e81d?ds=inline;hp=65ef0306d24eb3126c9f72b89ed021121b40ae2f Only write translators on cover if they fit. --- diff --git a/src/librarian/covers/marquise.py b/src/librarian/covers/marquise.py index d1f832c..fb84a79 100644 --- a/src/librarian/covers/marquise.py +++ b/src/librarian/covers/marquise.py @@ -17,6 +17,8 @@ class MarquiseCover(Cover): height = 2970 margin = 100 logo_h = 177 + author_width = 1300 + title_box_top = 262 color_schemes = [ @@ -138,8 +140,8 @@ class MarquiseCover(Cover): marquise.title_box_position[1], ) - AuthorBox(self, self.m.width - self.m.margin).apply( - img, 0, self.m.margin + AuthorBox(self, self.m.author_width).apply( + img, self.m.width - self.m.margin - self.m.author_width, self.m.margin ) WLLogo(self).apply(img, self.m.margin, self.m.margin, None, self.m.logo_h) diff --git a/src/librarian/covers/widgets/author.py b/src/librarian/covers/widgets/author.py index 786204c..162215f 100644 --- a/src/librarian/covers/widgets/author.py +++ b/src/librarian/covers/widgets/author.py @@ -1,7 +1,7 @@ import PIL.ImageFont from librarian import get_resource from librarian.cover import Metric -from ..utils.textbox import TextBox, split_words +from ..utils.textbox import TextBox, DoesNotFit, split_words from .base import Widget @@ -31,36 +31,43 @@ class AuthorBox(Widget): authors = [a.readable() for a in self.cover.book_info.authors] translators = [a.readable() for a in self.cover.book_info.translators] + + authors_written = False if authors and translators: author_str = ', '.join(authors) translator_str = '(tłum. ' + ', '.join(translators) + ')' # just print parts = [author_str, translator_str] - self.textboxes = [ - TextBox( - self.width, - self.m.leading * 2, - [author_str], - author_font, - 1, - self.m.leading, - 0, - 1, 0 - ), - TextBox( - self.width, - self.m.leading * 2, - [translator_str], - translator_font, - 1, - self.m.leading, - 0, - 1, 0 - ) - ] + try: + self.textboxes = [ + TextBox( + self.width, + self.m.leading * 2, + [author_str], + author_font, + 1, + self.m.leading, + 0, + 1, 0 + ), + TextBox( + self.width, + self.m.leading * 2, + [translator_str], + translator_font, + 1, + self.m.leading, + 0, + 1, 0 + ) + ] + except DoesNotFit: + pass + else: + authors_written = True - else: + if not authors_written: assert authors if len(authors) == 2: parts = authors