Skip to content

Commit

Permalink
SVGData: allow % values for gradient stop offset
Browse files Browse the repository at this point in the history
Also, don't allow NaN stop offsets
  • Loading branch information
joshtynjala committed Feb 22, 2025
1 parent 90337e7 commit 3e4c08a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion format/svg/SVGData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,21 @@ class SVGData extends Group {

grad.colors.push (getColorStyle ("stop-color", stop, styles, 0x000000));
grad.alphas.push (getFloatStyle ("stop-opacity", stop, styles, 1.0));
grad.ratios.push (Std.int (Std.parseFloat (stop.get ("offset")) * 255.0));
var percent = 0.0;
if (stop.exists("offset")) {
var offset = stop.get("offset");
if (offset.indexOf("%") != -1) {
// 0% - 100%
percent = Std.parseFloat (offset) / 100.0;
} else {
// 0.0 - 1.0
percent = Std.parseFloat(offset);
}
if (Math.isNaN(percent)) {
throw ("Unknown stop offset:" + offset);
}
}
grad.ratios.push (Std.int(percent * 255.0));

}

Expand Down

0 comments on commit 3e4c08a

Please sign in to comment.