X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/716a9ab552bffbb7df2cb31ae41ee196902c7653..261a3308d235fc252f30ae03603d0e964bb60223:/src/librarian/cover.py diff --git a/src/librarian/cover.py b/src/librarian/cover.py index b5996ae..7d7964d 100644 --- a/src/librarian/cover.py +++ b/src/librarian/cover.py @@ -191,7 +191,8 @@ class Cover(object): ) author_font = ImageFont.truetype( - self.author_font_ttf, metr.author_font_size) + self.author_font_ttf, metr.author_font_size, + layout_engine=ImageFont.LAYOUT_BASIC) for pa in self.pretty_authors(): tbox.text(pa, self.author_color, author_font, metr.author_lineskip, self.author_shadow) @@ -204,7 +205,8 @@ class Cover(object): metr.height - top, ) title_font = ImageFont.truetype( - self.title_font_ttf, metr.title_font_size) + self.title_font_ttf, metr.title_font_size, + layout_engine=ImageFont.LAYOUT_BASIC) tbox.text(self.pretty_title(), self.title_color, title_font, metr.title_lineskip, self.title_shadow) text_img = tbox.image() @@ -335,7 +337,8 @@ class WLCover(Cover): box = TextBox(metr.title_box_width, metr.height, padding_y=metr.box_padding_y) author_font = ImageFont.truetype( - self.author_font_ttf, metr.author_font_size) + self.author_font_ttf, metr.author_font_size, + layout_engine=ImageFont.LAYOUT_BASIC) for pa in self.pretty_authors(): box.text(pa, font=author_font, line_height=metr.author_lineskip, color=self.author_color, shadow_color=self.author_shadow) @@ -349,7 +352,8 @@ class WLCover(Cover): # Write title. title_font = ImageFont.truetype( - self.title_font_ttf, metr.title_font_size) + self.title_font_ttf, metr.title_font_size, + layout_engine=ImageFont.LAYOUT_BASIC) box.text(self.pretty_title(), line_height=metr.title_lineskip, font=title_font, @@ -359,10 +363,10 @@ class WLCover(Cover): box_img = box.image() # Find box position. - if self.box_position == 'top': - box_top = metr.box_top_margin - elif self.box_position == 'bottom': + if self.box_position == 'bottom' or box_img.size[1] + metr.box_top_margin + metr.box_bottom_margin > metr.height: box_top = metr.height - metr.box_bottom_margin - box_img.size[1] + elif self.box_position == 'top': + box_top = metr.box_top_margin else: # Middle. box_top = (metr.height - box_img.size[1]) // 2 @@ -466,6 +470,7 @@ class WLNoBoxCover(WLCover): class LogoWLCover(WLCover): gradient_height = 90 gradient_logo_height = 60 + gradient_logo_max_width = 1000 gradient_logo_margin_right = 30 gradient_logo_spacing = 40 gradient_color = '#000' @@ -474,6 +479,8 @@ class LogoWLCover(WLCover): 'res/wl-logo-white.png', 'res/fnp-logo-white.png', ] + annotation = None + annotation_height = 10 def __init__(self, book_info, *args, **kwargs): super(LogoWLCover, self).__init__(book_info, *args, **kwargs) @@ -533,7 +540,10 @@ class LogoWLCover(WLCover): - 2 * metr.gradient_logo_margin_right ) widths = [ - logo.size[0] * metr.gradient_logo_height / logo.size[1] + min( + metr.gradient_logo_max_width, + logo.size[0] * metr.gradient_logo_height / logo.size[1] + ) for logo in logos] taken_space = ( sum(widths) @@ -549,13 +559,36 @@ class LogoWLCover(WLCover): logo = logo.resize( ( int(round(widths[i] * logo_scale)), - int(round(metr.gradient_logo_height * logo_scale)) + int(round( + logo.size[1] * widths[i] / logo.size[0] * logo_scale + )) ), Image.ANTIALIAS) cursor -= logo.size[0] - img.paste(logo, (cursor, logo_top), mask=logo) + img.paste( + logo, + ( + cursor, + int(round(logo_top + (metr.gradient_logo_height - logo.size[1]) * logo_scale / 2)) + ), + mask=logo + ) cursor -= int(round(metr.gradient_logo_spacing * logo_scale)) + if self.annotation: + img2 = Image.new('RGBA', (metr.height, metr.height), color=None) + draw = ImageDraw.Draw(img2) + author_font = ImageFont.truetype( + self.author_font_ttf, metr.annotation_height, + layout_engine=ImageFont.LAYOUT_BASIC) + draw.text((self.annotation_height, self.annotation_height), self.annotation, font=author_font, fill='#FFFFFF') + img2.show() + img2 = img2.rotate(90) + img2.show() + img.putalpha(0) + img.alpha_composite(img2, (0, 0)) + img = img.convert('RGB') + return img @@ -672,11 +705,22 @@ class AtriumCover(LogoWLCover): ] +class BNCover(LogoWLCover): + gradient_logos = [ + 'res/dofinansowano.png', + 'res/MKIDN.jpg', + 'res/BN.png', + 'res/wl-logo-white.png', + ] +# annotation = 'Zadanie „Udostępnienie publikacji w formatach cyfrowych” w ramach Narodowego Programu Rozwoju Czytelnictwa. Dofinansowano ze środków Ministra Kultury, Dziedzictwa Narodowego i Sportu.' + + COVER_CLASSES = { 'default': LogoWLCover, 'kmlu': KMLUCover, 'mpw': MPWCover, 'atrium': AtriumCover, + 'bn': BNCover, }