def draw_horizontal_lines(draw, boxes, doc_bounding_box, line_width):
"""Draw black horizontal lines across the page _except_ for that word"""
line_weight_factor = random.triangular(0.005, 1.2)
color = get_color()
start_x = doc_bounding_box[0]
current_y = doc_bounding_box[1]
end_x = doc_bounding_box[2]
end_y = doc_bounding_box[3] - line_width / 2
while current_y < doc_bounding_box[3]:
by0 = current_y
by1 = current_y + line_width
select_boxes = []
for box in boxes:
wy0 = box.position[0][1]
wy1 = box.position[1][1]
if by0 <= wy0 and wy1 <= by1 or \
wy0 <= by1 and by1 <= wy1 or \
wy0 <= by0 and by0 <= wy1:
select_boxes.append(box)
if select_boxes:
x0 = start_x
x1 = end_x
for box in select_boxes:
x1 = box.position[0][0] - BOX_PADDING
draw_line(draw, [x0, current_y, x1, current_y],
line_width=line_width,
line_weight_factor=line_weight_factor, color=color,
dir="h")
x0 = box.position[1][0] + BOX_PADDING
draw_line(draw, [x0 + BOX_PADDING, current_y, end_x, current_y],
line_width=line_width, line_weight_factor=line_weight_factor, dir="h", color=color)
else:
draw_line(draw, [start_x, current_y, end_x, current_y],
line_width=line_width, color=color,
line_weight_factor=line_weight_factor,
dir="h")
current_y = by1
评论列表
文章目录