SVG translate( x, y) bugfix


#1

Some SVGs we use go through a scouring process to reduce their size. This has caused a problem with JUCE SVG support.

From the SVG spec:

translate(<tx> [<ty>]), which specifies a translation by tx and ty. If <ty> is not provided, it is assumed to be zero.

It shortens translate(dx, dy) if dy = 0 to translate(dx).

So line 1172 in juce_SVGParser.cpp

else if (t.startsWithIgnoreCase ("translate"))
{
    jassert (tokens.size() == 2);
    trans = AffineTransform::translation (numbers[0], numbers[1]);
}

Should be something like this:


else if (t.startsWithIgnoreCase ("translate"))
{
    if (tokens.size() == 1)
        trans = AffineTransform::translation (numbers[0], 0);
    else if (tokens.size() == 2)
        trans = AffineTransform::translation (numbers[0], numbers[1]);
    else
        jassertfalse;
}

JUCE Bug List Report
#2

Cheers Harry! Actually, I think it's just the assertion that's incorrect - if there's only one token then numbers[1] will already be 0 and it should already do the correct behaviour. But I'll sort out the assertion for you, thanks!