@@ -229,13 +229,13 @@ def __init__(self, style_for, get_image_from_uri, font_config,
229229 self .font_config = font_config
230230 self .counter_style = counter_style
231231 self .target_collector = target_collector
232- self ._excluded_shapes_lists = []
232+ self ._excluded_shapes_root_boxes = []
233+ self ._excluded_shapes = {}
233234 self .footnotes = []
234235 self .page_footnotes = {}
235236 self .current_page_footnotes = []
236237 self .reported_footnotes = []
237238 self .current_footnote_area = None # Not initialized yet
238- self .excluded_shapes = None # Not initialized yet
239239 self .page_bottom = None
240240 self .string_set = defaultdict (lambda : defaultdict (list ))
241241 self .running_elements = defaultdict (lambda : defaultdict (list ))
@@ -257,34 +257,39 @@ def overflows(bottom, position_y):
257257 # The 1e-9 value comes from PEP 485.
258258 return position_y > bottom * (1 + 1e-9 )
259259
260- def create_block_formatting_context ( self ):
261- self . excluded_shapes = []
262- self ._excluded_shapes_lists . append ( self .excluded_shapes )
260+ @ property
261+ def excluded_shapes ( self ):
262+ return self ._excluded_shapes [ self ._excluded_shapes_root_boxes [ - 1 ]]
263263
264- def finish_block_formatting_context (self , root_box ):
264+ @excluded_shapes .setter
265+ def excluded_shapes (self , excluded_shapes ):
266+ self ._excluded_shapes [self ._excluded_shapes_root_boxes [- 1 ]] = excluded_shapes
267+
268+ def create_block_formatting_context (self , root_box , new_list = None ):
269+ assert root_box not in self ._excluded_shapes_root_boxes
270+ self ._excluded_shapes_root_boxes .append (root_box )
271+ if root_box not in self ._excluded_shapes :
272+ self ._excluded_shapes [root_box ] = [] if new_list is None else new_list
273+
274+ def finish_block_formatting_context (self , root_box = None ):
265275 # See https://www.w3.org/TR/CSS2/visudet.html#root-height
266- if root_box .style ['height' ] == 'auto' and self .excluded_shapes :
276+ if root_box and root_box .style ['height' ] == 'auto' and self .excluded_shapes :
267277 box_bottom = root_box .content_box_y () + root_box .height
268278 max_shape_bottom = max ([
269279 shape .position_y + shape .margin_height ()
270280 for shape in self .excluded_shapes ] + [box_bottom ])
271281 root_box .height += max_shape_bottom - box_bottom
272- self ._excluded_shapes_lists .pop ()
273- if self ._excluded_shapes_lists :
274- self .excluded_shapes = self ._excluded_shapes_lists [- 1 ]
275- else :
276- self .excluded_shapes = None
282+ self ._excluded_shapes .pop (self ._excluded_shapes_root_boxes .pop ())
277283
278- def create_flex_formatting_context (self ):
279- self .excluded_shapes = FakeList ()
280- self ._excluded_shapes_lists .append (self .excluded_shapes )
284+ def create_flex_formatting_context (self , root_box ):
285+ self .create_block_formatting_context (root_box , FakeList ())
281286
282287 def finish_flex_formatting_context (self , root_box ):
283- self ._excluded_shapes_lists . pop ( )
284- if self . _excluded_shapes_lists :
285- self . excluded_shapes = self . _excluded_shapes_lists [ - 1 ]
286- else :
287- self .excluded_shapes = None
288+ self .finish_block_formatting_context ( root_box )
289+
290+ def add_broken_out_of_flow ( self , new_box , box , containing_block , resume_at ):
291+ self . broken_out_of_flow [ new_box ] = (
292+ box , containing_block , self ._excluded_shapes_root_boxes [ - 1 ], resume_at )
288293
289294 def get_string_set_for (self , page , name , keyword = 'first' ):
290295 """Resolve value of string function."""
0 commit comments