Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix floats across pages.

  • Loading branch information...
commit 925669d37c8338d0ff062bd2f3da899d2f969adb 1 parent ebf3723
Simon Sapin authored July 06, 2012
8  weasyprint/document.py
@@ -39,6 +39,7 @@ def __init__(self, dom, enable_hinting, user_stylesheets,
39 39
         self._formatting_structure = None
40 40
         self._pages = None
41 41
         self._excluded_shapes_lists = []
  42
+        self.excluded_shapes = None
42 43
 
43 44
         self.create_block_formatting_context()
44 45
 
@@ -108,16 +109,15 @@ def create_block_formatting_context(self):
108 109
         self._excluded_shapes_lists.append(self.excluded_shapes)
109 110
 
110 111
     def finish_block_formatting_context(self, root_box):
111  
-        excluded_shapes = self._excluded_shapes_lists.pop()
112  
-        self.excluded_shapes = self._excluded_shapes_lists[-1]
113  
-
114 112
         # See http://www.w3.org/TR/CSS2/visudet.html#root-height
115 113
         if root_box.style.height == 'auto':
116 114
             box_bottom = root_box.content_box_y() + root_box.height
117  
-            for shape in excluded_shapes:
  115
+            for shape in self.excluded_shapes:
118 116
                 shape_bottom = shape.position_y + shape.margin_height()
119 117
                 if shape_bottom > box_bottom:
120 118
                     root_box.height += shape_bottom - box_bottom
  119
+        self._excluded_shapes_lists.pop()
  120
+        self.excluded_shapes = self._excluded_shapes_lists[-1]
121 121
 
122 122
     def get_png_pages(self, resolution=None):
123 123
         """Yield (width, height, png_bytes) tuples, one for each page."""
6  weasyprint/layout/pages.py
@@ -488,8 +488,6 @@ def make_page(document, root_box, page_type, resume_at, content_empty):
488 488
     page_width(page, document, cb_width)
489 489
     page_height(page, document, cb_height)
490 490
 
491  
-    document.excluded_shapes = []
492  
-
493 491
     root_box.position_x = page.content_box_x()
494 492
     root_box.position_y = page.content_box_y()
495 493
     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):
498 496
     if content_empty:
499 497
         previous_resume_at = resume_at
500 498
         root_box = root_box.copy_with_children([])
  499
+    else:
  500
+        document.create_block_formatting_context()
501 501
 
502 502
     # TODO: handle cases where the root element is something else.
503 503
     # 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):
517 517
     page = page.copy_with_children([root_box])
518 518
     if content_empty:
519 519
         resume_at = previous_resume_at
  520
+    else:
  521
+        document.finish_block_formatting_context(root_box)
520 522
     return page, resume_at, next_page
521 523
 
522 524
 
27  weasyprint/tests/test_layout.py
@@ -4146,3 +4146,30 @@ def test_floats():
4146 4146
     assert outer_area(img_1) == (0, 0, 50, 50)
4147 4147
     assert outer_area(img_2) == (30, 50, 50, 50)
4148 4148
     assert outer_area(img_3) == (0, 50, 30, 30)
  4149
+
  4150
+    # Floats do no affect other pages
  4151
+    page_1, page_2 = parse('''
  4152
+        <style>
  4153
+            body { width: 90px; font-size: 0 }
  4154
+            img { vertical-align: top }
  4155
+        </style>
  4156
+        <body>
  4157
+        <img src=pattern.png style="float: left; width: 30px" />
  4158
+        <img src=pattern.png style="width: 50px" />
  4159
+        <div style="page-break-before: always"></div>
  4160
+        <img src=pattern.png style="width: 50px" />
  4161
+    ''')
  4162
+    html, = page_1.children
  4163
+    body, = html.children
  4164
+    float_img, anon_block, = body.children
  4165
+    line, = anon_block.children
  4166
+    img_1, = line.children
  4167
+    assert outer_area(float_img) == (0, 0, 30, 30)
  4168
+    assert outer_area(img_1) == (30, 0, 50, 50)
  4169
+
  4170
+    html, = page_2.children
  4171
+    body, = html.children
  4172
+    div, anon_block = body.children
  4173
+    line, = anon_block.children
  4174
+    img_2, = line.children
  4175
+    assert outer_area(img_2) == (0, 0, 50, 50)

0 notes on commit 925669d

Please sign in to comment.
Something went wrong with that request. Please try again.