mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-04 07:57:52 +03:00
Rename layout files to follow "display" values
This commit is contained in:
parent
9a720ac081
commit
35fa9037fd
@ -9,7 +9,7 @@
|
||||
import pytest
|
||||
from weasyprint.css import PageType, get_all_computed_styles
|
||||
from weasyprint.formatting_structure import boxes, build
|
||||
from weasyprint.layout.pages import set_page_type_computed_styles
|
||||
from weasyprint.layout.page import set_page_type_computed_styles
|
||||
|
||||
from .testing_utils import (
|
||||
FakeHTML, assert_no_logs, assert_tree, capture_logs, parse, parse_all,
|
||||
|
@ -14,7 +14,7 @@ from weasyprint import CSS, css, default_url_fetcher
|
||||
from weasyprint.css import (
|
||||
PageType, get_all_computed_styles, parse_page_selectors)
|
||||
from weasyprint.css.computed_values import strut_layout
|
||||
from weasyprint.layout.pages import set_page_type_computed_styles
|
||||
from weasyprint.layout.page import set_page_type_computed_styles
|
||||
from weasyprint.urls import path2url
|
||||
|
||||
from .testing_utils import (
|
||||
|
@ -238,7 +238,7 @@ def find_stylesheets(wrapper_element, device_media_type, url_fetcher, base_url,
|
||||
The output order is the same as the source order.
|
||||
|
||||
"""
|
||||
from ..html import element_has_link_type # Work around circular imports.
|
||||
from ..html import element_has_link_type
|
||||
|
||||
for wrapper in wrapper_element.query_all('style', 'link'):
|
||||
element = wrapper.etree_element
|
||||
|
@ -28,7 +28,7 @@ from .formatting_structure.build import build_formatting_structure
|
||||
from .html import W3C_DATE_RE, get_html_metadata
|
||||
from .images import get_image_from_uri as original_get_image_from_uri
|
||||
from .layout import LayoutContext, layout_document
|
||||
from .layout.percentages import percentage
|
||||
from .layout.percent import percentage
|
||||
from .logger import LOGGER, PROGRESS_LOGGER
|
||||
from .text.ffi import ffi, pango
|
||||
from .text.fonts import FontConfiguration
|
||||
|
@ -15,7 +15,7 @@ from xml.etree import ElementTree
|
||||
from .formatting_structure import boxes
|
||||
from .images import SVGImage
|
||||
from .layout import replaced
|
||||
from .layout.backgrounds import BackgroundLayer
|
||||
from .layout.background import BackgroundLayer
|
||||
from .stacking import StackingContext
|
||||
from .text.ffi import ffi, harfbuzz, pango, units_from_double, units_to_double
|
||||
from .text.line_break import get_last_word_end
|
||||
|
@ -71,7 +71,7 @@ def build_formatting_structure(element_tree, style_for, get_image_from_uri,
|
||||
target_collector.check_pending_targets()
|
||||
|
||||
box.is_for_root_element = True
|
||||
# If this is changed, maybe update weasy.layout.pages.make_margin_boxes()
|
||||
# If this is changed, maybe update weasy.layout.page.make_margin_boxes()
|
||||
process_whitespace(box)
|
||||
box = anonymous_table_boxes(box)
|
||||
box = flex_boxes(box)
|
||||
|
@ -14,7 +14,7 @@ from xml.etree import ElementTree
|
||||
import pydyf
|
||||
from PIL import Image
|
||||
|
||||
from .layout.percentages import percentage
|
||||
from .layout.percent import percentage
|
||||
from .logger import LOGGER
|
||||
from .svg import SVG
|
||||
from .urls import URLFetchingError, fetch
|
||||
|
@ -21,8 +21,8 @@ from functools import partial
|
||||
from ..formatting_structure import boxes
|
||||
from ..logger import PROGRESS_LOGGER
|
||||
from .absolute import absolute_box_layout, absolute_layout
|
||||
from .backgrounds import layout_backgrounds
|
||||
from .pages import make_all_pages, make_margin_boxes
|
||||
from .background import layout_backgrounds
|
||||
from .page import make_all_pages, make_margin_boxes
|
||||
|
||||
|
||||
def initialize_page_maker(context, root_box):
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
from ..formatting_structure import boxes
|
||||
from .min_max import handle_min_max_width
|
||||
from .percentages import resolve_percentages, resolve_position_percentages
|
||||
from .percent import resolve_percentages, resolve_position_percentages
|
||||
from .preferred import shrink_to_fit
|
||||
from .tables import table_wrapper_width
|
||||
from .table import table_wrapper_width
|
||||
|
||||
|
||||
class AbsolutePlaceholder:
|
||||
@ -187,6 +187,8 @@ def absolute_height(box, context, containing_block):
|
||||
|
||||
|
||||
def absolute_block(context, box, containing_block, fixed_boxes):
|
||||
from .block import block_container_layout
|
||||
|
||||
cb_x, cb_y, cb_width, cb_height = containing_block
|
||||
|
||||
translate_box_width, translate_x = absolute_width(
|
||||
@ -200,9 +202,6 @@ def absolute_block(context, box, containing_block, fixed_boxes):
|
||||
if box.is_table_wrapper:
|
||||
table_wrapper_width(context, box, (cb_width, cb_height))
|
||||
|
||||
# avoid a circular import
|
||||
from .blocks import block_container_layout
|
||||
|
||||
new_box, _, _, _, _ = block_container_layout(
|
||||
context, box, max_position_y=float('inf'), skip_stack=None,
|
||||
page_is_empty=False, absolute_boxes=absolute_boxes,
|
||||
@ -223,7 +222,6 @@ def absolute_block(context, box, containing_block, fixed_boxes):
|
||||
|
||||
def absolute_flex(context, box, containing_block_sizes, fixed_boxes,
|
||||
containing_block):
|
||||
# Avoid a circular import
|
||||
from .flex import flex_layout
|
||||
|
||||
# TODO: this function is really close to absolute_block, we should have
|
||||
@ -302,8 +300,8 @@ def absolute_box_layout(context, box, containing_block, fixed_boxes):
|
||||
|
||||
|
||||
def absolute_replaced(context, box, containing_block):
|
||||
# avoid a circular import
|
||||
from .inlines import inline_replaced_box_width_height
|
||||
from .inline import inline_replaced_box_width_height
|
||||
|
||||
inline_replaced_box_width_height(box, containing_block)
|
||||
|
||||
cb_x, cb_y, cb_width, cb_height = containing_block
|
||||
|
@ -9,7 +9,7 @@ from itertools import cycle
|
||||
|
||||
from ..formatting_structure import boxes
|
||||
from . import replaced
|
||||
from .percentages import percentage, resolve_radii_percentages
|
||||
from .percent import percentage, resolve_radii_percentages
|
||||
|
||||
Background = namedtuple('Background', 'color, layers, image_rendering')
|
||||
BackgroundLayer = namedtuple(
|
@ -8,15 +8,15 @@
|
||||
|
||||
from ..formatting_structure import boxes
|
||||
from .absolute import AbsolutePlaceholder, absolute_layout
|
||||
from .columns import columns_layout
|
||||
from .column import columns_layout
|
||||
from .flex import flex_layout
|
||||
from .float import avoid_collisions, float_layout, get_clearance
|
||||
from .inlines import (
|
||||
from .inline import (
|
||||
iter_line_boxes, min_max_auto_replaced, replaced_box_height,
|
||||
replaced_box_width)
|
||||
from .min_max import handle_min_max_width
|
||||
from .percentages import resolve_percentages, resolve_position_percentages
|
||||
from .tables import table_layout, table_wrapper_width
|
||||
from .percent import resolve_percentages, resolve_position_percentages
|
||||
from .table import table_layout, table_wrapper_width
|
||||
|
||||
|
||||
def block_level_layout(context, box, max_position_y, skip_stack,
|
@ -9,15 +9,14 @@
|
||||
from math import floor
|
||||
|
||||
from .absolute import absolute_layout
|
||||
from .percentages import resolve_percentages
|
||||
from .percent import resolve_percentages
|
||||
|
||||
|
||||
def columns_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
page_is_empty, absolute_boxes, fixed_boxes,
|
||||
adjoining_margins):
|
||||
"""Lay out a multi-column ``box``."""
|
||||
# Avoid circular imports
|
||||
from .blocks import (
|
||||
from .block import (
|
||||
block_box_layout, block_level_layout, block_level_width,
|
||||
collapse_margin)
|
||||
|
@ -11,9 +11,9 @@ from math import log10
|
||||
|
||||
from ..css.properties import Dimension
|
||||
from ..formatting_structure import boxes
|
||||
from .percentages import resolve_one_percentage, resolve_percentages
|
||||
from .percent import resolve_one_percentage, resolve_percentages
|
||||
from .preferred import max_content_width, min_content_width
|
||||
from .tables import find_in_flow_baseline
|
||||
from .table import find_in_flow_baseline
|
||||
|
||||
|
||||
class FlexLine(list):
|
||||
@ -22,8 +22,7 @@ class FlexLine(list):
|
||||
|
||||
def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
page_is_empty, absolute_boxes, fixed_boxes):
|
||||
# Avoid a circular import
|
||||
from . import blocks, preferred
|
||||
from . import block, preferred
|
||||
|
||||
context.create_block_formatting_context()
|
||||
resume_at = None
|
||||
@ -101,7 +100,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
if parent_box.margin_right == 'auto':
|
||||
box.margin_right = parent_box.margin_right = 0
|
||||
if isinstance(parent_box, boxes.FlexBox):
|
||||
blocks.block_level_width(parent_box, containing_block)
|
||||
block.block_level_width(parent_box, containing_block)
|
||||
else:
|
||||
parent_box.width = preferred.flex_max_content_width(
|
||||
context, parent_box)
|
||||
@ -154,7 +153,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
new_child.style['height'] = 'auto'
|
||||
new_child.style['min_height'] = Dimension(0, 'px')
|
||||
new_child.style['max_height'] = Dimension(float('inf'), 'px')
|
||||
new_child = blocks.block_level_layout(
|
||||
new_child = block.block_level_layout(
|
||||
context, new_child, float('inf'), child_skip_stack,
|
||||
parent_box, page_is_empty, [], [], [], False)[0]
|
||||
content_size = new_child.height
|
||||
@ -213,7 +212,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
else:
|
||||
new_child = child.copy()
|
||||
new_child.width = float('inf')
|
||||
new_child = blocks.block_level_layout(
|
||||
new_child = block.block_level_layout(
|
||||
context, new_child, float('inf'), child_skip_stack,
|
||||
parent_box, page_is_empty, absolute_boxes, fixed_boxes,
|
||||
adjoining_margins=[], discard=False)[0]
|
||||
@ -228,7 +227,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
else:
|
||||
new_child = child.copy()
|
||||
new_child.width = 0
|
||||
new_child = blocks.block_level_layout(
|
||||
new_child = block.block_level_layout(
|
||||
context, new_child, float('inf'), child_skip_stack,
|
||||
parent_box, page_is_empty, absolute_boxes, fixed_boxes,
|
||||
adjoining_margins=[], discard=False)[0]
|
||||
@ -248,7 +247,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
# Step 4
|
||||
# TODO: the whole step has to be fixed
|
||||
if axis == 'width':
|
||||
blocks.block_level_width(box, containing_block)
|
||||
block.block_level_width(box, containing_block)
|
||||
else:
|
||||
if box.style['height'] != 'auto':
|
||||
box.height = box.style['height'].value
|
||||
@ -460,9 +459,9 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
child_copy = child.copy_with_children(child.children)
|
||||
else:
|
||||
child_copy = child.copy()
|
||||
blocks.block_level_width(child_copy, parent_box)
|
||||
block.block_level_width(child_copy, parent_box)
|
||||
new_child, _, _, adjoining_margins, _ = (
|
||||
blocks.block_level_layout_switch(
|
||||
block.block_level_layout_switch(
|
||||
context, child_copy, float('inf'), child_skip_stack,
|
||||
parent_box, page_is_empty, absolute_boxes, fixed_boxes,
|
||||
adjoining_margins=[], discard=False))
|
||||
@ -473,8 +472,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
# As flex items margins never collapse (with other flex items
|
||||
# or with the flex container), we can add the adjoining margins
|
||||
# to the child bottom margin.
|
||||
child.margin_bottom += blocks.collapse_margin(
|
||||
adjoining_margins)
|
||||
child.margin_bottom += block.collapse_margin(adjoining_margins)
|
||||
else:
|
||||
child.width = min_content_width(context, child, outer=False)
|
||||
|
||||
@ -841,7 +839,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
|
||||
for line in flex_lines:
|
||||
for i, child in line:
|
||||
if child.is_flex_item:
|
||||
new_child, child_resume_at = blocks.block_level_layout_switch(
|
||||
new_child, child_resume_at = block.block_level_layout_switch(
|
||||
context, child, max_position_y, child_skip_stack, box,
|
||||
page_is_empty, absolute_boxes, fixed_boxes,
|
||||
adjoining_margins=[], discard=False)[:2]
|
||||
|
@ -8,9 +8,9 @@
|
||||
|
||||
from ..formatting_structure import boxes
|
||||
from .min_max import handle_min_max_width
|
||||
from .percentages import resolve_percentages, resolve_position_percentages
|
||||
from .percent import resolve_percentages, resolve_position_percentages
|
||||
from .preferred import shrink_to_fit
|
||||
from .tables import table_wrapper_width
|
||||
from .table import table_wrapper_width
|
||||
|
||||
|
||||
@handle_min_max_width
|
||||
@ -23,10 +23,9 @@ def float_width(box, context, containing_block):
|
||||
|
||||
def float_layout(context, box, containing_block, absolute_boxes, fixed_boxes):
|
||||
"""Set the width and position of floating ``box``."""
|
||||
# Avoid circular imports
|
||||
from .blocks import block_container_layout
|
||||
from .block import block_container_layout
|
||||
from .flex import flex_layout
|
||||
from .inlines import inline_replaced_box_width_height
|
||||
from .inline import inline_replaced_box_width_height
|
||||
|
||||
cb_width, cb_height = (containing_block.width, containing_block.height)
|
||||
resolve_percentages(box, (cb_width, cb_height))
|
||||
|
@ -16,10 +16,10 @@ from .absolute import AbsolutePlaceholder, absolute_layout
|
||||
from .flex import flex_layout
|
||||
from .float import avoid_collisions, float_layout
|
||||
from .min_max import handle_min_max_height, handle_min_max_width
|
||||
from .percentages import resolve_one_percentage, resolve_percentages
|
||||
from .percent import resolve_one_percentage, resolve_percentages
|
||||
from .preferred import (
|
||||
inline_min_content_width, shrink_to_fit, trailing_whitespace_size)
|
||||
from .tables import find_in_flow_baseline, table_wrapper_width
|
||||
from .table import find_in_flow_baseline, table_wrapper_width
|
||||
|
||||
|
||||
def iter_line_boxes(context, box, position_y, skip_stack, containing_block,
|
||||
@ -440,7 +440,7 @@ def first_letter_to_box(box, skip_stack, first_letter_style):
|
||||
@handle_min_max_width
|
||||
def replaced_box_width(box, containing_block):
|
||||
"""Set the used width for replaced boxes (inline- or block-level)."""
|
||||
from .blocks import block_level_width
|
||||
from .block import block_level_width
|
||||
|
||||
width, height, ratio = box.replacement.get_intrinsic_size(
|
||||
box.style['image_resolution'], box.style['font_size'])
|
||||
@ -596,8 +596,7 @@ def atomic_box(context, box, position_x, skip_stack, containing_block,
|
||||
|
||||
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
|
||||
from .block import block_container_layout
|
||||
|
||||
resolve_percentages(box, containing_block)
|
||||
|
||||
@ -625,9 +624,9 @@ def inline_block_box_layout(context, box, position_x, skip_stack,
|
||||
|
||||
|
||||
def inline_block_baseline(box):
|
||||
"""
|
||||
Return the y position of the baseline for an inline block
|
||||
from the top of its margin box.
|
||||
"""Return the y position of the baseline for an inline block.
|
||||
|
||||
Position is taken from the top of its margin box.
|
||||
|
||||
http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-align
|
||||
|
@ -12,9 +12,9 @@ from ..css import PageType, computed_from_cascaded
|
||||
from ..formatting_structure import boxes, build
|
||||
from ..logger import PROGRESS_LOGGER
|
||||
from .absolute import absolute_layout
|
||||
from .blocks import block_container_layout, block_level_layout
|
||||
from .block import block_container_layout, block_level_layout
|
||||
from .min_max import handle_min_max_height, handle_min_max_width
|
||||
from .percentages import resolve_percentages
|
||||
from .percent import resolve_percentages
|
||||
from .preferred import max_content_width, min_content_width
|
||||
|
||||
|
@ -374,8 +374,7 @@ def table_and_columns_preferred_widths(context, box, outer=True):
|
||||
http://dbaron.org/css/intrinsic/
|
||||
|
||||
"""
|
||||
# Avoid a circular import
|
||||
from .tables import distribute_excess_width
|
||||
from .table import distribute_excess_width
|
||||
|
||||
table = box.get_wrapped_table()
|
||||
result = context.tables.get(table)
|
||||
@ -732,7 +731,7 @@ def flex_max_content_width(context, box, outer=True):
|
||||
|
||||
def trailing_whitespace_size(context, box):
|
||||
"""Return the size of the trailing whitespace of ``box``."""
|
||||
from .inlines import split_first_line, split_text_box
|
||||
from .inline import split_first_line, split_text_box
|
||||
|
||||
while isinstance(box, (boxes.InlineBox, boxes.LineBox)):
|
||||
if not box.children:
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
"""
|
||||
|
||||
from .percentages import percentage
|
||||
from .percent import percentage
|
||||
|
||||
|
||||
def default_image_sizing(intrinsic_width, intrinsic_height, intrinsic_ratio,
|
||||
|
@ -8,15 +8,14 @@
|
||||
|
||||
from ..formatting_structure import boxes
|
||||
from ..logger import LOGGER
|
||||
from .percentages import resolve_one_percentage, resolve_percentages
|
||||
from .percent import resolve_one_percentage, resolve_percentages
|
||||
from .preferred import max_content_width, table_and_columns_preferred_widths
|
||||
|
||||
|
||||
def table_layout(context, table, max_position_y, skip_stack, containing_block,
|
||||
page_is_empty, absolute_boxes, fixed_boxes):
|
||||
"""Layout for a table box."""
|
||||
# Avoid a circular import
|
||||
from .blocks import (
|
||||
from .block import (
|
||||
block_container_layout, block_level_page_break,
|
||||
find_earlier_page_break)
|
||||
|
||||
@ -526,7 +525,10 @@ def table_layout(context, table, max_position_y, skip_stack, containing_block,
|
||||
|
||||
|
||||
def add_top_padding(box, extra_padding):
|
||||
"""Increase the top padding of a box. This also translates the children.
|
||||
"""Increase the top padding of a box.
|
||||
|
||||
This also translates the children.
|
||||
|
||||
"""
|
||||
box.padding_top += extra_padding
|
||||
for child in box.children:
|
||||
@ -534,7 +536,7 @@ def add_top_padding(box, extra_padding):
|
||||
|
||||
|
||||
def fixed_table_layout(box):
|
||||
"""Run the fixed table layout and return a list of column widths
|
||||
"""Run the fixed table layout and return a list of column widths.
|
||||
|
||||
http://www.w3.org/TR/CSS21/tables.html#fixed-table-layout
|
||||
|
||||
@ -748,8 +750,7 @@ def table_wrapper_width(context, wrapper, containing_block):
|
||||
|
||||
|
||||
def cell_baseline(cell):
|
||||
"""
|
||||
Return the y position of a cell’s baseline from the top of its border box.
|
||||
"""Return the y position of a cell baseline from the top of its border box.
|
||||
|
||||
See http://www.w3.org/TR/CSS21/tables.html#height-layout
|
||||
|
||||
@ -764,9 +765,10 @@ def cell_baseline(cell):
|
||||
|
||||
|
||||
def find_in_flow_baseline(box, last=False, baseline_types=(boxes.LineBox,)):
|
||||
"""
|
||||
Return the absolute Y position for the first (or last) in-flow baseline
|
||||
if any, or None.
|
||||
"""Return the absolute y position for the first (or last) in-flow baseline.
|
||||
|
||||
If there’s no in-flow baseline, return None.
|
||||
|
||||
"""
|
||||
# TODO: synthetize baseline when needed
|
||||
# See https://www.w3.org/TR/css-align-3/#synthesize-baseline
|
Loading…
Reference in New Issue
Block a user