Svg example in C / C ++

Can anyone provide an example of loading a .svg file and displaying it using C / C ++ and any library? I'm wondering if you will be using SDL, cairo or what.

+2


source to share


4 answers


As Paul said, QtSvg is the path I believe in. It's easier to use, but on our team we ran into performance issues with QtSvg, especially on Linux. So we decided to parse the SVG file directly by hand and render it using Qt itself. It 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 
    }
  }
}

      

+2


source


Helltone,

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



You can make things a little easier.

+3


source


QtSvg might be helpful.

+1


source


you can try boost.svg_plot

+1


source







All Articles