mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 00:21:15 +03:00
Add basic management of float elements
This commit is contained in:
parent
e648919f81
commit
44adb875e3
@ -328,6 +328,18 @@ def border_width(computer, name, value):
|
||||
return length(computer, name, value, pixels_only=True)
|
||||
|
||||
|
||||
@register_computer('clear')
|
||||
def clear(computer, name, values):
|
||||
"""Compute the ``clear`` property."""
|
||||
return values
|
||||
|
||||
|
||||
@register_computer('float')
|
||||
def float(computer, name, values):
|
||||
"""Compute the ``float`` property."""
|
||||
return values
|
||||
|
||||
|
||||
@register_computer('content')
|
||||
def content(computer, name, values):
|
||||
"""Compute the ``content`` property."""
|
||||
|
@ -330,6 +330,13 @@ def caption_side(keyword):
|
||||
return keyword in ('top', 'bottom')
|
||||
|
||||
|
||||
@validator()
|
||||
@single_keyword
|
||||
def clear(keyword):
|
||||
"""``clear`` property validation."""
|
||||
return keyword in ('left', 'right', 'both', 'none')
|
||||
|
||||
|
||||
@validator()
|
||||
@single_token
|
||||
def clip(token):
|
||||
@ -498,6 +505,13 @@ def display(keyword):
|
||||
'table-row', 'table-column-group', 'table-column', 'table-cell')
|
||||
|
||||
|
||||
@validator()
|
||||
@single_keyword
|
||||
def float(keyword):
|
||||
"""``float`` property validation."""
|
||||
return keyword in ('left', 'right', 'none')
|
||||
|
||||
|
||||
@validator()
|
||||
def font_family(tokens):
|
||||
"""``font-family`` property validation."""
|
||||
|
@ -13,6 +13,7 @@
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
from .absolute import absolute_layout, AbsolutePlaceholder
|
||||
from .float import float_layout, FloatPlaceholder
|
||||
from .inlines import (iter_line_boxes, replaced_box_width, replaced_box_height,
|
||||
handle_min_max_width, min_max_replaced_height,
|
||||
min_max_auto_replaced)
|
||||
@ -225,6 +226,7 @@ def block_container_layout(document, box, max_position_y, skip_stack,
|
||||
absolute_boxes = []
|
||||
|
||||
new_children = []
|
||||
float_children = []
|
||||
next_page = 'any'
|
||||
|
||||
is_start = skip_stack is None
|
||||
@ -247,9 +249,10 @@ def block_container_layout(document, box, max_position_y, skip_stack,
|
||||
new_children.append(placeholder)
|
||||
else:
|
||||
document.fixed_boxes.append(placeholder)
|
||||
else:
|
||||
# TODO: Floats
|
||||
new_children.append(child)
|
||||
elif child.style.float in ('left', 'right'):
|
||||
placeholder = FloatPlaceholder(child)
|
||||
float_children.append(placeholder)
|
||||
new_children.append(placeholder)
|
||||
continue
|
||||
|
||||
if isinstance(child, boxes.LineBox):
|
||||
@ -427,6 +430,9 @@ def block_container_layout(document, box, max_position_y, skip_stack,
|
||||
for absolute_box in absolute_boxes:
|
||||
absolute_layout(document, absolute_box, new_box)
|
||||
|
||||
for float_box in float_children:
|
||||
float_layout(document, float_box, new_box, absolute_boxes)
|
||||
|
||||
for child in new_box.children:
|
||||
relative_positioning(child, (new_box.width, new_box.height))
|
||||
|
||||
|
@ -14,6 +14,7 @@ import operator
|
||||
|
||||
from .formatting_structure import boxes
|
||||
from .layout.absolute import AbsolutePlaceholder
|
||||
from .layout.float import FloatPlaceholder
|
||||
|
||||
|
||||
_Z_INDEX_GETTER = operator.attrgetter('z_index')
|
||||
@ -68,7 +69,7 @@ class StackingContext(object):
|
||||
blocks_and_cells = []
|
||||
|
||||
def dispatch_children(box):
|
||||
if isinstance(box, AbsolutePlaceholder):
|
||||
if isinstance(box, (AbsolutePlaceholder, FloatPlaceholder)):
|
||||
box = box._box
|
||||
|
||||
if not isinstance(box, boxes.ParentBox):
|
||||
|
Loading…
Reference in New Issue
Block a user