Add different basic table layouts
This commit is contained in:
parent
0eb57056ba
commit
9dfbe9a142
42
test/fixtures/page_generation/page.py
vendored
42
test/fixtures/page_generation/page.py
vendored
@ -541,6 +541,17 @@ class RecursiveRandomTable(RandomContentRectangle):
|
||||
self.content = Image.new("RGBA", (self.width, self.height), (255, 255, 255, 0))
|
||||
self.background_color = tuple([random.randint(0, 100) for _ in range(4)])
|
||||
self.cell_border_color = (*map(lambda x: int(x * 0.8), self.background_color[:3]), 255)
|
||||
self.layout = random.choice(["closed", "horizontal", "vertical", "open"])
|
||||
|
||||
# Overwrite the layout choice in some cases
|
||||
if self.n_columns == 1 and self.n_rows == 1:
|
||||
self.layout = "closed"
|
||||
elif self.n_columns == 1:
|
||||
self.layout = random.choice(["vertical", "closed"])
|
||||
elif self.n_rows == 1:
|
||||
self.layout = random.choice(["horizontal", "closed"])
|
||||
|
||||
logger.debug(f"Layout: {self.layout}")
|
||||
# self.draw_single_cell_borders(self, border_width, fill=(0, 0, 0, 0))
|
||||
|
||||
def generate_random_table(self):
|
||||
@ -565,14 +576,16 @@ class RecursiveRandomTable(RandomContentRectangle):
|
||||
|
||||
elif size <= Size.MEDIUM.value:
|
||||
|
||||
choice = random.choice(["plot", "plain_table"])
|
||||
choice = random.choice(["plot", "recurse"])
|
||||
|
||||
if choice == "plain_table":
|
||||
return generate_random_table(cell)
|
||||
# cell.content = generate_random_table(inner_region).content
|
||||
# return cell
|
||||
elif choice == "plot": # and is_square_like(cell):
|
||||
# if choice == "plain_table":
|
||||
# return generate_random_table(cell)
|
||||
# # cell.content = generate_random_table(inner_region).content
|
||||
# # return cell
|
||||
if choice == "plot": # and is_square_like(cell):
|
||||
return generate_random_plot(cell)
|
||||
elif choice == "recurse":
|
||||
return generate_recursive_random_table(cell)
|
||||
else:
|
||||
return generate_text_block(cell, f"{choice} {size:.0f} {get_size_class(cell).name}")
|
||||
|
||||
@ -605,7 +618,22 @@ class RecursiveRandomTable(RandomContentRectangle):
|
||||
image = cell.content or Image.new("RGBA", (cell.width, cell.height), (255, 255, 255, 0))
|
||||
assert image.mode == "RGBA"
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.rectangle((0, 0, cell.width - 1, cell.height - 1), fill=fill, outline=self.cell_border_color, width=width)
|
||||
|
||||
# TODO: Refactor
|
||||
if self.layout == "closed":
|
||||
draw.rectangle(
|
||||
(0, 0, cell.width - 1, cell.height - 1), fill=fill, outline=self.cell_border_color, width=width
|
||||
)
|
||||
elif self.layout == "vertical":
|
||||
draw.line((0, 0, 0, cell.height - 1), fill=self.cell_border_color, width=width)
|
||||
draw.line((cell.width - 1, 0, cell.width - 1, cell.height - 1), fill=self.cell_border_color, width=width)
|
||||
elif self.layout == "horizontal":
|
||||
draw.line((0, 0, cell.width - 1, 0), fill=self.cell_border_color, width=width)
|
||||
draw.line((0, cell.height - 1, cell.width - 1, cell.height - 1), fill=self.cell_border_color, width=width)
|
||||
elif self.layout == "open":
|
||||
pass
|
||||
else:
|
||||
raise ValueError(f"Invalid layout '{self.layout}'")
|
||||
cell.content = image
|
||||
assert cell.content.mode == "RGBA"
|
||||
return cell
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user