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
Giovanni funchal
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
Abhay
source
to share
Helltone,
check out http://cairographics.org/cairomm/
You can make things a little easier.
+3
Scott
source
to share
QtSvg might be helpful.
+1
Pavel shved
source
to share
you can try boost.svg_plot
+1
tg
source
to share