Implemented import UBZ strokes from CFF (means strokes who was exported from UBZ to CFF and imported back).

Compatible with groups.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent 372160020a
commit 925efac633
  1. 151
      src/adaptors/UBCFFSubsetAdaptor.cpp

@ -16,6 +16,7 @@
#include <QSvgGenerator> #include <QSvgGenerator>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <QPixmap> #include <QPixmap>
#include <QMap>
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
@ -350,6 +351,13 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolygon(const QDomElement &e
} }
} }
//bounding rect lef top corner coordinates
qreal x1 = polygon.boundingRect().topLeft().x();
qreal y1 = polygon.boundingRect().topLeft().y();
//bounding rect dimensions
qreal width = polygon.boundingRect().width();
qreal height = polygon.boundingRect().height();
QString strokeColorText = element.attribute(aStroke); QString strokeColorText = element.attribute(aStroke);
QString fillColorText = element.attribute(aFill); QString fillColorText = element.attribute(aFill);
QString strokeWidthText = element.attribute(aStrokewidth); QString strokeWidthText = element.attribute(aStrokewidth);
@ -366,7 +374,13 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolygon(const QDomElement &e
brush.setColor(fillColor); brush.setColor(fillColor);
brush.setStyle(Qt::SolidPattern); brush.setStyle(Qt::SolidPattern);
QUuid itemUuid(element.attribute(aId).right(QUuid().toString().length()));
QUuid itemGroupUuid(element.attribute(aId).left(QUuid().toString().length()-1));
if (!itemUuid.isNull() && (itemGroupUuid!=itemUuid)) // reimported from UBZ
{
UBGraphicsPolygonItem *graphicsPolygon = new UBGraphicsPolygonItem(polygon); UBGraphicsPolygonItem *graphicsPolygon = new UBGraphicsPolygonItem(polygon);
graphicsPolygon->setBrush(brush); graphicsPolygon->setBrush(brush);
QTransform transform; QTransform transform;
@ -378,9 +392,41 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolygon(const QDomElement &e
} }
mCurrentScene->addItem(graphicsPolygon); mCurrentScene->addItem(graphicsPolygon);
graphicsPolygon->setUuid(itemUuid);
}
else // single CFF
{
QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width());
QPainter painter;
painter.begin(generator); //drawing to svg tmp file
painter.translate(pen.widthF() / 2 - x1, pen.widthF() / 2 - y1);
painter.setBrush(brush);
painter.setPen(pen);
painter.drawPolygon(polygon);
painter.end();
//add resulting svg file to scene
UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName()));
QTransform transform;
QString textTransform = element.attribute(aTransform);
svgItem->resetTransform();
if (!textTransform.isNull()) {
transform = transformFromString(textTransform, svgItem);
}
repositionSvgItem(svgItem, width +strokeWidth, height + strokeWidth, x1 - strokeWidth/2 + transform.m31(), y1 + strokeWidth/2 + transform.m32(), transform);
hashSceneItem(element, svgItem);
if (mGSectionContainer) if (mGSectionContainer)
{ {
addItemToGSection(graphicsPolygon); addItemToGSection(svgItem);
}
delete generator;
} }
return true; return true;
} }
@ -416,6 +462,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolyline(const QDomElement &
} }
} }
//bounding rect lef top corner coordinates
qreal x1 = polygon.boundingRect().topLeft().x();
qreal y1 = polygon.boundingRect().topLeft().y();
//bounding rect dimensions //bounding rect dimensions
qreal width = polygon.boundingRect().width(); qreal width = polygon.boundingRect().width();
qreal height = polygon.boundingRect().height(); qreal height = polygon.boundingRect().height();
@ -436,7 +486,16 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolyline(const QDomElement &
QBrush brush; QBrush brush;
brush.setColor(strokeColor); brush.setColor(strokeColor);
brush.setStyle(Qt::SolidPattern); brush.setStyle(Qt::SolidPattern);
QUuid itemUuid(element.attribute(aId).right(QUuid().toString().length()));
QUuid itemGroupUuid(element.attribute(aId).left(QUuid().toString().length()-1));
if (!itemUuid.isNull() && (itemGroupUuid!=itemUuid)) // reimported from UBZ
{
UBGraphicsPolygonItem *graphicsPolygon = new UBGraphicsPolygonItem(polygon); UBGraphicsPolygonItem *graphicsPolygon = new UBGraphicsPolygonItem(polygon);
UBGraphicsStroke *stroke = new UBGraphicsStroke();
graphicsPolygon->setStroke(stroke);
graphicsPolygon->setBrush(brush); graphicsPolygon->setBrush(brush);
QTransform transform; QTransform transform;
QString textTransform = element.attribute(aTransform); QString textTransform = element.attribute(aTransform);
@ -447,9 +506,39 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolyline(const QDomElement &
} }
mCurrentScene->addItem(graphicsPolygon); mCurrentScene->addItem(graphicsPolygon);
}
else // simple CFF
{
QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width());
QPainter painter;
painter.begin(generator); //drawing to svg tmp file
painter.translate(pen.widthF() / 2 - x1, pen.widthF() / 2 - y1);
painter.setBrush(brush);
painter.setPen(pen);
painter.drawPolygon(polygon);
painter.end();
//add resulting svg file to scene
UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName()));
QTransform transform;
QString textTransform = element.attribute(aTransform);
svgItem->resetTransform();
if (!textTransform.isNull()) {
transform = transformFromString(textTransform, svgItem);
}
repositionSvgItem(svgItem, width +strokeWidth, height + strokeWidth, x1 - strokeWidth/2 + transform.m31(), y1 + strokeWidth/2 + transform.m32(), transform);
hashSceneItem(element, svgItem);
if (mGSectionContainer) if (mGSectionContainer)
{ {
addItemToGSection(graphicsPolygon); addItemToGSection(svgItem);
}
delete generator;
} }
@ -945,8 +1034,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &p
{ {
QString tagName = parent.tagName(); QString tagName = parent.tagName();
if (parent.namespaceURI() != svgNS) { if (parent.namespaceURI() != svgNS) {
qDebug() << "Incorrect namespace, error at content file, line number" << parent.lineNumber(); qWarning() << "Incorrect namespace, error at content file, line number" << parent.lineNumber();
return false; //return false;
} }
if (tagName == tG && !parseGSection(parent)) return false; if (tagName == tG && !parseGSection(parent)) return false;
@ -992,8 +1081,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPageset(const QDomElement &p
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta(const QDomElement &element)
{ {
if (element.namespaceURI() != iwbNS) { if (element.namespaceURI() != iwbNS) {
qDebug() << "incorrect meta namespace, incorrect document"; qWarning() << "incorrect meta namespace, incorrect document";
return false; //return false;
} }
return true; return true;
@ -1001,8 +1090,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta(const QDomElement &elem
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg(const QDomElement &svgSection) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg(const QDomElement &svgSection)
{ {
if (svgSection.namespaceURI() != svgNS) { if (svgSection.namespaceURI() != svgNS) {
qDebug() << "incorrect svg namespace, incorrect document"; qWarning() << "incorrect svg namespace, incorrect document";
return false; // return false;
} }
parseSvgSectionAttr(svgSection); parseSvgSectionAttr(svgSection);
@ -1021,13 +1110,15 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro
{ {
//TODO. Create groups from elements parsed by parseIwbElement() function //TODO. Create groups from elements parsed by parseIwbElement() function
if (parent.namespaceURI() != iwbNS) { if (parent.namespaceURI() != iwbNS) {
qDebug() << "incorrect iwb group namespace, incorrect document"; qWarning() << "incorrect iwb group namespace, incorrect document";
return false; // return false;
} }
UBGraphicsGroupContainerItem *group = new UBGraphicsGroupContainerItem(); UBGraphicsGroupContainerItem *group = new UBGraphicsGroupContainerItem();
QList<UBGraphicsPolygonItem *> strokesContainer; QMultiMap<QString, UBGraphicsPolygonItem *> strokesGroupsContainer;
QList<QGraphicsItem *> groupContainer; QList<QGraphicsItem *> groupContainer;
QString currentStrokeIdentifier;
QDomElement currentStrokeElement = parent.firstChildElement(); QDomElement currentStrokeElement = parent.firstChildElement();
while (!currentStrokeElement.isNull()) while (!currentStrokeElement.isNull())
{ {
@ -1038,17 +1129,28 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro
QString uuid = currentStrokeElement.attribute(aRef); QString uuid = currentStrokeElement.attribute(aRef);
if (!uuid.isEmpty()) if (!uuid.isEmpty())
{ {
if (uuid.contains("stroke")) // create stroke group if (uuid.size() > QUuid().toString().length()) // create stroke group
strokesContainer.append(qgraphicsitem_cast<UBGraphicsPolygonItem *>(mCurrentScene->itemForUuid(uuid))); {
currentStrokeIdentifier = uuid.left(QUuid().toString().length()-1);
UBGraphicsPolygonItem *strokeByUuid = qgraphicsitem_cast<UBGraphicsPolygonItem *>(mCurrentScene->itemForUuid(QUuid(uuid.right(QUuid().toString().length()))));
if (strokeByUuid)
strokesGroupsContainer.insert(currentStrokeIdentifier, strokeByUuid);
}
else // single elements in group else // single elements in group
groupContainer.append(mCurrentScene->itemForUuid(uuid)); groupContainer.append(mCurrentScene->itemForUuid(QUuid(uuid)));
} }
} }
currentStrokeElement = currentStrokeElement.nextSiblingElement(); currentStrokeElement = currentStrokeElement.nextSiblingElement();
} }
foreach (QString key, strokesGroupsContainer.keys())
{
UBGraphicsStrokesGroup* pStrokesGroup = new UBGraphicsStrokesGroup(); UBGraphicsStrokesGroup* pStrokesGroup = new UBGraphicsStrokesGroup();
UBGraphicsStroke *currentStroke = new UBGraphicsStroke(); UBGraphicsStroke *currentStroke = new UBGraphicsStroke();
foreach(UBGraphicsPolygonItem* poly, strokesContainer) foreach(UBGraphicsPolygonItem* poly, strokesGroupsContainer.values(key))
{ {
if (poly) if (poly)
{ {
@ -1065,13 +1167,24 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro
mCurrentScene->addItem(pStrokesGroup); mCurrentScene->addItem(pStrokesGroup);
else else
delete pStrokesGroup; delete pStrokesGroup;
foreach(QGraphicsItem* item, groupContainer)
group->addToGroup(item);
if (pStrokesGroup) if (pStrokesGroup)
group->addToGroup(pStrokesGroup); group->addToGroup(pStrokesGroup);
}
foreach(QGraphicsItem* item, groupContainer)
group->addToGroup(item);
if (group->childItems().count()) if (group->childItems().count())
{
mCurrentScene->addItem(group); mCurrentScene->addItem(group);
if (!groupContainer.count())
{
group->destroy(false);
}
}
return group; return group;
} }
@ -1083,8 +1196,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::strToBool(QString str)
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElement(QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElement(QDomElement &element)
{ {
if (element.namespaceURI() != iwbNS) { if (element.namespaceURI() != iwbNS) {
qDebug() << "incorrect iwb element namespace, incorrect document"; qWarning() << "incorrect iwb element namespace, incorrect document";
return false; // return false;
} }
bool locked = false; bool locked = false;

Loading…
Cancel
Save