Marquise: scale title text in all layouts. 2.4.12
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 4 May 2023 10:21:44 +0000 (12:21 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 4 May 2023 10:27:56 +0000 (12:27 +0200)
setup.py
src/librarian/covers/marquise.py
src/librarian/covers/widgets/title.py

index 1502037..44ab5ee 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_tree(prefix, path):
 
 setup(
     name='librarian',
-    version='2.4.11.1',
+    version='2.4.12',
     description='Converter from WolneLektury.pl XML-based language to XHTML, TXT and other formats',
     author="Marek StÄ™pniowski",
     author_email='marek@stepniowski.com',
index fb84a79..d0ce49e 100644 (file)
@@ -99,20 +99,25 @@ class MarquiseCover(Cover):
                 (self.m.marquise_xl, None),
             ]
 
-        for marquise_h, lines in layout_options:
-            title_box_height = marquise_h - self.m.title_box_top - self.m.margin
-            try:
-                title_box = TitleBox(
-                    self,
-                    self.m.width - 2 * self.m.margin,
-                    title_box_height,
-                    lines,
-                    force=lines is None
-                )
-            except DoesNotFit:
-                continue
-            else:
-                break
+        # Trying all the layout options with decreasing scale.
+        title_box = None
+        title_scale = 1
+        while title_box is None:
+            for marquise_h, lines in layout_options:
+                title_box_height = marquise_h - self.m.title_box_top - self.m.margin
+                try:
+                    title_box = TitleBox(
+                        self,
+                        self.m.width - 2 * self.m.margin,
+                        title_box_height,
+                        lines,
+                        scale=title_scale
+                    )
+                except DoesNotFit:
+                    continue
+                else:
+                    break
+            title_scale *= .99
 
         self.marquise_height = marquise_h
         marquise = Marquise(self, marquise_h)
index a5c6522..7d070ca 100644 (file)
@@ -10,29 +10,14 @@ class TitleBox(Widget):
     leading = 176  # 50pt
     tracking = 2.385
 
-    def __init__(self, cover, width, height, lines, force=False):
+    def __init__(self, cover, width, height, lines, scale=1):
         self.width = width
         self.height = height
         self.lines = lines
-        self.force = force
-        self.m = Metric(self, cover.m._scale)
+        self.m = Metric(self, cover.m._scale * scale)
         super().__init__(cover)
 
     def setup(self):
-        m = self.m
-        while True:
-            try:
-                self.build_box()
-            except:
-                if self.force:
-                    self.m = Metric(self, self.m._scale * .99)
-                    print('lower to', self.m.font_size)
-                else:
-                    raise
-            else:
-                break
-
-    def build_box(self):
         title_font = PIL.ImageFont.truetype(
             get_resource('fonts/SourceSans3VF-Roman.ttf'),
             self.m.font_size,