SVGKit / SVGKit

Display and interact with SVG Images on iOS / OS X, using native rendering (CoreAnimation)
Other
4.47k stars 1.08k forks source link

A confusing SVGTextElement's anchorPoint comment #317

Open freeatnet opened 9 years ago

freeatnet commented 9 years ago

The following comment is in SVGTextElement's, newLayer:

label.anchorPoint = CGPointZero; // WARNING: SVG applies transforms around the top-left as origin, whereas Apple defaults to center as origin, so we tell Apple to work "like SVG" here.

As a developer, I the transformations on a text element with the default text-anchor to be applied about the top-left corner of the element. If I apply a zero-degree transformation, I discover the anchor point to be at the bottom-left corner; which is consistent with CGPointZero and the coordinate system.

Screenshot: http://i.imgur.com/ZJ0CPu9.png

Should the comment be changed or is this a bug?

Version used: 352033dc30dc64bcc3306c0a2fceeafbc162b3bb on the 2.x branch.

adamgit commented 9 years ago

Apple applies multiple incompatible coord systems by the time something renders on iOS.

Probably the comment is correct, but Apple is applying an additional flip later in their render loop, that causes the effect you see. At the point where the comment sits, I think is correct - but you're not testing that, you're testing the higher level rendering. I think.

(their implementation of CA on iOS is horribly confusing, with magic "heuristic" flips applied silently internally and such)

On 25 April 2015 03:43:06 Arseniy Ivanov notifications@github.com wrote:

The following comment is in SVGTextElement's, newLayer:

label.anchorPoint = CGPointZero; // WARNING: SVG applies transforms around 
the top-left as origin, whereas Apple defaults to center as origin, so we 
tell Apple to work "like SVG" here.

As a developer, I the transformations on a text element with the default text-anchor to be applied about the top-left corner of the element. If I apply a zero-degree transformation, I discover the anchor point to be at the bottom-left corner; which is consistent with CGPointZero and the coordinate system.

Screenshot: http://i.imgur.com/ZJ0CPu9.png

Should the comment be changed or is this a bug?

Version used: 352033dc30dc64bcc3306c0a2fceeafbc162b3bb on the 2.x branch.


Reply to this email directly or view it on GitHub: https://github.com/SVGKit/SVGKit/issues/317

freeatnet commented 9 years ago

Thank you for your reply, Adam. I'm continuing to look into the issue; in the meanwhile, however, TinySVGTextAreaElement appears to be more consistent when positioning elements. I'll post more details / a pull request once I have a better understanding on how to improve SVGTextElement's positioning behaviour.