Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

PSD Vector: load and parse vogk data.

Wolthera van Hövell tot Westerflier84ffb9deb562
diff --git a/libs/psd/psd_additional_layer_info_block.cpp b/libs/psd/psd_additional_layer_info_block.cpp
index c774a15835..7ca69198a7 100644
--- a/libs/psd/psd_additional_layer_info_block.cpp
+++ b/libs/psd/psd_additional_layer_info_block.cpp
@@ -343,7 +343,8 @@ void PsdAdditionalLayerInfoBlock::readImpl(QIODevice &io)
}
}
} else if (key == "sn2P") {
- } else if (key == "vogk") {
+ } else if (key == "vogk") { // Live path shapes, these are similar to parametric shapes.
+ vectorOriginationData = KisAslReader::readVectorOriginationData(io, byteOrder);
} else if (key == "Mtrn" || key == "Mt16" || key == "Mt32") { // There is no data associated with these keys.
} else if (key == "LMsk") {
diff --git a/libs/psd/psd_additional_layer_info_block.h b/libs/psd/psd_additional_layer_info_block.h
index e83b468408..66be43a9c6 100644
--- a/libs/psd/psd_additional_layer_info_block.h
+++ b/libs/psd/psd_additional_layer_info_block.h
@@ -1174,6 +1174,121 @@ struct KRITAPSD_EXPORT psd_vector_stroke_data {
}
};
+struct psd_vector_origination_data {
+ int originType = -1; ///< 1 = rect, 2 = rounded rect, 3 = ? 4 = ? 5 = ellipse, 6 = ?, 7 = polygon, 8 = star, 9 = premade path shape.
+ QRectF originShapeBBox; ///< pre-transform bbox.
+ double originResolution = 72.0; ///< Resolution of the coordinates.
+ QTransform transform;
+ int originIndex = 0; // unknown, always 0.
+
+ QPolygonF originBoxCorners; ///< post-transform bbox as a polygon, seen on 1, 7, 8 and 9.
+ int originPolySides = 0; ///< Only for 7 and 8.
+ double originPolyStarRatio = 100.0; ///< Only for 8, percentage of small radius to big radius.
+ bool isStar = false;
+ double originPolyPixelHSF = 1.0; ///< Only 7 and 8, no clue.
+ QPolygonF originPolyPreviousTightBoxCorners; ///< Only 7 an 8, same as originBoxCorners.
+ QPolygonF originPolyTrueRectCorners;///< Only 7 an 8, same as originBoxCorners.
+
+ void setOriginType(int type) {
+ originType = type;
+ }
+
+ void setOriginResolution(double res) {
+ originResolution = res;
+ }
+
+ void setTransform(QTransform t) {
+ transform = t;
+ }
+
+ void setOriginShapeBBox(QRectF ShapeBBox) {
+ originShapeBBox = ShapeBBox;
+ }
+ void setOriginBoxCorners(QPointF p) {
+ originBoxCorners.append(p);
+ }
+ void setOriginPolyTightBoxCorners(QPointF p) {
+ originPolyPreviousTightBoxCorners.append(p);
+ }
+ void setOriginPolyTrueRectCorners(QPointF p) {
+ originPolyTrueRectCorners.append(p);
+ }
+
+ void setOriginPolySides(int sides) {
+ originPolySides = sides;
+ }
+
+ void setOriginPolyStarRatio(double ratio) {
+ originPolyStarRatio = ratio;
+ isStar = true;
+ }
+
+ static void setupCatcher(const QString path, KisAslCallbackObjectCatcher &catcher, psd_vector_origination_data *data) {
+ QString descriptorPath = path+"/keyDescriptorList/null";
+ catcher.subscribeInteger(descriptorPath + "/keyOriginType", std::bind(&psd_vector_origination_data::setOriginType, data, std::placeholders::_1));
+ catcher.subscribeDouble(descriptorPath + "/keyOriginResolution", std::bind(&psd_vector_origination_data::setOriginResolution, data, std::placeholders::_1));
+ catcher.subscribeTransform(descriptorPath + "/Trnf", std::bind(&psd_vector_origination_data::setTransform, data, std::placeholders::_1));
+ catcher.subscribeUnitRect(descriptorPath + "/keyOriginShapeBBox", "#Pxl", std::bind(&psd_vector_origination_data::setOriginShapeBBox, data, std::placeholders::_1));
+
+ catcher.subscribePoint(descriptorPath + "/keyOriginBoxCorners/rectangleCornerA", std::bind(&psd_vector_origination_data::setOriginBoxCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginBoxCorners/rectangleCornerB", std::bind(&psd_vector_origination_data::setOriginBoxCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginBoxCorners/rectangleCornerC", std::bind(&psd_vector_origination_data::setOriginBoxCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginBoxCorners/rectangleCornerD", std::bind(&psd_vector_origination_data::setOriginBoxCorners, data, std::placeholders::_1));
+
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyPreviousTightBoxCorners/rectangleCornerA", std::bind(&psd_vector_origination_data::setOriginPolyTightBoxCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyPreviousTightBoxCorners/rectangleCornerB", std::bind(&psd_vector_origination_data::setOriginPolyTightBoxCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyPreviousTightBoxCorners/rectangleCornerC", std::bind(&psd_vector_origination_data::setOriginPolyTightBoxCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyPreviousTightBoxCorners/rectangleCornerD", std::bind(&psd_vector_origination_data::setOriginPolyTightBoxCorners, data, std::placeholders::_1));
+
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyTrueRectCorners/rectangleCornerA", std::bind(&psd_vector_origination_data::setOriginPolyTrueRectCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyTrueRectCorners/rectangleCornerB", std::bind(&psd_vector_origination_data::setOriginPolyTrueRectCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyTrueRectCorners/rectangleCornerC", std::bind(&psd_vector_origination_data::setOriginPolyTrueRectCorners, data, std::placeholders::_1));
+ catcher.subscribePoint(descriptorPath + "/keyOriginPolyTrueRectCorners/rectangleCornerD", std::bind(&psd_vector_origination_data::setOriginPolyTrueRectCorners, data, std::placeholders::_1));
+
+ catcher.subscribeInteger(descriptorPath + "/keyOriginPolySides", std::bind(&psd_vector_origination_data::setOriginPolySides, data, std::placeholders::_1));
+ catcher.subscribeUnitFloat(descriptorPath + "/keyOriginPolyStarRatio", "#Prc", std::bind(&psd_vector_origination_data::setOriginPolyStarRatio, data, std::placeholders::_1));
+
+ }
+
+ QString elementType () {
+ QString el;
+ if (originType == 1) {
+ el = "rect";
+ } else if (originType == 5) {
+ el = "ellipse";
+ } else if (originType == 7) {
+ el = "regular-polygon";
+ } else if (originType == 8) {
+ el = "regular-polygon";
+ }
+ return el;
+ }
+
+ bool canMakeParametricShape() {
+ bool p = !elementType().isEmpty();
+ return p;
+ }
+
+ /**
+ * For some reason, instead of putting the whole transformation into the
+ * transform, PSD instead creates a list points that represents the transformed
+ * bounding box. To get the original width and height and angle,
+ * one must first untransform this polygon and use it to determine the appropriate
+ * values.
+ */
+ void OriginalSizeAndAngle(QSizeF &size, double &angle) {
+ size = originShapeBBox.size();
+ angle = QLineF(originShapeBBox.topLeft(), originShapeBBox.topRight()).angle();
+ if (originBoxCorners.size() == 4) {
+ QPolygonF poly = transform.inverted().map(originBoxCorners);
+ angle = QLineF(poly.first(), poly.value(1)).angle();
+ double w = QLineF(poly.first(), poly.value(1)).length();
+ double h = QLineF(poly.first(), poly.value(3)).length();
+ size = QSizeF(w, h);
+ }
+ }
+};
+
/**
* @brief The PsdAdditionalLayerInfoBlock class implements the Additional Layer Information block
*
@@ -1227,6 +1342,7 @@ public:
psd_vector_mask vectorMask;
QDomDocument vectorStroke;
+ QDomDocument vectorOriginationData;
psd_section_type sectionDividerType;
QString sectionDividerBlendMode;
diff --git a/libs/psd/psd_layer_record.cpp b/libs/psd/psd_layer_record.cpp
index 0c9ae05331..43a045dac9 100644
--- a/libs/psd/psd_layer_record.cpp
+++ b/libs/psd/psd_layer_record.cpp
@@ -936,6 +936,7 @@ bool PSDLayerRecord::readMask(QIODevice &io, KisPaintDeviceSP dev, ChannelInfo *
KoPathShape *PSDLayerRecord::constructPathShape(psd_path path, double shapeWidth, double shapeHeight)
{
KoPathShape *shape = new KoPathShape();
+
// psd paths are stored normalized.
QTransform tf = QTransform::fromScale(shapeWidth, shapeHeight);
diff --git a/libs/psd/psd_layer_record.h b/libs/psd/psd_layer_record.h
index fd07d85d0d..3a3c611fc2 100644
--- a/libs/psd/psd_layer_record.h
+++ b/libs/psd/psd_layer_record.h
@@ -87,6 +87,7 @@ public:
* @param path a psd path struct.
* @param shapeWidth the image width in points
* @param shapeHeight the image height in points
+ * @param vogk extra vector data from the vogk layer info block.
* @return a KoPathShape.
*/
KoPathShape *constructPathShape(psd_path path, double shapeWidth, double shapeHeight);
diff --git a/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp b/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
index 4766a50ee3..48be34fd16 100644
--- a/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
+++ b/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
@@ -43,7 +43,19 @@ struct UnitFloatMapping {
ASLCallbackDouble map;
};
+struct UnitRectMapping {
+ UnitRectMapping(const QString &_unit, ASLCallbackRect _map)
+ : unit(_unit)
+ , map(_map)
+ {
+ }
+
+ QString unit;
+ ASLCallbackRect map;
+};
+
typedef QHash<QString, UnitFloatMapping> MapHashUnitFloat;
+typedef QHash<QString, UnitRectMapping> MapHashUnitRect;
typedef QHash<QString, ASLCallbackString> MapHashText;
typedef QHash<QString, ASLCallbackBoolean> MapHashBoolean;
@@ -54,6 +66,8 @@ typedef QHash<QString, ASLCallbackPattern> MapHashPattern;
typedef QHash<QString, ASLCallbackPatternRef> MapHashPatternRef;
typedef QHash<QString, ASLCallbackGradient> MapHashGradient;
typedef QHash<QString, ASLCallbackRawData> MapHashRawData;
+typedef QHash<QString, ASLCallbackTransform> MapHashTransform;
+typedef QHash<QString, ASLCallbackRect> MapHashRect;
struct KisAslCallbackObjectCatcher::Private {
MapHashDouble mapDouble;
@@ -69,6 +83,9 @@ struct KisAslCallbackObjectCatcher::Private {
MapHashPatternRef mapPatternRef;
MapHashGradient mapGradient;
MapHashRawData mapRawData;
+ MapHashTransform mapTransform;
+ MapHashRect mapRect;
+ MapHashUnitRect mapUnitRect;
ASLCallbackNewStyle newStyleCallback;
};
@@ -196,6 +213,28 @@ void KisAslCallbackObjectCatcher::addRawData(const QString &path, QByteArray ba)
passToCallback(path, m_d->mapRawData, ba);
}
+void KisAslCallbackObjectCatcher::addTransform(const QString &path, const QTransform &transform)
+{
+ passToCallback(path, m_d->mapTransform, transform);
+}
+
+void KisAslCallbackObjectCatcher::addRect(const QString &path, const QRectF &rect)
+{
+ passToCallback(path, m_d->mapRect, rect);
+}
+
+void KisAslCallbackObjectCatcher::addUnitRect(const QString &path, const QString &unit, const QRectF &rect)
+{
+ MapHashUnitRect::const_iterator it = m_d->mapUnitRect.constFind(path);
+ if (it != m_d->mapUnitRect.constEnd()) {
+ if (it->unit == unit) {
+ it->map(rect);
+ } else {
+ warnKrita << "KisAslCallbackObjectCatcher::addUnitRect: inconsistent unit" << ppVar(unit) << ppVar(it->unit);
+ }
+ }
+}
+
/*****************************************************************/
/* Subscription methods */
/*****************************************************************/
@@ -269,3 +308,18 @@ void KisAslCallbackObjectCatcher::subscribeRawData(const QString &path, ASLCallb
{
m_d->mapRawData.insert(path, callback);
}
+
+void KisAslCallbackObjectCatcher::subscribeTransform(const QString &path, ASLCallbackTransform callback)
+{
+ m_d->mapTransform.insert(path, callback);
+}
+
+void KisAslCallbackObjectCatcher::subscribeRect(const QString &path, ASLCallbackRect callback)
+{
+ m_d->mapRect.insert(path, callback);
+}
+
+void KisAslCallbackObjectCatcher::subscribeUnitRect(const QString &path, const QString &unit, ASLCallbackRect callback)
+{
+ m_d->mapUnitRect.insert(path, UnitRectMapping(unit, callback));
+}
diff --git a/libs/psdutils/asl/kis_asl_callback_object_catcher.h b/libs/psdutils/asl/kis_asl_callback_object_catcher.h
index 094d079eb6..804ecba5b0 100644
--- a/libs/psdutils/asl/kis_asl_callback_object_catcher.h
+++ b/libs/psdutils/asl/kis_asl_callback_object_catcher.h
@@ -30,6 +30,8 @@ using ASLCallbackPatternRef = std::function<void(const QString &, const QString
using ASLCallbackGradient = std::function<void(KoAbstractGradientSP)>;
using ASLCallbackNewStyle = std::function<void()>;
using ASLCallbackRawData = std::function<void(QByteArray)>;
+using ASLCallbackTransform = std::function<void(QTransform)>;
+using ASLCallbackRect = std::function<void(QRectF)>;
class KRITAPSDUTILS_EXPORT KisAslCallbackObjectCatcher : public KisAslObjectCatcher
{
@@ -51,6 +53,9 @@ public:
void addGradient(const QString &path, KoAbstractGradientSP gradient) override;
void newStyleStarted() override;
void addRawData(const QString &path, QByteArray ba) override;
+ void addTransform(const QString &path, const QTransform &transform) override;
+ void addRect(const QString &path, const QRectF &rect) override;
+ void addUnitRect(const QString &path, const QString &unit, const QRectF &rect) override;
void subscribeDouble(const QString &path, ASLCallbackDouble callback);
@@ -67,6 +72,9 @@ public:
void subscribeGradient(const QString &path, ASLCallbackGradient callback);
void subscribeNewStyleStarted(ASLCallbackNewStyle callback);
void subscribeRawData(const QString &path, ASLCallbackRawData callback);
+ void subscribeTransform(const QString &path, ASLCallbackTransform callback);
+ void subscribeRect(const QString &path, ASLCallbackRect callback);
+ void subscribeUnitRect(const QString &path, const QString &unit, ASLCallbackRect callback);
private:
struct Private;
diff --git a/libs/psdutils/asl/kis_asl_object_catcher.cpp b/libs/psdutils/asl/kis_asl_object_catcher.cpp
index 7a21628242..7ef0591c04 100644
--- a/libs/psdutils/asl/kis_asl_object_catcher.cpp
+++ b/libs/psdutils/asl/kis_asl_object_catcher.cpp
@@ -88,6 +88,21 @@ void KisAslObjectCatcher::addRawData(const QString &path, QByteArray ba)
dbgKrita << "Unhandled:" << (m_arrayMode ? "[A]" : "[ ]") << path << "bytearray";
}
+void KisAslObjectCatcher::addTransform(const QString &path, const QTransform &transform)
+{
+ dbgKrita << "Unhandled:" << (m_arrayMode ? "[A]" : "[ ]") << path << "transform" << transform;
+}
+
+void KisAslObjectCatcher::addRect(const QString &path, const QRectF &rect)
+{
+ dbgKrita << "Unhandled:" << (m_arrayMode ? "[A]" : "[ ]") << path << "corner rect" << rect;
+}
+
+void KisAslObjectCatcher::addUnitRect(const QString &path, const QString &unit, const QRectF &rect)
+{
+ dbgKrita << "Unhandled:" << (m_arrayMode ? "[A]" : "[ ]") << path << "unit rect" << unit << "rect" << rect;
+}
+
void KisAslObjectCatcher::newStyleStarted()
{
dbgKrita << "Unhandled:"
diff --git a/libs/psdutils/asl/kis_asl_object_catcher.h b/libs/psdutils/asl/kis_asl_object_catcher.h
index 98ce7534c2..7beb9f81ed 100644
--- a/libs/psdutils/asl/kis_asl_object_catcher.h
+++ b/libs/psdutils/asl/kis_asl_object_catcher.h
@@ -41,6 +41,9 @@ public:
virtual void addPatternRef(const QString &path, const QString &patternUuid, const QString &patternName);
virtual void addGradient(const QString &path, KoAbstractGradientSP gradient);
virtual void addRawData(const QString &path, QByteArray ba);
+ virtual void addTransform(const QString &path, const QTransform &transform);
+ virtual void addRect(const QString &path, const QRectF &rect);
+ virtual void addUnitRect(const QString &path, const QString &unit, const QRectF &rect);
virtual void newStyleStarted();
diff --git a/libs/psdutils/asl/kis_asl_reader.cpp b/libs/psdutils/asl/kis_asl_reader.cpp
index 812e9b977c..4ef9d37241 100644
--- a/libs/psdutils/asl/kis_asl_reader.cpp
+++ b/libs/psdutils/asl/kis_asl_reader.cpp
@@ -926,6 +926,51 @@ QDomDocument readVectorStrokeImpl(QIODevice &device)
return doc;
}
+template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
+QDomDocument readVectorOriginationDataImpl(QIODevice &device);
+QDomDocument KisAslReader::readVectorOriginationData(QIODevice &device, psd_byte_order byteOrder)
+{
+ switch (byteOrder) {
+ case psd_byte_order::psdLittleEndian:
+ return readVectorOriginationDataImpl<psd_byte_order::psdLittleEndian>(device);
+ default:
+ return readVectorOriginationDataImpl(device);
+ }
+}
+
+template<psd_byte_order byteOrder>
+QDomDocument readVectorOriginationDataImpl(QIODevice &device)
+{
+ QDomDocument doc;
+
+ if (device.isSequential()) {
+ warnKrita << "WARNING: *** KisAslReader::readVectorStroke: the supplied"
+ << "IO device is sequential. Chances are that"
+ << "the fill config will *not* be loaded correctly!";
+ }
+ try {
+
+ {
+ quint32 version = GARBAGE_VALUE_MARK;
+ SAFE_READ_SIGNATURE_EX(byteOrder, device, version, 1);
+ }
+ {
+ quint32 descriptorVersion = GARBAGE_VALUE_MARK;
+ SAFE_READ_SIGNATURE_EX(byteOrder, device, descriptorVersion, 16);
+ }
+
+ QDomElement root = doc.createElement("asl");
+ doc.appendChild(root);
+
+ Private::readDescriptor<byteOrder>(device, "", &root, &doc);
+
+ } catch (KisAslReaderUtils::ASLParseException &e) {
+ warnKrita << "WARNING: PSD: vogk section:" << e.what();
+ }
+
+ return doc;
+}
+
template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
QDomDocument readPsdSectionPatternImpl(QIODevice &device, qint64 bytesLeft);
diff --git a/libs/psdutils/asl/kis_asl_reader.h b/libs/psdutils/asl/kis_asl_reader.h
index 0e752f8c3a..64b459ba7c 100644
--- a/libs/psdutils/asl/kis_asl_reader.h
+++ b/libs/psdutils/asl/kis_asl_reader.h
@@ -23,6 +23,7 @@ public:
static QDomDocument readFillLayer(QIODevice &device, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
static QDomDocument readTypeToolObjectSettings(QIODevice &device, QTransform &transform, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
static QDomDocument readVectorStroke(QIODevice &device, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
+ static QDomDocument readVectorOriginationData(QIODevice &device, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
static QDomDocument readPsdSectionPattern(QIODevice &device, qint64 bytesLeft, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
};
diff --git a/libs/psdutils/asl/kis_asl_xml_parser.cpp b/libs/psdutils/asl/kis_asl_xml_parser.cpp
index 5a4004111b..46d04192ec 100644
--- a/libs/psdutils/asl/kis_asl_xml_parser.cpp
+++ b/libs/psdutils/asl/kis_asl_xml_parser.cpp
@@ -604,6 +604,105 @@ bool tryParseDescriptor(const QDomElement &el, const QString &path, const QStrin
}
catcher.addGradient(path, gradient);
+ } else if (classId == "Trnf") {
+
+ double xx = 1.0;
+ double xy = 0.0;
+ double yx = 0.0;
+ double yy = 1.0;
+ double tx = 0.0;
+ double ty = 0.0;
+
+ QDomNode child = el.firstChild();
+ while (!child.isNull()) {
+ QDomElement childEl = child.toElement();
+
+ QString type = childEl.attribute("type", "<unknown>");
+ QString key = childEl.attribute("key", "");
+ double value = KisDomUtils::toDouble(childEl.attribute("value"));
+
+
+ if (type == "Double") {
+ if (key == "xx") {
+ xx = value;
+ } else if (key == "xy") {
+ xy = value;
+ } else if (key == "yx") {
+ yx = value;
+ } else if (key == "yy") {
+ yy = value;
+ } else if (key == "tx") {
+ tx = value;
+ } else if (key == "ty") {
+ ty = value;
+ }
+ }
+
+ child = child.nextSibling();
+ }
+ catcher.addTransform(path, QTransform(xx, xy, yx, yy, tx, ty));
+ } else if (classId == "classFloatRect") {
+
+ QRectF rect;
+
+ QDomNode child = el.firstChild();
+ while (!child.isNull()) {
+ QDomElement childEl = child.toElement();
+
+ QString type = childEl.attribute("type", "<unknown>");
+ QString key = childEl.attribute("key", "");
+ double value = KisDomUtils::toDouble(childEl.attribute("value"));
+
+
+ if (type == "Double") {
+ if (key == "Top ") {
+ rect.setTop(value);
+ } else if (key == "Left") {
+ rect.setLeft(value);
+ } else if (key == "Btom") {
+ rect.setBottom(value);
+ } else if (key == "Rght") {
+ rect.setRight(value);
+ }
+ }
+ child = child.nextSibling();
+ }
+
+ if (el.attribute("key", " ") == "keyOriginShapeBBox") {
+ catcher.addUnitRect(path, "#Pxl", rect);
+ } else {
+ catcher.addRect(path, rect);
+ }
+ } else if (classId == "unitRect") {
+ QRectF rect;
+
+ QDomNode child = el.firstChild();
+ QString unit;
+ while (!child.isNull()) {
+ QDomElement childEl = child.toElement();
+
+ QString type = childEl.attribute("type", "<unknown>");
+ QString key = childEl.attribute("key", "");
+ unit = childEl.attribute("unit", unit);
+ double value = KisDomUtils::toDouble(childEl.attribute("value"));
+
+
+ if (type == "UnitFloat") {
+ if (key == "Top ") {
+ rect.setTop(value);
+ } else if (key == "Left") {
+ rect.setLeft(value);
+ } else if (key == "Btom") {
+ rect.setBottom(value);
+ } else if (key == "Rght") {
+ rect.setRight(value);
+ }
+ }
+ child = child.nextSibling();
+ }
+
+ catcher.addUnitRect(path, unit, rect);
+
} else {
retval = false;
}
diff --git a/plugins/impex/psd/psd_loader.cpp b/plugins/impex/psd/psd_loader.cpp
index 48846a338f..ef4d648362 100644
--- a/plugins/impex/psd/psd_loader.cpp
+++ b/plugins/impex/psd/psd_loader.cpp
@@ -21,6 +21,12 @@
#include <KoPathShape.h>
#include <KoShapeStroke.h>
#include <kis_shape_selection.h>
+#include <SvgShape.h>
+#include <KoShapeFactoryBase.h>
+#include <KoShapeRegistry.h>
+#include <KoXmlNS.h>
+#include <KoDocumentResourceManager.h>
+#include <KoProperties.h>
#include <kis_annotation.h>
#include <kis_types.h>
@@ -317,12 +323,69 @@ KisImportExportErrorCode PSDLoader::decode(QIODevice &io)
QDomDocument fillConfig;
KisAslCallbackObjectCatcher catcher;
- KoPathShape *vectorMask = nullptr;
+ KoShape *vectorMask = nullptr;
if (layerRecord->infoBlocks.keys.contains("vmsk") || layerRecord->infoBlocks.keys.contains("vsms")) {
- double width = m_image->width() / m_image->xRes();
- double height = m_image->height() / m_image->yRes();
- vectorMask = layerRecord->constructPathShape(layerRecord->infoBlocks.vectorMask.path, width, height);
- vectorMask->setUserData(new KisShapeSelectionMarker);
+ psd_vector_origination_data data;
+ if (!layerRecord->infoBlocks.vectorOriginationData.isNull()) {
+ KisAslCallbackObjectCatcher catcher;
+ psd_vector_origination_data::setupCatcher("/null", catcher, &data);
+ KisAslXmlParser parser;
+ parser.parseXML(layerRecord->infoBlocks.vectorOriginationData, catcher);
+ }
+ if (!data.canMakeParametricShape()) {
+ double width = m_image->width() / m_image->xRes();
+ double height = m_image->height() / m_image->yRes();
+ vectorMask = layerRecord->constructPathShape(layerRecord->infoBlocks.vectorMask.path, width, height);
+ vectorMask->setUserData(new KisShapeSelectionMarker);
+ } else {
+ QString el = data.elementType();
+ QList<KoShapeFactoryBase*> factories = KoShapeRegistry::instance()->factoriesForElement(KoXmlNS::draw, el);
+
+ QSizeF size;
+ double angle;
+ data.OriginalSizeAndAngle(size, angle);
+ QTransform scaleToPt = QTransform::fromScale(m_image->xRes(), m_image->yRes()).inverted();
+ size = QSizeF(size.width()/m_image->xRes(), size.height()/m_image->yRes());
+ Q_FOREACH(const KoShapeFactoryBase *f, factories) {
+ KoDocumentResourceManager manager;
+ KoProperties props;
+ if (el == "rect") {
+ props.setProperty("x", 0);
+ props.setProperty("y", 0);
+ props.setProperty("width", size.width());
+ props.setProperty("height", size.height());
+ } else if (el == "regular-polygon") {
+ props.setProperty("corners", data.originPolySides);
+ props.setProperty("convex", !data.isStar);
+
+ double angle = 360.0/(data.originPolySides*2);
+ double a = cos(kisDegreesToRadians(angle)) * 100.0;
+ double totalHeight = a + 100.0;
+ double l = size.height() / totalHeight * 100;
+
+ if (data.isStar) {
+ // 100% is a normal polygon.
+ a = cos(kisDegreesToRadians(angle)) * ((data.originPolyStarRatio*0.01) * l);
+ props.setProperty("baseRadius", a);
+ }
+ props.setProperty("tipRadius", l);
+ props.setProperty("baseRoundness", 0.0);
+ props.setProperty("tipRoundness", 0.0);
+ }
+ KoShape *shape = f->createShape(&props, &manager);
+ if (!shape)
+ continue;
+ shape->setSize(size);
+ QTransform t;
+ t.rotate(360.0-angle);
+
+ shape->setTransformation(t * scaleToPt.inverted() * data.transform * scaleToPt);
+ shape->setAbsolutePosition(scaleToPt.map(data.originShapeBBox.center()));
+
+ vectorMask = shape;
+ break;
+ }
+ }
}
if (layerRecord->infoBlocks.fillType == psd_fill_gradient) {
cfg = KisGeneratorRegistry::instance()->value("gradient")->defaultConfiguration(resourceProxy.resourcesInterface());