1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 07:57:52 +03:00

Handle footnote-display

Handling footnote-display requires the footnote area children to be recreated
each time one footnote is added: as footnotes can be blocks or inlines, we have
to create anonymous boxes each time, and thus to do the whole footnote area
layout.
This commit is contained in:
Guillaume Ayoub 2021-12-07 15:58:27 +01:00
parent 232d9eff3b
commit 313a09d10e
5 changed files with 28 additions and 7 deletions

View File

@ -120,6 +120,7 @@ INITIAL_VALUES = {
'bookmark_level': 'none',
'bookmark_state': 'open',
'content': 'normal',
'footnote_display': 'block',
'quotes': list('“”‘’'), # chosen by the user agent
'string_set': 'none',

View File

@ -1457,6 +1457,13 @@ def bookmark_state(keyword):
return keyword in ('open', 'closed')
@property(unstable=True)
@single_keyword
def footnote_display(keyword):
"""Validation for ``bookmark-state``."""
return keyword in ('block', 'inline', 'compact')
@property(unstable=True, wants_base_url=True)
@comma_separated_list
def string_set(tokens, base_url):

View File

@ -134,6 +134,13 @@ def element_to_box(element, style_for, get_image_from_uri, base_url,
if display == ('none',):
return []
if style['float'] == 'footnote':
if style['footnote_display'] == 'block':
style['display'] = ('block', 'flow')
else:
# TODO: handle compact footnotes
style['display'] = ('inline', 'flow')
box = make_box(element.tag, style, [], element)
if state is None:
@ -246,7 +253,6 @@ def element_to_box(element, style_for, get_image_from_uri, base_url,
marker_style, box, quote_depth, counter_values, get_image_from_uri,
target_collector, counter_style)
box.children.insert(0, marker)
box = create_anonymous_boxes(box)
# Specific handling for the element. (eg. replaced element)
return html.handle_element(element, box, get_image_from_uri, base_url)

View File

@ -19,7 +19,7 @@ from collections import defaultdict
from functools import partial
from math import inf
from ..formatting_structure import boxes
from ..formatting_structure import boxes, build
from ..logger import PROGRESS_LOGGER
from .absolute import absolute_box_layout, absolute_layout
from .background import layout_backgrounds
@ -322,9 +322,11 @@ class LayoutContext:
if self.current_footnote_area.height != 'auto':
self.page_bottom += self.current_footnote_area.margin_height()
self.current_footnote_area.children = self.current_page_footnotes
footnote_area = build.create_anonymous_boxes(
self.current_footnote_area.deepcopy())
footnote_area, _, _, _, _ = block_level_layout(
self, self.current_footnote_area, -inf, None,
self.current_footnote_area.page, True, [], [], [], False)
self, footnote_area, -inf, None, self.current_footnote_area.page,
True, [], [], [], False)
self.current_footnote_area.height = footnote_area.height
self.page_bottom -= footnote_area.margin_height()
@ -334,8 +336,10 @@ class LayoutContext:
self.page_bottom += self.current_footnote_area.margin_height()
self.current_footnote_area.children = self.current_page_footnotes
if self.current_footnote_area.children:
footnote_area = build.create_anonymous_boxes(
self.current_footnote_area.deepcopy())
footnote_area, _, _, _, _ = block_level_layout(
self, self.current_footnote_area, -inf, None,
self, footnote_area, -inf, None,
self.current_footnote_area.page, True, [], [], [], False)
self.current_footnote_area.height = footnote_area.height
self.page_bottom -= footnote_area.margin_height()

View File

@ -552,9 +552,11 @@ def make_page(context, root_box, page_type, resume_at, page_number,
if context.reported_footnotes:
footnote_area.children = tuple(context.reported_footnotes)
context.reported_footnotes = []
reported_footnote_area = build.create_anonymous_boxes(
footnote_area.deepcopy())
reported_footnote_area, _, _, _, _ = block_level_layout(
context, footnote_area, -float('inf'), None, footnote_area.page,
True, [], [], [], False)
context, reported_footnote_area, -float('inf'), None,
footnote_area.page, True, [], [], [], False)
footnote_area.height = reported_footnote_area.height
context.page_bottom -= reported_footnote_area.margin_height()
@ -573,6 +575,7 @@ def make_page(context, root_box, page_type, resume_at, page_number,
for absolute_box in positioned_boxes:
absolute_layout(context, absolute_box, page, positioned_boxes)
footnote_area = build.create_anonymous_boxes(footnote_area)
footnote_area, _, _, _, _ = block_level_layout(
context, footnote_area, -float('inf'), None, footnote_area.page,
True, [], [], [], False)