Cff new functional

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent 5683ee7a91
commit 9f4b3f27d3
  1. 104
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 22
      src/adaptors/UBCFFSubsetAdaptor.h
  3. 4
      src/adaptors/UBImportCFF.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;
}

@ -19,6 +19,8 @@
#include <QtXml>
#include <QString>
#include <QStack>
#include <QDomDocument>
#include <QHash>
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<QString, QString> textAttributes;
};
class UBCFFSubsetAdaptor
{
public:
@ -65,6 +76,15 @@ private:
QPointF mViewBoxCenter;
QSize mSize;
private:
QDomDocument mDOMdoc;
QHash<QString, IwbExt> 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<int> stateStack;
int currentState;
//helper methods

@ -47,8 +47,8 @@ UBImportCFF::~UBImportCFF()
QStringList UBImportCFF::supportedExtentions()
{
// return QStringList("iwb");
return QStringList();
return QStringList("iwb");
// return QStringList();
}

Loading…
Cancel
Save