pocketsvg/PocketSVG

CGPathGetCurrentPoint: no current point emitted

robaho opened this issue · 7 comments

When using PocketSVG, it continually emits 'no current point'.

I believe the problem is the following code is lines 576-578 in SVGEngine.mm

        CGPoint currentPoint = CGPathGetCurrentPoint(_path);
        CGFloat x = _operands[i+0] + (_cmd == 'm' ? currentPoint.x : 0);
        CGFloat y = _operands[i+1] + (_cmd == 'm' ? currentPoint.y : 0);

in pathDefinitionParser::appendMoveTo()

I believe the code should be changed to be:

        CGPoint currentPoint = _cmd == 'm' && !CGPathIsEmpty(_path) ? CGPathGetCurrentPoint(_path) : CGPointZero;
        CGFloat x = _operands[i+0] + currentPoint.x;
        CGFloat y = _operands[i+1] + currentPoint.y;

which will avoid calling CGPathGetCurrentPoint() when the path is most likely empty, and wouldn't be used anyway.

I think this is related to issue #133

Hi @robaho
Could you please provide steps to reproduce this issue?

I'm experiencing this issue as well. I can reproduce it with the following code and SVG:

let url = Bundle.main.url(forResource: "example", withExtension: "svg")
let svgLayer = SVGLayer(contentsOf: url!)

example.svg

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg">
    <path d="M25,50 C25,100 150,100 150,50 Z" />
</svg>

I don't see any PR originating from you @robaho

fixed via #173