OK, after squinting on the svg specs I have to admit following really is only a starting point to display the specific Illustrator output my Graphic Designer is delivering to me (./modules/juce_gui_basics/drawables/juce_SVGParser.cpp):
Drawable* parseText (const XmlPath& xml)
{
Array <float> xCoords, yCoords, dxCoords, dyCoords;
getCoordList (xCoords, getInheritedAttribute (xml, "x"), true, true);
getCoordList (yCoords, getInheritedAttribute (xml, "y"), true, false);
getCoordList (dxCoords, getInheritedAttribute (xml, "dx"), true, true);
getCoordList (dyCoords, getInheritedAttribute (xml, "dy"), true, false);
DrawableComposite* const drawable = new DrawableComposite();
drawable->setComponentID (xml->getStringAttribute ("id"));
//xxx not done text yet!
forEachXmlChildElement (*xml, e)
{
if (e->isTextElement())
{
DrawableText* text = new DrawableText();
String string = e->getText();
Font font(
xml->getStringAttribute ("font-family", Font::getDefaultSansSerifFontName()).
trimCharactersAtStart("'").trimCharactersAtEnd("'"),
xml->getStringAttribute ("font-style", Font::getDefaultStyle()).
trimCharactersAtStart("'").trimCharactersAtEnd("'"),
xml->getDoubleAttribute ("font-size", 12)*1.2);
text->setFont (font,true);
float x = xml->getDoubleAttribute ("x",0);
float y = xml->getDoubleAttribute ("y",0)-font.getAscent();
if (xml->hasAttribute ("transform"))
{
AffineTransform transform = parseTransform (xml->getStringAttribute ("transform"));
text->setTransform (transform);
transform.transformPoint (x,y);
}
if (xml->hasAttribute ("fill"))
{
text->setColour (Colour (0xff000000|
xml->getStringAttribute ("fill").trimCharactersAtStart("#").getHexValue32()));
}
text->setBoundingBox (Rectangle<float> (x,y,font.getStringWidth (string),font.getHeight()));
text->setText (string);
/*
std::clog<<
e->getText()<<" ("<<x<<", "<<y<<", "<<
font.getTypefaceName()<<", "<<
font.getTypefaceStyle()<<", "<<
font.getHeight()<<", "<<
std::hex<<text->getColour().toDisplayString(true)<<std::dec<<
std::endl;
//std::clog<<"x:";for(auto&coord:xCoords)std::clog<<coord<<", ";std::clog<<std::endl;
//std::clog<<"y:";for(auto&coord:yCoords)std::clog<<coord<<", ";std::clog<<std::endl;
//std::clog<<"dx:";for(auto&coord:dxCoords)std::clog<<coord<<", ";std::clog<<std::endl;
//std::clog<<"dy:";for(auto&coord:dyCoords)std::clog<<coord<<", ";std::clog<<std::endl;
*/
drawable->addAndMakeVisible (text);
}
else if (e->hasTagNameIgnoringNamespace ("tspan"))
{
drawable->addAndMakeVisible (parseText (xml.getChild (e)));
}
}
return drawable;
}
One probably should take advantage of the existing parse path functions, but currently this only serves as a proof of concept to create my GUI. With advancing the GUI requirements this could advance as well. Also the parent coords are not used yet. Before putting in more effort I would like to hear if this is principal the right approach.
Cheers,
raketa