fix: 布局问题

This commit is contained in:
Zhang Muyu
2023-09-16 22:07:08 +08:00
parent fb4d950a60
commit 8f3a0cd65c

View File

@@ -37,12 +37,13 @@ min_width = 250
min_height = 250
space_size = 20
safe_area_size = 8
text_size = 40
content_width = min_width
content_height = min_height + exit_height
content_height = min_height + exit_height + 2 * safe_area_size
data_file_name = 'data5'
data_file_name = input('data file name(./data/*.json):')
data_file_path = './data/{}.json'.format(data_file_name)
svg_file_path = './output/{}.svg'.format(data_file_name)
@@ -78,7 +79,6 @@ for line in lines:
ele_line = []
for item in line:
print(item)
item_type = item.get('type')
item_info = item.get('info')
if item_type == 0:
@@ -124,9 +124,7 @@ for line in lines:
line_heights.append(line_height)
ele_lines.append(ele_line)
content_height = max(content_height, sum(line_heights) + (len(line_heights) + 1) * space_size)
print(content_width, content_height)
content_height = max(content_height, sum(line_heights) + 2 * exit_height + (len(line_heights) + 2) * space_size + 2 * safe_area_size)
# rect
dwg = svgwrite.Drawing(svg_file_path.format(data_file_name), profile='tiny', width=content_width, height=content_height)
@@ -137,19 +135,13 @@ if obj_type == 1:
bg_rect = DoubleStrokeRectComponent(width=content_width, height=content_height - exit_height, main_color='#1f963b', stroke_color='#ffffff', stroke_width=4, r=16)
bg_rect.draw(dwg, 0, exit_height)
valid_height = content_height - 2 * exit_height - space_size
print(valid_height)
valid_height = content_height - 2 * exit_height - 2 * safe_area_size - space_size
real_vertical_space = (valid_height - sum(line_heights)) / (len(line_heights) + 1)
print(real_vertical_space)
current_line_y = exit_height
current_line_y = exit_height + safe_area_size
for (eles, current_line_height) in zip(ele_lines, line_heights):
print(eles, current_line_height)
current_line_y += real_vertical_space
print(current_line_y)
ele_count = len(eles)
real_horizontal_space = (content_width - sum(ele.width() for ele in eles)) / (ele_count + 1)
print(real_horizontal_space)
current_row_x = 0
for ele in eles:
current_row_x += real_horizontal_space
@@ -189,7 +181,7 @@ dst = Image.open(png_file_path)
src = Image.open(src_file_path)
src = src.resize((exit_height, exit_height))
src_x = int((content_width - exit_height) / 2)
src_y = int(content_height - space_size - exit_height)
src_y = int(content_height - space_size - safe_area_size - exit_height)
dst.paste(src, (src_x, src_y))
dst.putalpha(200)
dst.save(png_file_path)