Change default cover.
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 22 Jun 2023 07:24:44 +0000 (09:24 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 22 Jun 2023 07:24:44 +0000 (09:24 +0200)
setup.py
src/librarian/cover.py
src/librarian/covers/utils/textbox.py
src/librarian/covers/widgets/author.py
src/librarian/covers/widgets/background.py
src/librarian/covers/widgets/base.py

index 267195f..c300f27 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_tree(prefix, path):
 
 setup(
     name='librarian',
-    version='2.5.1',
+    version='2.6',
     description='Converter from WolneLektury.pl XML-based language to XHTML, TXT and other formats',
     author="Marek StÄ™pniowski",
     author_email='marek@stepniowski.com',
index 4fd3d45..0e9b079 100644 (file)
@@ -989,7 +989,7 @@ class FactoryCover(LogoWLCover):
 from librarian.covers.marquise import MarquiseCover, LabelMarquiseCover
 
 COVER_CLASSES = {
-    'default': LogoWLCover,
+    'legacy': LogoWLCover,
     'kmlu': KMLUCover,
     'mpw': MPWCover,
     'atrium': AtriumCover,
@@ -1000,6 +1000,7 @@ COVER_CLASSES = {
     'factory': FactoryCover,
     'm': MarquiseCover,
     'm-label': LabelMarquiseCover,
+    'default': MarquiseCover,
 }
 
 
index a5097ed..cc9c501 100644 (file)
@@ -80,6 +80,8 @@ class TextBox:
     def find_grouping(self, groups, ngroups, glue):
         best = None
         best_var = None
+        if not groups:
+            return []
 
         mean = sum(g[0] for g in groups) + (len(groups) - ngroups) * glue
         if mean > self.width * ngroups:
index 5fa3528..4060999 100644 (file)
@@ -31,6 +31,7 @@ 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]
+        self.textboxes = []
 
         if authors and translators:
             # Try with two boxes.
@@ -130,7 +131,8 @@ class AuthorBox(Widget):
 
             self.textboxes = [author_box]
 
-        self.margin_top = self.textboxes[0].margin_top
+        if self.textboxes:
+            self.margin_top = self.textboxes[0].margin_top
 
     def build(self, w, h):
         img = PIL.Image.new('RGBA', (self.width, self.m.leading * 2))
index 8c9e03b..7836b5c 100644 (file)
@@ -9,6 +9,7 @@ class Background(Widget):
     transparency = False
 
     def setup(self):
+        self.img = None
         if self.cover.book_info.cover_url:
             while True:
                 try:
@@ -34,6 +35,8 @@ class Background(Widget):
             self.img = img
 
     def build(self, w, h):
+        if not self.img:
+            return
         kwadrat = round(max(w, h))
         img = self.img
         img = self.img.resize((kwadrat, kwadrat))
index 15e4462..9c56693 100644 (file)
@@ -14,8 +14,9 @@ class Widget:
 
     def apply(self, img, x, y, w=None, h=None):
         my_img = self.build(w, h)
-        img.paste(
-            my_img,
-            (round(x), round(y - self.margin_top)),
-            my_img if self.transparency else None
-        )
+        if my_img is not None:
+            img.paste(
+                my_img,
+                (round(x), round(y - self.margin_top)),
+                my_img if self.transparency else None
+            )