Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix some little things about absolute blocks

  • Loading branch information...
commit b20022ee11b247702adf00d16a31c5dbccf85aea 1 parent 1fc2da2
@liZe liZe authored
View
27 weasyprint/layout/absolute.py
@@ -41,12 +41,19 @@ def absolute_layout(document, box, containing_block):
top = box.top
bottom = box.bottom
- # 'cb' stands for 'containing block'
cb = containing_block
- cb_x = cb.padding_box_x()
- cb_y = cb.padding_box_y()
- cb_width = cb.padding_width()
- cb_height = cb.padding_height()
+ # TODO: handle inline boxes (point 10.1.4.1)
+ # http://www.w3.org/TR/CSS2/visudet.html#containing-block-details
+ if isinstance(box, boxes.PageBox):
+ cb_x = cb.content_box_x()
+ cb_y = cb.content_box_y()
+ cb_width = cb.padding_width()
+ cb_height = cb.padding_height()
+ else:
+ cb_x = cb.padding_box_x()
+ cb_y = cb.padding_box_y()
+ cb_width = cb.padding_width()
+ cb_height = cb.padding_height()
# http://www.w3.org/TR/CSS2/visudet.html#abs-replaced-width
@@ -85,16 +92,17 @@ def absolute_layout(document, box, containing_block):
box.margin_right = 0
spacing = paddings_plus_borders_x + box.margin_left + box.margin_right
if left == width == 'auto':
- box.width = shrink_to_fit(box, cb.width - spacing - right)
+ box.width = shrink_to_fit(box, cb_width - spacing - right)
translate_x = cb_width - right - spacing + default_translate_x
translate_box_width = True
elif left == right == 'auto':
pass # Keep the static position
elif width == right == 'auto':
- box.width = shrink_to_fit(box, cb.width - spacing - left)
+ box.width = shrink_to_fit(box, cb_width - spacing - left)
translate_x = left + default_translate_x
elif left == 'auto':
- translate_x = cb_width - right - spacing + default_translate_x - width
+ translate_x = (
+ cb_width - right - spacing + default_translate_x - width)
elif width == 'auto':
box.width = cb_width - right - left - spacing
translate_x = left + default_translate_x
@@ -133,7 +141,8 @@ def absolute_layout(document, box, containing_block):
elif height == bottom == 'auto':
translate_y = top + default_translate_y
elif top == 'auto':
- translate_y = cb_height + default_translate_y - bottom - spacing - height
+ translate_y = (
+ cb_height + default_translate_y - bottom - spacing - height)
elif height == 'auto':
box.height = cb_height - bottom - top - spacing
translate_y = top + default_translate_y
View
11 weasyprint/layout/blocks.py
@@ -235,7 +235,7 @@ def block_container_layout(document, box, max_position_y, skip_stack,
absolute_boxes.append(child)
continue
- if child.style.position in ('relative', 'fixed'):
+ if child.style.position == 'relative':
# New containing block, use a new absolute list
old_absolute_boxes = absolute_boxes
absolute_boxes = []
@@ -355,7 +355,7 @@ def block_container_layout(document, box, max_position_y, skip_stack,
resume_at = (index, resume_at)
break
- if child.style.position in ('relative', 'fixed'):
+ if child.style.position == 'relative':
absolute_boxes = old_absolute_boxes
else:
@@ -408,14 +408,13 @@ def block_container_layout(document, box, max_position_y, skip_stack,
for child in new_box.children:
relative_positioning(child, new_box)
- # TODO: don't rely on the html element tag to detect the root box
- if (new_box.style.position in ('relative', 'fixed')) or new_box.element_tag == 'html':
+ if new_box.style.position == 'relative':
# New containing block, resolve the layout of the absolute descendants
# TODO: avoid this (circular import)
from .absolute import absolute_layout
for absolute_box in absolute_boxes:
- absolute_box.new_box = absolute_layout(document, absolute_box, new_box)
- new_box.children += (absolute_box.new_box,)
+ new_box.children += (
+ absolute_layout(document, absolute_box, new_box),)
if resume_at is not None:
# If there was a list marker, we kept it on `new_box`.
View
11 weasyprint/layout/pages.py
@@ -14,6 +14,7 @@
from ..logger import LOGGER
from ..formatting_structure import boxes, build
+from .absolute import absolute_layout
from .blocks import block_level_layout, block_container_layout
from .percentages import resolve_percentages
from .preferred import inline_preferred_minimum_width, inline_preferred_width
@@ -487,13 +488,19 @@ def make_page(document, root_box, page_type, resume_at):
assert isinstance(root_box, boxes.BlockBox)
page_is_empty = True
adjoining_margins = []
+ absolute_boxes = []
root_box, resume_at, next_page, _, _ = block_level_layout(
document, root_box, page_content_bottom, resume_at,
initial_containing_block, device_size, page_is_empty,
- [], adjoining_margins)
+ absolute_boxes, adjoining_margins)
assert root_box
- page = page.copy_with_children([root_box])
+ children = [root_box]
+
+ for absolute_box in absolute_boxes:
+ children.append(absolute_layout(document, absolute_box, page))
+
+ page = page.copy_with_children(children)
return page, resume_at, next_page
Please sign in to comment.
Something went wrong with that request. Please try again.