openfl / svg

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

Fixed stroke width, default miter, matrix parsing, added testcase #36

Closed jcward closed 8 years ago

jcward commented 8 years ago

See individual commits:

Created a testcase which exercises all of the above:

image

<svg id="svg1" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" width="256" height="256">
  <rect width="256" height="256" style="fill:#FFF" />
  <rect x="10" y="10" width="100" height="20" style="fill:#f00;stroke:#000;stroke-width:10;" transform="scale(2.0)"/>
  <rect x="30" y="25" width="40" height="20" style="fill:#0f0;stroke:#000;stroke-width:15;" transform="matrix(3.38073983743877, 0.905868727550796, -0.905868727550796, 3.38073983743877, 0, 0)"/>
</svg>
jcward commented 8 years ago

I realize I've done the default joint style slightly wrong for inheritance, but it won't matter until later when the properties are properly inherited. I've said that "not defining a joint style == define as miter" -- but later when they're inherited, inheritance needs to take precedence over this non-definition.

But since property inheritance is currently non-existent, and this is an improvement on the current state, I might take this PR anyway. We're taking baby steps in the right direction. ;)

ashes999 commented 8 years ago

Please review @ibilon

ibilon commented 8 years ago

@jcward do you have an example of matrix string that failed with the previous regex?

Also this seems to have conflict now.

jcward commented 8 years ago

I'll see if I can push an update in the next hour or so.

jcward commented 8 years ago

@ibilon ok, I've fixed the merge conflict and added a simple matrix rotation testcase that will coredump before this matrix regexp fix is in place:

<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <g>
  <title>Layer 1</title>
  <rect fill="#ffffff" x="0" y="0" width="100" height="100" />
  <rect fill="#ff0000" stroke="#000000" stroke-width="0" stroke-dasharray="null" stroke-linejoin="null" stroke-linecap="null" x="-25" y="50" width="50" height="50" transform="matrix(0.7071, -0.7071, 0.7071, 0.7071, 0, 0)" />
 </g>
</svg>

Results in:

>haxe test.hxml 

MUnit Results
------------------------------
Class: SvgGenerationTest ....x.Segmentation fault (core dumped)
Error: Command failed with error 139

Because the old regex captures parses nulls values into the Matrix it creates.

TheSHEEEP commented 8 years ago

Any specific reason not to apply this PR?

ashes999 commented 8 years ago

@TheSHEEEP no reason in particular.

@ibilon does this PR meet your approval? I can merge it if so.

ibilon commented 8 years ago

@ashes999 Sorry forgot about it, all good for me.