mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 00:21:15 +03:00
Initial support of leaders
This commit is contained in:
parent
8a4a696175
commit
ff9888285c
@ -80,6 +80,7 @@ class Box:
|
||||
transformation_matrix = None
|
||||
bookmark_label = None
|
||||
string_set = None
|
||||
leader_string = None
|
||||
|
||||
# Default, overriden on some subclasses
|
||||
def all_children(self):
|
||||
|
@ -527,6 +527,10 @@ def compute_content_list(content_list, parent_box, counter_values, css_token,
|
||||
get_image_from_uri, target_collector, counter_style,
|
||||
context=context, page=page)
|
||||
boxlist.append(new_box)
|
||||
elif type_ == 'leader()':
|
||||
leader_box = boxes.InlineBox.anonymous_from(parent_box, [])
|
||||
leader_box.leader_string = value[1]
|
||||
boxlist.append(leader_box)
|
||||
text = ''.join(texts)
|
||||
if text:
|
||||
boxlist.append(boxes.TextBox.anonymous_from(parent_box, text))
|
||||
|
@ -49,6 +49,7 @@ def iter_line_boxes(context, box, position_y, skip_stack, containing_block,
|
||||
context, box, position_y, skip_stack, containing_block,
|
||||
absolute_boxes, fixed_boxes, first_letter_style)
|
||||
if line:
|
||||
handle_leaders(context, line, containing_block)
|
||||
position_y = line.position_y + line.height
|
||||
if line is None:
|
||||
return
|
||||
@ -60,6 +61,47 @@ def iter_line_boxes(context, box, position_y, skip_stack, containing_block,
|
||||
first_letter_style = None
|
||||
|
||||
|
||||
def handle_leaders(context, line, containing_block):
|
||||
after_leader = False
|
||||
children = []
|
||||
for child in tuple(line.descendants()):
|
||||
if child.leader_string:
|
||||
after_leader = True
|
||||
available_width = containing_block.width - line.width
|
||||
line.width = containing_block.width
|
||||
child.width = available_width
|
||||
|
||||
text_box = boxes.TextBox.anonymous_from(child, child.leader_string)
|
||||
resolve_percentages(text_box, containing_block)
|
||||
text_box, _, _ = split_text_box(
|
||||
context, text_box, float('inf'), None)
|
||||
|
||||
number_of_leaders = int(line.width // text_box.width)
|
||||
for i in range(number_of_leaders):
|
||||
text_box = boxes.TextBox.anonymous_from(
|
||||
child, child.leader_string)
|
||||
resolve_percentages(text_box, containing_block)
|
||||
text_box, _, _ = split_text_box(
|
||||
context, text_box, float('inf'), None)
|
||||
text_box.position_x = (
|
||||
line.position_x + line.width - ((i + 1) * text_box.width))
|
||||
text_box.position_y = child.position_y
|
||||
|
||||
if text_box.position_x < child.position_x:
|
||||
# Don’t add leaders behind the text on the left
|
||||
continue
|
||||
elif (text_box.position_x + text_box.width >
|
||||
child.position_x + available_width):
|
||||
# Don’t add leaders behind the text on the right
|
||||
continue
|
||||
children.append(text_box)
|
||||
|
||||
child.children = tuple(children)
|
||||
continue
|
||||
if after_leader:
|
||||
child.position_x += available_width
|
||||
|
||||
|
||||
def get_next_linebox(context, linebox, position_y, skip_stack,
|
||||
containing_block, absolute_boxes, fixed_boxes,
|
||||
first_letter_style):
|
||||
|
Loading…
Reference in New Issue
Block a user