Skip to content

Commit fe1f3d9

Browse files
committed
Fix and test broken absolutes in lines
1 parent 089ffa4 commit fe1f3d9

File tree

2 files changed

+119
-6
lines changed

2 files changed

+119
-6
lines changed

tests/draw/test_absolute.py

+106
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,109 @@ def test_absolute_rtl_4():
527527
<div>bbb</div>
528528
'''
529529
assert_pixels('absolute_rtl_4', 16, 3, expected_pixels, html)
530+
531+
532+
@assert_no_logs
533+
def test_absolute_pages_counter():
534+
expected_pixels = '''
535+
______
536+
_RR___
537+
_RR___
538+
_RR___
539+
_RR___
540+
_____B
541+
______
542+
_RR___
543+
_RR___
544+
_BB___
545+
_BB___
546+
_____B
547+
'''
548+
html = '''
549+
<style>
550+
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
551+
@page {
552+
background: white;
553+
font-family: weasyprint;
554+
margin: 1px;
555+
size: 6px 6px;
556+
@bottom-right-corner {
557+
color: blue;
558+
content: counter(pages);
559+
font-size: 1px;
560+
}
561+
}
562+
body {
563+
color: red;
564+
font-family: weasyprint;
565+
font-size: 2px;
566+
line-height: 1;
567+
orphans: 1;
568+
widows: 1;
569+
}
570+
div {
571+
color: blue;
572+
position: absolute;
573+
}
574+
</style>
575+
a a a <div>a a</div>
576+
'''
577+
assert_pixels('absolute_pages_counter', 6, 12, expected_pixels, html)
578+
579+
580+
@assert_no_logs
581+
def test_absolute_pages_counter_orphans():
582+
expected_pixels = '''
583+
______
584+
_RR___
585+
_RR___
586+
_RR___
587+
_RR___
588+
______
589+
______
590+
______
591+
_____B
592+
______
593+
_RR___
594+
_RR___
595+
_BB___
596+
_BB___
597+
_GG___
598+
_GG___
599+
______
600+
_____B
601+
'''
602+
html = '''
603+
<style>
604+
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
605+
@page {
606+
background: white;
607+
font-family: weasyprint;
608+
margin: 1px;
609+
size: 6px 9px;
610+
@bottom-right-corner {
611+
color: blue;
612+
content: counter(pages);
613+
font-size: 1px;
614+
}
615+
}
616+
body {
617+
color: red;
618+
font-family: weasyprint;
619+
font-size: 2px;
620+
line-height: 1;
621+
orphans: 2;
622+
widows: 2;
623+
}
624+
div {
625+
color: blue;
626+
position: absolute;
627+
}
628+
div ~ div {
629+
color: lime;
630+
}
631+
</style>
632+
a a a <div>a a a</div> a <div>a a a</div>
633+
'''
634+
assert_pixels(
635+
'absolute_pages_counter_orphans', 6, 18, expected_pixels, html)

weasyprint/layout/block.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ def _out_of_flow_layout(context, box, index, child, new_children,
257257
return stop, resume_at, out_of_flow_resume_at
258258

259259

260-
def _break_line(box, new_children, lines_iterator, page_is_empty, index,
261-
skip_stack, resume_at):
260+
def _break_line(context, box, line, new_children, lines_iterator,
261+
page_is_empty, index, skip_stack, resume_at, absolute_boxes,
262+
fixed_boxes):
262263
over_orphans = len(new_children) - box.style['orphans']
263264
if over_orphans < 0 and not page_is_empty:
264265
# Reached the bottom of the page before we had
@@ -277,8 +278,12 @@ def _break_line(box, new_children, lines_iterator, page_is_empty, index,
277278
return True, False, resume_at
278279
if needed and needed <= over_orphans:
279280
# Remove lines to keep them for the next page
281+
for child in new_children[-needed:]:
282+
remove_placeholders(
283+
context, child.children, absolute_boxes, fixed_boxes)
280284
del new_children[-needed:]
281285
# Page break here, resume before this line
286+
remove_placeholders(context, line.children, absolute_boxes, fixed_boxes)
282287
return False, True, {index: skip_stack}
283288

284289

@@ -318,8 +323,9 @@ def _linebox_layout(context, box, index, child, new_children, page_is_empty,
318323
context.overflows_page(bottom_space, new_position_y + offset_y))
319324
if overflow:
320325
abort, stop, resume_at = _break_line(
321-
box, new_children, lines_iterator, page_is_empty, index,
322-
skip_stack, resume_at)
326+
context, box, line, new_children, lines_iterator,
327+
page_is_empty, index, skip_stack, resume_at, absolute_boxes,
328+
fixed_boxes)
323329
break
324330

325331
# TODO: this is incomplete.
@@ -351,8 +357,9 @@ def _linebox_layout(context, box, index, child, new_children, page_is_empty,
351357
context.report_footnote(footnote)
352358
if footnote.style['footnote_policy'] == 'line':
353359
abort, stop, resume_at = _break_line(
354-
box, new_children, lines_iterator, page_is_empty,
355-
index, skip_stack, resume_at)
360+
context, box, line, new_children, lines_iterator,
361+
page_is_empty, index, skip_stack, resume_at,
362+
absolute_boxes, fixed_boxes)
356363
break_linebox = True
357364
elif footnote.style['footnote_policy'] == 'block':
358365
abort = break_linebox = True

0 commit comments

Comments
 (0)