From 384f0e5f281da8a08e32fe6d97393b99d01cd0e3 Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Wed, 18 Jan 2023 13:42:38 +0100 Subject: [PATCH] [WIP] recursive random table: tweak cell broder and fill logic --- test/fixtures/page_generation/page.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/fixtures/page_generation/page.py b/test/fixtures/page_generation/page.py index 29e2f63..296dcb4 100644 --- a/test/fixtures/page_generation/page.py +++ b/test/fixtures/page_generation/page.py @@ -441,17 +441,16 @@ class RecursiveRandomTable(RandomContentRectangle): self.n_columns = max(self.width // 100, 1) self.n_rows = max(self.height // 17, 1) self.cell_size = (self.width // self.n_columns, self.height // self.n_rows) - logger.debug(f"RecursiveRandomTable({self.n_columns}, {self.n_rows}, {self.cell_size}) at {self}") - self.content = Image.new("RGB", (self.width, self.height), (255, 255, 255)) - self.draw = ImageDraw.Draw(self.content) + + self.content = Image.new("RGBA", (self.width, self.height), (255, 255, 255, 255)) + self.background_color = tuple([random.randint(100, 200) for _ in range(4)]) + self.cell_border_color = tuple(map(lambda x: int(x * 0.8), self.background_color[:3])) def generate_random_table(self): + self.draw_single_cell_borders(self, 3) cells = list(self.generate_cells_with_content()) self.content = paste_contents(self.content, cells) - # convert to RGBA - self.content = self.content.convert("RGBA") assert self.content.mode == "RGBA" - # self.draw_cell_borders(cells) def generate_cells_with_content(self): for cell in self.generate_table(): @@ -466,10 +465,12 @@ class RecursiveRandomTable(RandomContentRectangle): for cell in cells: self.draw_single_cell_borders(cell) - def draw_single_cell_borders(self, cell: ContentRectangle): + def draw_single_cell_borders(self, cell: ContentRectangle, width=1): image = cell.content or Image.new("RGBA", (cell.width, cell.height), (255, 255, 255)) draw = ImageDraw.Draw(image) - draw.rectangle((0, 0, cell.width, cell.height), fill=(126, 178, 231, 50), outline=(1, 1, 1), width=2) + draw.rectangle( + (0, 0, cell.width, cell.height), fill=self.background_color, outline=self.cell_border_color, width=width + ) cell.content = image assert cell.content.mode == "RGBA" return cell