openfl / svg

Provides SVG parsing and rendering for OpenFL and Haxe
MIT License
68 stars 30 forks source link

Added CSS2 color parsing: rgb(r, g, b) #37

Closed jcward closed 8 years ago

jcward commented 8 years ago

Per: https://www.w3.org/TR/SVG/types.html#DataTypeColor

Parses both numeric and % values, e.g.: rgb(255,127,0) == rgb(100%, 50%, 0)

Includes testcase.

Side note: We might need the test suite at some point to tolerate a slight difference in pixel color. Especially with opacity and % color -- a pixel is wholly counted as "incorrect" if it is even different by 1 in any R, G or B. This makes it easy to get false negatives by adjusting opacity / percentages in the testcases.

ibilon commented 8 years ago

On the side note: comparing rgb values is bad and not even correct (it's not linear), should use hsl or something similar.

jcward commented 8 years ago

Yes, the 6 matches are intentional. Each of R, G, and B are parsed as integer and optional_%. If you don't use a percent, it's blank (or null in Haxe.) So rgb(255,17%,0) is supported. In CSS you can always write the 0 with or without any units, because 0 == 0% == 0px.

I've added braces.

ashes999 commented 8 years ago

Looks okay to me.

@ibilon ?

ibilon commented 8 years ago

Looks good for me too.