1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 
   2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 
   5 from librarian import get_resource
 
   6 from librarian.cover import Metric
 
   7 from ..utils.textbox import TextBox, split_words
 
   8 from .base import Widget
 
  11 class TitleBox(Widget):
 
  12     font_size = 159 # 45pt
 
  16     def __init__(self, cover, width, height, lines, scale=1):
 
  20         self.m = Metric(self, cover.m._scale * scale)
 
  21         super().__init__(cover)
 
  24         title_font = PIL.ImageFont.truetype(
 
  25             get_resource('fonts/SourceSans3VF-Roman.ttf'),
 
  27             layout_engine=PIL.ImageFont.Layout.BASIC
 
  29         title_font.set_variation_by_axes([800])
 
  31         lines = self.lines or (int(self.height * (176/200) / self.m.leading) - 0)
 
  36             split_words(self.cover.title),
 
  43         self.margin_top = self.tb.margin_top
 
  45     def build(self, w, h):
 
  46         return self.tb.as_pil_image(self.cover.color_scheme['text'])