tags:

views:

1026

answers:

4

Hi,

Can someone provide an example of how to load a .svg file and display it using C/C++ and any library? I'm wondering if you will use SDL, cairo, or what.

+2  A: 

Helltone,

check out http://cairographics.org/cairomm/

Might make things a little easier.

Scott
+1  A: 

QtSvg module might be helpful.

Pavel Shved
+2  A: 

As Pavel put it, QtSvg is the way to go i believe. It is easier to use but in our team we have faced performance issues with QtSvg especially on Linux. So we decided to directly parse the SVG file XML by hand and render it using Qt itself. This turned out to be much faster.

pseudocode:-

// Read the SVG file using XML parser (SAX)
void SvgReader::readFile()
{
  QFile file(<some svg filename>);
  if (!file.open(QFile::ReadOnly | QFile::Text)) {
    qWarning("Cannot open file");
    return;
  }
  QString localName;
  QXmlStreamAttributes attributes;
  pXml = new QXmlStreamReader(&file);
  pXml->setNamespaceProcessing(false);
  while (!pXml->atEnd()) {
    switch (pXml->readNext()) {
        case QXmlStreamReader::StartElement:
          localName = pXml->name().toString();
          if (localName.compare(<some element path>) == 0) {
            attributes = pXml->attributes();
            QStringRef data  = attributes.value(<some attribute name>);
            // parse/use your data;
          }
        // similarly other case statements 
    }
  }
}
Abhay
+1  A: 

you may try boost.svg_plot

t.g.