rel
[librarian.git] / src / librarian / cover.py
index ae5f456..dfb0b76 100644 (file)
@@ -289,6 +289,7 @@ class WLCover(Cover):
     background_color = '#444'
     author_color = '#444'
     background_img = get_resource('res/cover.png')
     background_color = '#444'
     author_color = '#444'
     background_img = get_resource('res/cover.png')
+    background_top = False
     format = 'JPEG'
 
     epoch_colors = {
     format = 'JPEG'
 
     epoch_colors = {
@@ -322,11 +323,10 @@ class WLCover(Cover):
             self.bar_width = 0
         else:
             self.bar_color = book_info.cover_bar_color or \
             self.bar_width = 0
         else:
             self.bar_color = book_info.cover_bar_color or \
-                self.epoch_colors.get(book_info.epoch, self.bar_color)
+                self.get_variable_color(book_info) or self.bar_color
         # Set title color.
         if self.set_title_color:
         # Set title color.
         if self.set_title_color:
-            self.title_color = self.epoch_colors.get(book_info.epoch,
-                                                     self.title_color)
+            self.title_color = self.get_variable_color(book_info) or self.title_color
 
         self.bleed = bleed
         self.box_top_margin += bleed
 
         self.bleed = bleed
         self.box_top_margin += bleed
@@ -341,6 +341,9 @@ class WLCover(Cover):
             self.background_img = BytesIO(bg_src.read())
             bg_src.close()
 
             self.background_img = BytesIO(bg_src.read())
             bg_src.close()
 
+    def get_variable_color(self, book_info):
+        return self.epoch_colors.get(book_info.epoch, None)
+
     def pretty_authors(self):
         return [a.upper() for a in self.authors]
 
     def pretty_authors(self):
         return [a.upper() for a in self.authors]
 
@@ -476,7 +479,10 @@ class WLCover(Cover):
                     trg_size[0],
                     int(round(src.size[1] * trg_size[0] / src.size[0]))
                 )
                     trg_size[0],
                     int(round(src.size[1] * trg_size[0] / src.size[0]))
                 )
-                cut = (resized[1] - trg_size[1]) // 2
+                if self.background_top:
+                    cut = 0
+                else:
+                    cut = (resized[1] - trg_size[1]) // 2
                 src = src.resize(resized, Image.ANTIALIAS)
                 src = src.crop((0, cut, src.size[0], src.size[1] - cut))
             else:
                 src = src.resize(resized, Image.ANTIALIAS)
                 src = src.crop((0, cut, src.size[0], src.size[1] - cut))
             else:
@@ -534,7 +540,7 @@ class LogoWLCover(WLCover):
         ]
         self.end_cover_logos = []
         if cover_logo:
         ]
         self.end_cover_logos = []
         if cover_logo:
-            self.end_cover_logos.append(
+            self.additional_cover_logos.append(
                     open(cover_logo, 'rb')
                     )
 
                     open(cover_logo, 'rb')
                     )
 
@@ -731,16 +737,49 @@ class LegimiCover(LogoWLCover):
     ]
     logos_right = False
     gradient_logo_centering = True
     ]
     logos_right = False
     gradient_logo_centering = True
+    background_top = True
+
+    genre_colors = {
+        'Artykuł': '#bf001a',
+        'Artykuł naukowy': '#bf001a',
+        'Dziennik': '#bf001a',
+        'Esej': '#bf001a',
+        'Felieton': '#bf001a',
+        'Kronika': '#bf001a',
+        'List': '#bf001a',
+        'Manifest': '#bf001a',
+        'Odczyt': '#bf001a',
+        'Pamiętnik': '#bf001a',
+        'Poradnik': '#bf001a',
+        'Praca naukowa': '#bf001a',
+        'Publicystyka': '#bf001a',
+        'Reportaż': '#bf001a',
+        'Reportaż podróżniczy': '#bf001a',
+        'Rozprawa': '#bf001a',
+        'Rozprawa polityczna': '#bf001a',
+        'Traktat': '#bf001a',
+    }
+    kind_colors = {
+        'Epika': '#9bbb2b',
+        'Liryka': '#3e626f',
+        'Dramat': '#ecbe00',
+    }
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         if self.has_gradient_logos:
             self.box_bottom_margin += self.box_bottom_margin_logos_add
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         if self.has_gradient_logos:
             self.box_bottom_margin += self.box_bottom_margin_logos_add
-        
-    
+
     def pretty_authors(self):
         return self.authors
 
     def pretty_authors(self):
         return self.authors
 
+    def get_variable_color(self, book_info):
+        for genre in book_info.genres:
+            if genre in self.genre_colors:
+                return self.genre_colors[genre]
+        for kind in book_info.kinds:
+            if kind in self.kind_colors:
+                return self.kind_colors[kind]
 
 class LegimiCornerCover(LegimiCover):
     gradient_logos = []
 
 class LegimiCornerCover(LegimiCover):
     gradient_logos = []