diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index a4812096..6d688b34 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -34,6 +34,8 @@ #include "core/UBApplication.h" #include "QFile" +#include "QDomDocument" + //enum of xmlparse status //tag names definition @@ -75,11 +77,54 @@ static QString aFontstyle = "font-style"; static QString aFontweight = "font-weight"; static QString aTextalign = "text-align"; static QString aPoints = "points"; +static QString svgNS = "http://www.w3.org/2000/svg"; +static QString tId = "id"; + UBCFFSubsetAdaptor::UBCFFSubsetAdaptor() { } +void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashNode(QDomNode *parent, QString prefix) +{ + QDomNode n = parent->firstChild(); + while (!n.isNull()) { + QDomElement e = n.toElement(); + QString id = e.attribute(tId); + if(!id.isNull()) { + extProperties.insert(id, IwbExt(e)); + qDebug() << prefix + e.prefix() + ":" + e.tagName(); + } + if (n.hasChildNodes()) { + hashNode(&n, QString("| %1").arg(prefix)); + } + n = n.nextSibling(); + } +} + +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::hashElements() +{ + QDomElement svgSection = mDOMdoc.elementsByTagNameNS(svgNS, tSvg).at(0).toElement(); + Q_ASSERT(!svgSection.isNull()); + + hashNode(&svgSection); + + qDebug() << "ext properties count " << extProperties.count(); + qDebug() << extProperties.value("link1").element.toElement().tagName(); + + + // QDomNode n = docElem.firstChild(); +// int i = 0; +// while(!n.isNull()) { +// QDomElement e = n.toElement(); // try to convert the node to an element. +// if(!e.isNull()) { +// qDebug() << e.prefix() << ":" << e.tagName() ; // the node really is an element. +// i++; +// } +// n = n.nextSibling(); +// } + return false; +} bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument) { @@ -116,6 +161,14 @@ bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentP UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QByteArray &content): mReader(content), mProxy(proxy), currentState(NONE) { + int errorLine, errorColumn; + QString errorStr; + if(!mDOMdoc.setContent(content, true, &errorStr, &errorLine, &errorColumn)){ + qWarning() << "Error:Parseerroratline" << errorLine << "," + << "column" << errorColumn << ":" << errorStr; + } else { + qDebug() << "well parsed to DOM"; + } // QFile tfile("/home/ilia/Documents/tmp/2/out.xml"); // tfile.open(QIODevice::ReadWr ite | QIODevice::Text); // QTextStream out(&tfile); @@ -131,6 +184,9 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse() if (!getTempFileName()) return false; + if (mDOMdoc.isNull()) + return false; + bool result = parseDoc(); if (result) result = mProxy->pageCount() != 0; @@ -160,29 +216,31 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::PushState(int state) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() { - while (!mReader.atEnd()) - { - mReader.readNext(); - if (mReader.isStartElement()) - { - if (!parseCurrentElementStart()) - return false; - } - else - if (mReader.isCharacters()) - { - if (!parseCurrentElementCharacters()) - return false; - } - else - if (mReader.isEndElement()) - { - if (!parseCurrentElementEnd()) - return false; - } - } - if (!mReader.error() == QXmlStreamReader::NoError) - UBApplication::showMessage(mReader.errorString()); +// while (!mReader.atEnd()) +// { +// mReader.readNext(); +// if (mReader.isStartElement()) +// { +// if (!parseCurrentElementStart()) +// return false; +// } +// else +// if (mReader.isCharacters()) +// { +// if (!parseCurrentElementCharacters()) +// return false; +// } +// else +// if (mReader.isEndElement()) +// { +// if (!parseCurrentElementEnd()) +// return false; +// } +// } +// if (!mReader.error() == QXmlStreamReader::NoError) +// UBApplication::showMessage(mReader.errorString()); + if (!hashElements()) return false; + return true; } diff --git a/src/adaptors/UBCFFSubsetAdaptor.h b/src/adaptors/UBCFFSubsetAdaptor.h index 2c78f1e4..7515b2c4 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.h +++ b/src/adaptors/UBCFFSubsetAdaptor.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include class UBDocumentProxy; class UBGraphicsScene; @@ -26,6 +28,15 @@ class QSvgGenerator; class UBGraphicsSvgItem; class QTransform; +struct IwbExt { + IwbExt() : group(NULL) {;} + IwbExt(QDomNode element) : group(NULL), element(element) {;} + + QDomNode *group; + QDomNode element; + QHash textAttributes; +}; + class UBCFFSubsetAdaptor { public: @@ -65,6 +76,15 @@ private: QPointF mViewBoxCenter; QSize mSize; + private: + QDomDocument mDOMdoc; + QHash extProperties; + bool hashElements(); + + void hashNode(QDomNode *parent, QString prefix = ""); + + + //methods to store current xml parse state int PopState(); void PushState(int state); @@ -92,7 +112,9 @@ private: bool createNewScene(); bool persistCurrentScene(); + QStack stateStack; + int currentState; //helper methods diff --git a/src/adaptors/UBImportCFF.cpp b/src/adaptors/UBImportCFF.cpp index 4ad47896..f6554415 100644 --- a/src/adaptors/UBImportCFF.cpp +++ b/src/adaptors/UBImportCFF.cpp @@ -47,8 +47,8 @@ UBImportCFF::~UBImportCFF() QStringList UBImportCFF::supportedExtentions() { -// return QStringList("iwb"); - return QStringList(); + return QStringList("iwb"); +// return QStringList(); }