From fb0887cfd7971805955659b73f78b84881f98ad1 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 10 Sep 2019 14:17:05 +0200 Subject: [PATCH 1/4] Fix crash when using currentColor in gradients --- weasyprint/css/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/weasyprint/css/utils.py b/weasyprint/css/utils.py index 847e9a49..aa17862e 100644 --- a/weasyprint/css/utils.py +++ b/weasyprint/css/utils.py @@ -360,6 +360,9 @@ def parse_radial_gradient_parameters(arguments): def parse_color_stop(tokens): if len(tokens) == 1: color = parse_color(tokens[0]) + if color == 'currentColor': + # TODO: return the current color instead + return parse_color('black'), None if color is not None: return color, None elif len(tokens) == 2: From f66df067a1bba4e4926326ada50b7300433700c3 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 10 Sep 2019 14:52:46 +0200 Subject: [PATCH 2/4] Don't crash when using ex units in word-spacing in letter-spacing --- weasyprint/text.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/weasyprint/text.py b/weasyprint/text.py index 20c613a5..826f8a1d 100644 --- a/weasyprint/text.py +++ b/weasyprint/text.py @@ -748,14 +748,18 @@ class Layout(object): self.text = bytestring.decode('utf-8') pango.pango_layout_set_text(self.layout, text, -1) - word_spacing = self.style['word_spacing'] + # Word spacing may not be set if we're trying to get word-spacing + # computed value using a layout, for example if its unit is ex. + word_spacing = self.style.get('word_spacing', 0) if justify: # Justification is needed when drawing text but is useless during # layout. Ignore it before layout is reactivated before the drawing # step. word_spacing += self.justification_spacing - letter_spacing = self.style['letter_spacing'] + # Letter spacing may not be set if we're trying to get letter-spacing + # computed value using a layout, for example if its unit is ex. + letter_spacing = self.style.get('letter_spacing', 'normal') if letter_spacing == 'normal': letter_spacing = 0 From c790ff209418480c8aad9f7a4da22b3549cc38c6 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 10 Sep 2019 15:18:44 +0200 Subject: [PATCH 3/4] Don't crash when properties needing base URL use var functions --- weasyprint/css/computed_values.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/weasyprint/css/computed_values.py b/weasyprint/css/computed_values.py index 9a6a9cb5..a505b02e 100644 --- a/weasyprint/css/computed_values.py +++ b/weasyprint/css/computed_values.py @@ -225,7 +225,11 @@ def compute(element, pseudo_type, specified, computed, parent_style, if computed_value is None: new_value = None else: - new_value = PROPERTIES[name.replace('_', '-')](computed_value) + prop = PROPERTIES[name.replace('_', '-')] + if prop.wants_base_url: + new_value = prop(computed_value, base_url) + else: + new_value = prop(computed_value) # See https://drafts.csswg.org/css-variables/#invalid-variables if new_value is None: From d63eac318133293156d0a4b10a2a92cba177a604 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 10 Sep 2019 15:26:53 +0200 Subject: [PATCH 4/4] Don't crash with object-fit: non images with no intrinsic size --- weasyprint/layout/replaced.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/weasyprint/layout/replaced.py b/weasyprint/layout/replaced.py index f989fa3b..d3fb6263 100644 --- a/weasyprint/layout/replaced.py +++ b/weasyprint/layout/replaced.py @@ -91,8 +91,11 @@ def replacedbox_layout(box): position = box.style['object_position'] image = box.replacement - iwidth, iheight = image.get_intrinsic_size( + intrinsic_width, intrinsic_height = image.get_intrinsic_size( box.style['image_resolution'], box.style['font_size']) + if None in (intrinsic_width, intrinsic_height): + intrinsic_width, intrinsic_height = contain_constraint_image_sizing( + box.width, box.height, box.replacement.intrinsic_ratio) if object_fit == 'fill': draw_width, draw_height = box.width, box.height @@ -105,11 +108,11 @@ def replacedbox_layout(box): box.width, box.height, box.replacement.intrinsic_ratio) else: assert object_fit == 'none', object_fit - draw_width, draw_height = iwidth, iheight + draw_width, draw_height = intrinsic_width, intrinsic_height if object_fit == 'scale-down': - draw_width = min(draw_width, iwidth) - draw_height = min(draw_height, iheight) + draw_width = min(draw_width, intrinsic_width) + draw_height = min(draw_height, intrinsic_height) origin_x, position_x, origin_y, position_y = position[0] ref_x = box.width - draw_width