Skip to content

Commit 3e4c08a

Browse files
committed
SVGData: allow % values for gradient stop offset
Also, don't allow NaN stop offsets
1 parent 90337e7 commit 3e4c08a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

format/svg/SVGData.hx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,21 @@ class SVGData extends Group {
490490

491491
grad.colors.push (getColorStyle ("stop-color", stop, styles, 0x000000));
492492
grad.alphas.push (getFloatStyle ("stop-opacity", stop, styles, 1.0));
493-
grad.ratios.push (Std.int (Std.parseFloat (stop.get ("offset")) * 255.0));
493+
var percent = 0.0;
494+
if (stop.exists("offset")) {
495+
var offset = stop.get("offset");
496+
if (offset.indexOf("%") != -1) {
497+
// 0% - 100%
498+
percent = Std.parseFloat (offset) / 100.0;
499+
} else {
500+
// 0.0 - 1.0
501+
percent = Std.parseFloat(offset);
502+
}
503+
if (Math.isNaN(percent)) {
504+
throw ("Unknown stop offset:" + offset);
505+
}
506+
}
507+
grad.ratios.push (Std.int(percent * 255.0));
494508

495509
}
496510

0 commit comments

Comments
 (0)