Permalink
Browse files

Fix floats across pages.

  • Loading branch information...
1 parent ebf3723 commit 925669d37c8338d0ff062bd2f3da899d2f969adb @SimonSapin committed Jul 6, 2012
Showing with 35 additions and 6 deletions.
  1. +4 −4 weasyprint/document.py
  2. +4 −2 weasyprint/layout/pages.py
  3. +27 −0 weasyprint/tests/test_layout.py
View
@@ -39,6 +39,7 @@ def __init__(self, dom, enable_hinting, user_stylesheets,
self._formatting_structure = None
self._pages = None
self._excluded_shapes_lists = []
+ self.excluded_shapes = None
self.create_block_formatting_context()
@@ -108,16 +109,15 @@ def create_block_formatting_context(self):
self._excluded_shapes_lists.append(self.excluded_shapes)
def finish_block_formatting_context(self, root_box):
- excluded_shapes = self._excluded_shapes_lists.pop()
- self.excluded_shapes = self._excluded_shapes_lists[-1]
-
# See http://www.w3.org/TR/CSS2/visudet.html#root-height
if root_box.style.height == 'auto':
box_bottom = root_box.content_box_y() + root_box.height
- for shape in excluded_shapes:
+ for shape in self.excluded_shapes:
shape_bottom = shape.position_y + shape.margin_height()
if shape_bottom > box_bottom:
root_box.height += shape_bottom - box_bottom
+ self._excluded_shapes_lists.pop()
+ self.excluded_shapes = self._excluded_shapes_lists[-1]
def get_png_pages(self, resolution=None):
"""Yield (width, height, png_bytes) tuples, one for each page."""
@@ -488,8 +488,6 @@ def make_page(document, root_box, page_type, resume_at, content_empty):
page_width(page, document, cb_width)
page_height(page, document, cb_height)
- document.excluded_shapes = []
-
root_box.position_x = page.content_box_x()
root_box.position_y = page.content_box_y()
page_content_bottom = root_box.position_y + page.height
@@ -498,6 +496,8 @@ def make_page(document, root_box, page_type, resume_at, content_empty):
if content_empty:
previous_resume_at = resume_at
root_box = root_box.copy_with_children([])
+ else:
+ document.create_block_formatting_context()
# TODO: handle cases where the root element is something else.
# See http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo
@@ -517,6 +517,8 @@ def make_page(document, root_box, page_type, resume_at, content_empty):
page = page.copy_with_children([root_box])
if content_empty:
resume_at = previous_resume_at
+ else:
+ document.finish_block_formatting_context(root_box)
return page, resume_at, next_page
@@ -4146,3 +4146,30 @@ def test_floats():
assert outer_area(img_1) == (0, 0, 50, 50)
assert outer_area(img_2) == (30, 50, 50, 50)
assert outer_area(img_3) == (0, 50, 30, 30)
+
+ # Floats do no affect other pages
+ page_1, page_2 = parse('''
+ <style>
+ body { width: 90px; font-size: 0 }
+ img { vertical-align: top }
+ </style>
+ <body>
+ <img src=pattern.png style="float: left; width: 30px" />
+ <img src=pattern.png style="width: 50px" />
+ <div style="page-break-before: always"></div>
+ <img src=pattern.png style="width: 50px" />
+ ''')
+ html, = page_1.children
+ body, = html.children
+ float_img, anon_block, = body.children
+ line, = anon_block.children
+ img_1, = line.children
+ assert outer_area(float_img) == (0, 0, 30, 30)
+ assert outer_area(img_1) == (30, 0, 50, 50)
+
+ html, = page_2.children
+ body, = html.children
+ div, anon_block = body.children
+ line, = anon_block.children
+ img_2, = line.children
+ assert outer_area(img_2) == (0, 0, 50, 50)

0 comments on commit 925669d

Please sign in to comment.