| 1 |
#include "utils.h" |
| 2 |
#include <QtCore/QFile> |
| 3 |
#include <QtCore/QDebug> |
| 4 |
#include <libxml/parser.h> |
| 5 |
#include <libxslt/xsltInternals.h> |
| 6 |
#include <libxslt/transform.h> |
| 7 |
#include <libxslt/xsltutils.h> |
| 8 |
|
| 9 |
QByteArray loadFile(const QString& filename) { |
| 10 |
QFile file(filename); |
| 11 |
if (!file.open(QIODevice::ReadOnly)) { |
| 12 |
qDebug() << file.errorString(); |
| 13 |
} |
| 14 |
return file.readAll(); |
| 15 |
} |
| 16 |
|
| 17 |
void |
| 18 |
xmltosvg(xsltStylesheetPtr xsl, const char* filepath, FILE* out) { |
| 19 |
QString file = QString::fromLocal8Bit(filepath); |
| 20 |
const QMap<QString, QByteArray> streams = readStreams(file); |
| 21 |
const QMap<QString, QSharedPointer<const Introspectable> > introspectables |
| 22 |
= parseStreams(streams); |
| 23 |
const QByteArray xml = streamsToExtendedXml(introspectables); |
| 24 |
xmlDocPtr pptxmldoc = xmlParseMemory(xml, xml.size()); |
| 25 |
|
| 26 |
xmlDocPtr res = xsltApplyStylesheet(xsl, pptxmldoc, 0); |
| 27 |
|
| 28 |
xsltSaveResultToFile(out, res, xsl); |
| 29 |
|
| 30 |
xmlFreeDoc(pptxmldoc); |
| 31 |
xmlFreeDoc(res); |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
main(int argc, char** argv) { |
| 36 |
if (argc < 2) return 1; |
| 37 |
|
| 38 |
QByteArray xslfiledata = loadFile(":/ppttosvg.xsl"); |
| 39 |
xmlDocPtr xsldoc = xmlParseMemory(xslfiledata, xslfiledata.size()); |
| 40 |
xslfiledata.resize(0); |
| 41 |
xsltStylesheetPtr xsl = xsltParseStylesheetDoc(xsldoc); |
| 42 |
|
| 43 |
for (int i=1; i<argc; ++i) { |
| 44 |
xmltosvg(xsl, argv[i], stdout); |
| 45 |
} |
| 46 |
xsltFreeStylesheet(xsl); // this frees xsldoc too |
| 47 |
|
| 48 |
xsltCleanupGlobals(); |
| 49 |
xmlCleanupParser(); |
| 50 |
|
| 51 |
return 0; |
| 52 |
} |