Remove legacy code for txt.
[librarian.git] / src / librarian / covers / widgets / marquise.py
1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 import PIL.Image
5 from .base import Widget
6
7
8 class Marquise(Widget):
9     segments = 4
10
11     def __init__(self, cover, edge_top):
12         self.edge_top = edge_top
13         super().__init__(cover)
14
15     def setup(self):
16         self.slope_w = self.cover.m.width / self.segments / 2
17         self.segment_h = self.cover.m.margin
18         self.title_box_position = (
19             self.cover.m.margin,
20             self.cover.m.title_box_top
21         )
22
23     def get_points(self, w):
24         tip_y = self.edge_top + self.segment_h
25         points = [
26             (0, 0),
27             (w, 0),
28             (w, tip_y),
29         ]
30         for i in range(self.segments - 1, 0, -1):
31             points.extend([
32                 ((2 * i + 1) * self.slope_w, self.edge_top),
33                 (2 * i * self.slope_w, tip_y)
34             ])
35         points.extend([
36             (self.slope_w, self.edge_top),
37             (0, tip_y)
38         ])
39         return points
40
41     def build(self, w, h):
42         img = PIL.Image.new('RGBA', (
43             round(w), round(self.edge_top + self.segment_h)
44         ))
45         draw = PIL.ImageDraw.ImageDraw(img)
46         draw.polygon(
47             self.get_points(w), fill=self.cover.color_scheme['rgb'])
48         return img