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])
 
  30         title_font_2 = PIL.ImageFont.truetype(
 
  31             get_resource('fonts/OpenSans-VariableFont_wdth,wght.ttf'),
 
  33             layout_engine=PIL.ImageFont.Layout.BASIC
 
  35         title_font_2.set_variation_by_axes([700, 700])
 
  37             ('\u0590', '\u05FF'): title_font_2,
 
  40         lines = self.lines or (int(self.height * (176/200) / self.m.leading) - 0)
 
  45             split_words(self.cover.title),
 
  51             font_fallbacks=font_fallbacks
 
  53         self.margin_top = self.tb.margin_top
 
  55     def build(self, w, h):
 
  56         return self.tb.as_pil_image(self.cover.color_scheme['text'])