Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def group_layout(group, position_y, max_position_y,
page_is_empty, skip_stack):
resume_at = None
resolve_percentages(group, containing_block=table)
group.position_x = rows_x
group.position_y = position_y
group.width = rows_width
new_group_children = []
# For each rows, cells for which this is the last row (with rowspan)
ending_cells_by_row = [[] for row in group.children]
is_group_start = skip_stack is None
if is_group_start:
skip = 0
else:
skip, skip_stack = skip_stack
assert not skip_stack # No breaks inside rows for now
for index_row, row in group.enumerate_skip(skip):
resolve_percentages(row, containing_block=table)
row.position_x = rows_x
# @margins mustn't manipulate page-context counters
margin_state = copy.deepcopy(state)
quote_depth, counter_values, counter_scopes = margin_state
# TODO: check this, probably useless
counter_scopes.append(set())
build.update_counters(margin_state, box.style)
box.children = build.content_to_boxes(
box.style, box, quote_depth, counter_values,
context.get_image_from_uri, context.target_collector, context,
page)
build.process_whitespace(box)
box = build.anonymous_table_boxes(box)
box = build.flex_boxes(box)
box = build.inline_in_block(box)
box = build.block_in_inline(box)
resolve_percentages(box, containing_block)
if not box.is_generated:
box.width = box.height = 0
for side in ('top', 'right', 'bottom', 'left'):
box._reset_spacing(side)
return box
containing_block, device_size, absolute_boxes,
fixed_boxes, line_placeholders, waiting_floats,
line_children):
"""Fit as much content as possible from an inline-level box in a width.
Return ``(new_box, resume_at, preserved_line_break, first_letter,
last_letter)``. ``resume_at`` is ``None`` if all of the content
fits. Otherwise it can be passed as a ``skip_stack`` parameter to resume
where we left off.
``new_box`` is non-empty (unless the box is empty) and as big as possible
while being narrower than ``available_width``, if possible (may overflow
is no split is possible.)
"""
resolve_percentages(box, containing_block)
if isinstance(box, boxes.TextBox):
box.position_x = position_x
if skip_stack is None:
skip = 0
else:
skip, skip_stack = skip_stack
skip = skip or 0
assert skip_stack is None
new_box, skip, preserved_line_break = split_text_box(
context, box, max_x - position_x, skip)
if skip is None:
resume_at = None
else:
resume_at = (skip, None)
def split_inline_level(context, box, position_x, max_x, skip_stack,
containing_block, absolute_boxes, fixed_boxes,
line_placeholders, waiting_floats, line_children):
"""Fit as much content as possible from an inline-level box in a width.
Return ``(new_box, resume_at, preserved_line_break, first_letter,
last_letter)``. ``resume_at`` is ``None`` if all of the content
fits. Otherwise it can be passed as a ``skip_stack`` parameter to resume
where we left off.
``new_box`` is non-empty (unless the box is empty) and as big as possible
while being narrower than ``available_width``, if possible (may overflow
is no split is possible.)
"""
resolve_percentages(box, containing_block)
float_widths = {'left': 0, 'right': 0}
if isinstance(box, boxes.TextBox):
box.position_x = position_x
if skip_stack is None:
skip = 0
else:
skip, skip_stack = skip_stack
skip = skip or 0
assert skip_stack is None
new_box, skip, preserved_line_break = split_text_box(
context, box, max_x - position_x, skip)
if skip is None:
resume_at = None
else:
def inline_block_box_layout(context, box, position_x, skip_stack,
containing_block, device_size, absolute_boxes,
fixed_boxes):
# Avoid a circular import
from .blocks import block_container_layout
resolve_percentages(box, containing_block)
# http://www.w3.org/TR/CSS21/visudet.html#inlineblock-width
if box.margin_left == 'auto':
box.margin_left = 0
if box.margin_right == 'auto':
box.margin_right = 0
# http://www.w3.org/TR/CSS21/visudet.html#block-root-margin
if box.margin_top == 'auto':
box.margin_top = 0
if box.margin_bottom == 'auto':
box.margin_bottom = 0
inline_block_width(box, context, containing_block)
box.position_x = position_x
box.position_y = 0
absolute_boxes, fixed_boxes, first_letter_style):
"""Return an iterator of ``(line, resume_at)``.
``line`` is a laid-out LineBox with as much content as possible that
fits in the available width.
:param box: a non-laid-out :class:`LineBox`
:param position_y: vertical top position of the line box on the page
:param skip_stack: ``None`` to start at the beginning of ``linebox``,
or a ``resume_at`` value to continue just after an
already laid-out line.
:param containing_block: Containing block of the line box:
a :class:`BlockContainerBox`
"""
resolve_percentages(box, containing_block)
if skip_stack is None:
# TODO: wrong, see https://github.com/Kozea/WeasyPrint/issues/679
resolve_one_percentage(box, 'text_indent', containing_block.width)
else:
box.text_indent = 0
while 1:
line, resume_at = get_next_linebox(
context, box, position_y, skip_stack, containing_block,
absolute_boxes, fixed_boxes, first_letter_style)
if line:
position_y = line.position_y + line.height
if line is None:
return
yield line, resume_at
if resume_at is None:
return
cb = containing_block
# TODO: handle inline boxes (point 10.1.4.1)
# http://www.w3.org/TR/CSS2/visudet.html#containing-block-details
if isinstance(containing_block, boxes.PageBox):
cb_x = cb.content_box_x()
cb_y = cb.content_box_y()
cb_width = cb.width
cb_height = cb.height
else:
cb_x = cb.padding_box_x()
cb_y = cb.padding_box_y()
cb_width = cb.padding_width()
cb_height = cb.padding_height()
containing_block = cb_x, cb_y, cb_width, cb_height
resolve_percentages(box, (cb_width, cb_height))
resolve_position_percentages(box, (cb_width, cb_height))
context.create_block_formatting_context()
# Absolute tables are wrapped into block boxes
if isinstance(box, boxes.BlockBox):
new_box = absolute_block(context, box, containing_block, fixed_boxes)
elif isinstance(box, boxes.FlexContainerBox):
new_box = absolute_flex(
context, box, containing_block, fixed_boxes, cb)
else:
assert isinstance(box, boxes.BlockReplacedBox)
new_box = absolute_replaced(context, box, containing_block)
context.finish_block_formatting_context(new_box)
return new_box
def inline_block_box_layout(context, box, position_x, skip_stack,
containing_block, absolute_boxes, fixed_boxes):
# Avoid a circular import
from .blocks import block_container_layout
resolve_percentages(box, containing_block)
# http://www.w3.org/TR/CSS21/visudet.html#inlineblock-width
if box.margin_left == 'auto':
box.margin_left = 0
if box.margin_right == 'auto':
box.margin_right = 0
# http://www.w3.org/TR/CSS21/visudet.html#block-root-margin
if box.margin_top == 'auto':
box.margin_top = 0
if box.margin_bottom == 'auto':
box.margin_bottom = 0
inline_block_width(box, context, containing_block)
box.position_x = position_x
box.position_y = 0
table.skipped_rows = skipped_rows
# If the height property has a bigger value, just add blank space
# below the last row group.
table.height = max(
table.height if table.height != 'auto' else 0,
position_y - table.content_box_y())
# Layout for column groups and columns
columns_height = position_y - initial_position_y
if table.children:
# The last border spacing is below the columns.
columns_height -= border_spacing_y
for group in table.column_groups:
for column in group.children:
resolve_percentages(column, containing_block=table)
if column.grid_x < len(column_positions):
column.position_x = column_positions[column.grid_x]
column.position_y = initial_position_y
column.width = column_widths[column.grid_x]
column.height = columns_height
else:
# Ignore extra empty columns
column.position_x = 0
column.position_y = 0
column.width = 0
column.height = 0
resolve_percentages(group, containing_block=table)
column.get_cells = get_column_cells(table, column)
first = group.children[0]
last = group.children[-1]
group.position_x = first.position_x