Skip to content

Commit

Permalink
Reduce degree of panic caused by stop-opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Jun 16, 2020
1 parent 403009b commit 32c52ba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/nanoemoji/color_glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ def _parse_radial_gradient(grad_el, shape_bbox, view_box, upem):

def _color_stop(stop_el) -> ColorStop:
offset = _number_or_percentage(stop_el.attrib.get("offset", "0"))
color = stop_el.attrib.get("stop-color", "black")
if "stop-opacity" in stop_el.attrib:
raise ValueError("<stop stop-opacity/> not supported")
return ColorStop(stopOffset=offset, color=Color.fromstring(color))
color = Color.fromstring(stop_el.attrib.get("stop-color", "black"))
opacity = _number_or_percentage(stop_el.attrib.get("stop-opacity", "1"))
color = color._replace(alpha=color.alpha * opacity)
return ColorStop(stopOffset=offset, color=color)


def _common_gradient_parts(el):
Expand Down
2 changes: 1 addition & 1 deletion tests/color_glyph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _round_gradient_coordinates(paint, prec=6):
PaintLinearGradient(
stops=(
ColorStop(stopOffset=0.1, color=Color.fromstring("blue")),
ColorStop(stopOffset=0.9, color=Color.fromstring("cyan")),
ColorStop(stopOffset=0.9, color=Color.fromstring("cyan", 0.8)),
),
p0=Point(200, 800),
p1=Point(800, 800),
Expand Down
2 changes: 1 addition & 1 deletion tests/linear_gradient_rect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/linear_gradient_rect_colr_1.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<StopOffset value="0.9"/>
<Color>
<PaletteIndex value="1"/>
<Transparency value="0.0"/>
<Transparency value="0.2"/>
</Color>
</ColorStop>
</ColorLine>
Expand Down

0 comments on commit 32c52ba

Please sign in to comment.