Skip to content

Commit eef8b4d

Browse files
committed
Always set color and state before drawing
That’s required as per Figure 9 of PDF 32000-1:2008.
1 parent c215697 commit eef8b4d

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

weasyprint/draw.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ def draw_background(stream, bg, clip_box=True, bleed=None, marks=()):
246246
# Background color
247247
if bg.color.alpha > 0:
248248
with stacked(stream):
249+
stream.set_color_rgb(*bg.color[:3])
250+
stream.set_alpha(bg.color.alpha)
249251
painting_area = bg.layers[-1].painting_area
250252
if painting_area:
251253
if bleed:
@@ -259,8 +261,6 @@ def draw_background(stream, bg, clip_box=True, bleed=None, marks=()):
259261
stream.clip()
260262
stream.end()
261263
stream.rectangle(*stream.page_rectangle)
262-
stream.set_color_rgb(*bg.color[:3])
263-
stream.set_alpha(bg.color.alpha)
264264
stream.fill()
265265

266266
if bleed and marks:
@@ -686,37 +686,38 @@ def draw_dots(dashes, line, way, x, y, px, py, chl):
686686

687687

688688
def draw_rounded_border(stream, box, style, color):
689-
rounded_box_path(stream, box.rounded_padding_box())
690689
if style in ('ridge', 'groove'):
691-
rounded_box_path(stream, box.rounded_box_ratio(1 / 2))
692690
stream.set_color_rgb(*color[0][:3])
693691
stream.set_alpha(color[0][3])
694-
stream.fill(even_odd=True)
692+
rounded_box_path(stream, box.rounded_padding_box())
695693
rounded_box_path(stream, box.rounded_box_ratio(1 / 2))
696-
rounded_box_path(stream, box.rounded_border_box())
694+
stream.fill(even_odd=True)
697695
stream.set_color_rgb(*color[1][:3])
698696
stream.set_alpha(color[1][3])
697+
rounded_box_path(stream, box.rounded_box_ratio(1 / 2))
698+
rounded_box_path(stream, box.rounded_border_box())
699699
stream.fill(even_odd=True)
700700
return
701+
stream.set_color_rgb(*color[:3])
702+
stream.set_alpha(color[3])
703+
rounded_box_path(stream, box.rounded_padding_box())
701704
if style == 'double':
702705
rounded_box_path(stream, box.rounded_box_ratio(1 / 3))
703706
rounded_box_path(stream, box.rounded_box_ratio(2 / 3))
704707
rounded_box_path(stream, box.rounded_border_box())
705-
stream.set_color_rgb(*color[:3])
706-
stream.set_alpha(color[3])
707708
stream.fill(even_odd=True)
708709

709710

710711
def draw_rect_border(stream, box, widths, style, color):
711712
bbx, bby, bbw, bbh = box
712713
bt, br, bb, bl = widths
713-
stream.rectangle(*box)
714714
if style in ('ridge', 'groove'):
715+
stream.set_color_rgb(*color[0][:3])
716+
stream.set_alpha(color[0][3])
717+
stream.rectangle(*box)
715718
stream.rectangle(
716719
bbx + bl / 2, bby + bt / 2,
717720
bbw - (bl + br) / 2, bbh - (bt + bb) / 2)
718-
stream.set_color_rgb(*color[0][:3])
719-
stream.set_alpha(color[0][3])
720721
stream.fill(even_odd=True)
721722
stream.rectangle(
722723
bbx + bl / 2, bby + bt / 2,
@@ -726,6 +727,9 @@ def draw_rect_border(stream, box, widths, style, color):
726727
stream.set_alpha(color[1][3])
727728
stream.fill(even_odd=True)
728729
return
730+
stream.set_color_rgb(*color[:3])
731+
stream.set_alpha(color[3])
732+
stream.rectangle(*box)
729733
if style == 'double':
730734
stream.rectangle(
731735
bbx + bl / 3, bby + bt / 3,
@@ -734,8 +738,6 @@ def draw_rect_border(stream, box, widths, style, color):
734738
bbx + bl * 2 / 3, bby + bt * 2 / 3,
735739
bbw - (bl + br) * 2 / 3, bbh - (bt + bb) * 2 / 3)
736740
stream.rectangle(bbx + bl, bby + bt, bbw - bl - br, bbh - bt - bb)
737-
stream.set_color_rgb(*color[:3])
738-
stream.set_alpha(color[3])
739741
stream.fill(even_odd=True)
740742

741743

0 commit comments

Comments
 (0)