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++

Implement loading text data from psd with some formatting applied.

Wolthera van Hövell tot Westerflier812b9df7d7c6
diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
index 9d68bc7b70..53cfb08e03 100644
--- a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
+++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
@@ -20,6 +20,11 @@
#include <QStringList>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QTextCodec>
#include <QTextBlock>
#include <QTextLayout>
@@ -1115,6 +1120,297 @@ bool KoSvgTextShapeMarkupConverter::convertSvgToDocument(const QString &svgText,
return true;
}
+// PSD engine data parsing
+QJsonValue readJsonValue(QIODevice &dev, bool array) {
+ QJsonValue val;
+ if (!array) {
+ QJsonObject object;
+ QString key;
+ while(!dev.atEnd()) {
+ QByteArray line = dev.readLine();
+ if (line.isEmpty()) {
+ break;
+ }
+ // hacky
+ if (line.endsWith("\r")) {
+ line = line.trimmed();
+ line.append("\r");
+ } else {
+ line = line.trimmed();
+ }
+
+
+ if (line.startsWith("/")) {
+ QList<QByteArray> keyVal = line.split(' ');
+ if (keyVal.size() > 0) {
+ key = keyVal.first();
+ keyVal.removeFirst();
+ key.remove(0, 1);
+ //qDebug() << key;
+ }
+ if (keyVal.size() > 0) {
+ if (keyVal.first().startsWith("(")) {
+ line = keyVal.join(' ');
+ if (!line.endsWith(")")) {
+ QByteArray curLine = line;
+ while(!curLine.endsWith(")")) {
+ line = dev.readLine();
+ if (line.endsWith("\r")) {
+ line = line.trimmed();
+ line.append("\r");
+ } else {
+ line = line.trimmed();
+ }
+ curLine.append(line);
+ }
+ line = curLine;
+ }
+ line = line.remove(0, 1);
+ line.chop(1);
+ QTextCodec *Utf16Codec = QTextCodec::codecForName("UTF-16BE");
+ object.insert(key, Utf16Codec->toUnicode(line));
+
+ } else if (keyVal.first().startsWith("[")) {
+ if (keyVal.size() > 1) {
+ QJsonArray array;
+ for (int i = 0; i < keyVal.size(); i++) {
+ if (keyVal.at(i) != "[" ||
+ keyVal.at(i) != "]") {
+ bool res;
+ float val = keyVal.at(i).toFloat(&res);
+ if (res) {
+ array.append(val);
+ }
+ }
+ }
+ object.insert(key, array);
+ } else {
+ object.insert(key, readJsonValue(dev, true));
+ }
+ } else {
+ line = keyVal.join(' ');
+ if (line == "true") {
+ object.insert(key, true);
+ } else if (line == "false") {
+ object.insert(key, false);
+ } else {
+ bool res;
+ float val = line.toFloat(&res);
+ if (res) {
+ object.insert(key, val);
+ } else {
+ object.insert(key, QString(line));
+ }
+ }
+ }
+ }
+ } else if (line == "[") {
+ object.insert(key, readJsonValue(dev, true));
+ } else if (line == "<<") {
+ object.insert(key, readJsonValue(dev, false));
+ } else if (line == ">>") {
+ break;
+ }
+ }
+ val = object;
+ } else {
+ QJsonArray array;
+ while(!dev.atEnd()) {
+ QByteArray line = dev.readLine();
+ if (line.isEmpty()) {
+ break;
+ }
+ line = line.trimmed();
+ if (line == "[") {
+ array.append(readJsonValue(dev, true));
+ }
+
+ if (line == "<<") {
+ array.append(readJsonValue(dev, false));
+ }
+
+ if (line == "]") {
+ break;
+ }
+ }
+ val = array;
+ }
+
+ return val;
+}
+
+QColor colorFromPSDStyleSheet(QJsonObject color) {
+ QColor c(Qt::black);
+ if (color.value("Type").toInt() == 1) {
+ QJsonArray values = color.value("Values").toArray();
+ c = QColor::fromRgbF(values.at(1).toDouble(), values.at(2).toDouble(), values.at(3).toDouble(), values.at(0).toDouble());
+ }
+ return c;
+}
+
+QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, QString> fontNames) {
+ QStringList styles;
+
+ QStringList textDecor;
+ for (int i=0; i < PSDStyleSheet.keys().size(); i++) {
+ QString key = PSDStyleSheet.keys().at(i);
+
+ if (key == "FontSize") {
+ styles.append("font-size:"+QString::number(PSDStyleSheet.value(key).toDouble()));
+ } else if (key == "Font") {
+ QString family = fontNames.value(PSDStyleSheet.value(key).toInt());
+ styles.append("font-family:"+family);
+ } else if (key == "FillColor") {
+ bool fill = true;
+ if (PSDStyleSheet.keys().contains("FillFlag")) {
+ fill = PSDStyleSheet.value("FillFlag").toBool();
+ }
+ if (fill) {
+ QJsonObject color = PSDStyleSheet.value(key).toObject();
+ styles.append("fill:"+colorFromPSDStyleSheet(color).name());
+ } else {
+ styles.append("fill:none");
+ }
+ } else if (key == "StrokeColor") {
+ bool fill = true;
+ if (PSDStyleSheet.keys().contains("StrokeFlag")) {
+ fill = PSDStyleSheet.value("StrokeFlag").toBool();
+ }
+ if (fill) {
+ QJsonObject color = PSDStyleSheet.value(key).toObject();
+ styles.append("stroke:"+colorFromPSDStyleSheet(color).name());
+ } else {
+ styles.append("stroke:none");
+ }
+ } else if (key == "OutlineWidth") {
+ styles.append("stroke-width:"+QString::number(PSDStyleSheet.value(key).toDouble()));
+ } else if (key == "Tracking") {
+ double fontSize = PSDStyleSheet.value("FontSize").toDouble();
+ double letterSpacing = fontSize * (0.01 * PSDStyleSheet.value(key).toDouble());
+ styles.append("letter-spacing:"+QString::number(letterSpacing));
+ } else if (key == "Underline" && PSDStyleSheet.value(key).toBool()) {
+ textDecor.append("underline");
+ } if (key == "Strikethrough" && PSDStyleSheet.value(key).toBool()) {
+ textDecor.append("line-through");
+ }
+ }
+ if (!textDecor.isEmpty()) {
+ styles.append("text-decoration:"+textDecor.join(" "));
+ }
+ return styles.join("; ");
+}
+
+bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QByteArray ba, QString *svgText)
+{
+ debugFlake << "Convert from psd engine data";
+
+ QJsonObject root;
+ QBuffer dev(&ba);
+ if (dev.open(QIODevice::ReadOnly)) {
+ while(!dev.atEnd()) {
+ QByteArray buf = dev.readLine();
+ if (buf.trimmed() == "<<") {
+ root = readJsonValue(dev, false).toObject();
+ }
+ }
+ dev.close();
+ } else {
+ d->errors << dev.errorString();
+ return false;
+ }
+ qDebug() << "Parsed JSON Object" << root;
+
+ // This should proly be turned into a list of structs, where
+ // we search fontconfig on the name with FC_POSTSCRIPT_NAME,
+ // and we then note down the proper family name, slant, width and weight,
+ // so we can use that to set the proper svg values.
+ QMap<int, QString> fontNames;
+
+ QJsonObject engineDict = root.value("EngineDict").toObject();
+ if (engineDict.isEmpty()) {
+ d->errors << "No engine dict found in PSD engine data";
+ return false;
+ }
+ QJsonObject resourceDict = root.value("ResourceDict").toObject();
+ if (resourceDict.isEmpty()) {
+ d->errors << "No engine dict found in PSD engine data";
+ return false;
+ } else {
+ QJsonArray fonts = resourceDict.value("FontSet").toArray();
+ for (int i = 0; i < fonts.size(); i++) {
+ QJsonObject font = fonts.at(i).toObject();
+ fontNames.insert(i, font.value("Name").toString());
+ }
+ }
+ QJsonObject curve = root.value("Curve").toObject();
+ QJsonObject documentResources = root.value("DocumentResources").toObject();
+
+ QBuffer svgBuffer;
+ svgBuffer.open(QIODevice::WriteOnly);
+
+ QXmlStreamWriter svgWriter(&svgBuffer);
+
+ // disable auto-formatting to avoid axtra spaces appearing here and there
+ svgWriter.setAutoFormatting(false);
+
+ svgWriter.writeStartElement("text");
+
+ QJsonObject editor = engineDict.value("Editor").toObject();
+ QString text = "";
+ if (editor.isEmpty()) {
+ d->errors << "No editor dict found in PSD engine data";
+ return false;
+ } else {
+ text = editor.value("Text").toString();
+ text.replace("\r", "\n");
+ }
+
+ QJsonObject styleRun = engineDict.value("StyleRun").toObject();
+ if (styleRun.isEmpty()) {
+ d->errors << "No styleRun dict found in PSD engine data";
+ return false;
+ } else {
+ QJsonArray runLengthArray = styleRun.value("RunLengthArray").toArray();
+ QJsonArray runArray = styleRun.value("RunArray").toArray();
+ if (runLengthArray.isEmpty() && runArray.isEmpty()) {
+ d->errors << "No styleRun dict found in PSD engine data";
+ return false;
+ } else {
+ QJsonObject styleSheet = runArray.at(0).toObject().value("StyleSheet").toObject().value("StyleSheetData").toObject();
+ int length = 0;
+ int pos = 0;
+ for (int i = 0; i < runArray.size(); i++) {
+ QJsonObject newStyle = runArray.at(i).toObject().value("StyleSheet").toObject().value("StyleSheetData").toObject();
+ if (newStyle == styleSheet) {
+ length += runLengthArray.at(i).toInt();
+ } else {
+ svgWriter.writeStartElement("tspan");
+ svgWriter.writeAttribute("style", stylesForPSDStyleSheet(styleSheet, fontNames));
+ svgWriter.writeCharacters(text.mid(pos, length));
+ svgWriter.writeEndElement();
+ styleSheet = newStyle;
+ pos += length;
+ length = 0;
+ }
+ }
+ svgWriter.writeStartElement("tspan");
+ svgWriter.writeAttribute("style", stylesForPSDStyleSheet(styleSheet, fontNames));
+ svgWriter.writeCharacters(text.mid(pos));
+ svgWriter.writeEndElement();
+ }
+ }
+
+ svgWriter.writeEndElement();//text root element.
+
+ if (svgWriter.hasError()) {
+ d->errors << i18n("Unknown error writing SVG text element");
+ return false;
+ }
+ *svgText = QString::fromUtf8(svgBuffer.data()).trimmed();
+
+ return true;
+}
+
QStringList KoSvgTextShapeMarkupConverter::errors() const
{
return d->errors;
diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.h b/libs/flake/text/KoSvgTextShapeMarkupConverter.h
index ecf8629c26..a00790d853 100644
--- a/libs/flake/text/KoSvgTextShapeMarkupConverter.h
+++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.h
@@ -84,6 +84,7 @@ public:
*/
bool convertSvgToDocument(const QString &svgText, QTextDocument *doc);
+ bool convertPSDTextEngineDataToSVG(QByteArray ba, QString *svgText);
/**
* A list of errors happened during loading the user's text
diff --git a/libs/psd/psd_additional_layer_info_block.cpp b/libs/psd/psd_additional_layer_info_block.cpp
index 9b9d9f2d3f..22e9f5b419 100644
--- a/libs/psd/psd_additional_layer_info_block.cpp
+++ b/libs/psd/psd_additional_layer_info_block.cpp
@@ -235,6 +235,7 @@ void PsdAdditionalLayerInfoBlock::readImpl(QIODevice &io)
} else if (key == "vmsk" || key == "vsms") { // If key is "vsms" then we are writing for (Photoshop CS6) and the document will have a "vscg" key
} else if (key == "TySh") {
+ textData = KisAslReader::readTypeToolObjectSettings(io, byteOrder);
} else if (key == "ffxi") {
} else if (key == "lnsr") {
} else if (key == "shpa") {
diff --git a/libs/psd/psd_additional_layer_info_block.h b/libs/psd/psd_additional_layer_info_block.h
index 4befa2f297..5c02f0ac7c 100644
--- a/libs/psd/psd_additional_layer_info_block.h
+++ b/libs/psd/psd_additional_layer_info_block.h
@@ -634,6 +634,27 @@ struct KRITAPSD_EXPORT psd_layer_type_tool {
bool anti_alias {false}; // Anti alias on/off
};
+struct KRITAPSD_EXPORT psd_layer_type_shape {
+ QByteArray engineData;
+ QRectF bounds;
+
+ void setEngineData(QByteArray ba) {
+ engineData = ba;
+ }
+ void setTop(float val) {
+ bounds.setTop(val);
+ }
+ void setLeft(float val) {
+ bounds.setLeft(val);
+ }
+ void setRight(float val) {
+ bounds.setRight(val);
+ }
+ void setBottom(float val) {
+ bounds.setBottom(val);
+ }
+};
+
/**
* @brief The PsdAdditionalLayerInfoBlock class implements the Additional Layer Information block
*
@@ -675,6 +696,8 @@ public:
QDomDocument fillConfig;
psd_fill_type fillType {psd_fill_solid_color};
+ QDomDocument textData;
+
psd_section_type sectionDividerType;
QString sectionDividerBlendMode;
diff --git a/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp b/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
index 71c41585c1..4766a50ee3 100644
--- a/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
+++ b/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
@@ -53,6 +53,7 @@ typedef QHash<QString, ASLCallbackCurve> MapHashCurve;
typedef QHash<QString, ASLCallbackPattern> MapHashPattern;
typedef QHash<QString, ASLCallbackPatternRef> MapHashPatternRef;
typedef QHash<QString, ASLCallbackGradient> MapHashGradient;
+typedef QHash<QString, ASLCallbackRawData> MapHashRawData;
struct KisAslCallbackObjectCatcher::Private {
MapHashDouble mapDouble;
@@ -67,6 +68,7 @@ struct KisAslCallbackObjectCatcher::Private {
MapHashPattern mapPattern;
MapHashPatternRef mapPatternRef;
MapHashGradient mapGradient;
+ MapHashRawData mapRawData;
ASLCallbackNewStyle newStyleCallback;
};
@@ -189,6 +191,11 @@ void KisAslCallbackObjectCatcher::newStyleStarted()
}
}
+void KisAslCallbackObjectCatcher::addRawData(const QString &path, QByteArray ba)
+{
+ passToCallback(path, m_d->mapRawData, ba);
+}
+
/*****************************************************************/
/* Subscription methods */
/*****************************************************************/
@@ -257,3 +264,8 @@ void KisAslCallbackObjectCatcher::subscribeNewStyleStarted(ASLCallbackNewStyle c
{
m_d->newStyleCallback = callback;
}
+
+void KisAslCallbackObjectCatcher::subscribeRawData(const QString &path, ASLCallbackRawData callback)
+{
+ m_d->mapRawData.insert(path, callback);
+}
diff --git a/libs/psdutils/asl/kis_asl_callback_object_catcher.h b/libs/psdutils/asl/kis_asl_callback_object_catcher.h
index 4cee661c87..094d079eb6 100644
--- a/libs/psdutils/asl/kis_asl_callback_object_catcher.h
+++ b/libs/psdutils/asl/kis_asl_callback_object_catcher.h
@@ -29,6 +29,7 @@ using ASLCallbackPattern = std::function<void(const KoPatternSP, const QString &
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)>;
class KRITAPSDUTILS_EXPORT KisAslCallbackObjectCatcher : public KisAslObjectCatcher
{
@@ -49,6 +50,8 @@ public:
void addPatternRef(const QString &path, const QString &patternUuid, const QString &patternName) override;
void addGradient(const QString &path, KoAbstractGradientSP gradient) override;
void newStyleStarted() override;
+ void addRawData(const QString &path, QByteArray ba) override;
+
void subscribeDouble(const QString &path, ASLCallbackDouble callback);
void subscribeInteger(const QString &path, ASLCallbackInteger callback);
@@ -63,6 +66,7 @@ public:
void subscribePatternRef(const QString &path, ASLCallbackPatternRef callback);
void subscribeGradient(const QString &path, ASLCallbackGradient callback);
void subscribeNewStyleStarted(ASLCallbackNewStyle callback);
+ void subscribeRawData(const QString &path, ASLCallbackRawData 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 e0c7894f32..7a21628242 100644
--- a/libs/psdutils/asl/kis_asl_object_catcher.cpp
+++ b/libs/psdutils/asl/kis_asl_object_catcher.cpp
@@ -83,6 +83,11 @@ void KisAslObjectCatcher::addGradient(const QString &path, KoAbstractGradientSP
dbgKrita << "Unhandled:" << (m_arrayMode ? "[A]" : "[ ]") << path << "gradient" << value;
}
+void KisAslObjectCatcher::addRawData(const QString &path, QByteArray ba)
+{
+ dbgKrita << "Unhandled:" << (m_arrayMode ? "[A]" : "[ ]") << path << "bytearray";
+}
+
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 8f79152669..98ce7534c2 100644
--- a/libs/psdutils/asl/kis_asl_object_catcher.h
+++ b/libs/psdutils/asl/kis_asl_object_catcher.h
@@ -40,6 +40,7 @@ public:
virtual void addPattern(const QString &path, const KoPatternSP pattern, const QString &patternUuid);
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 newStyleStarted();
diff --git a/libs/psdutils/asl/kis_asl_reader.cpp b/libs/psdutils/asl/kis_asl_reader.cpp
index 5e9a9d5310..94d68f863d 100644
--- a/libs/psdutils/asl/kis_asl_reader.cpp
+++ b/libs/psdutils/asl/kis_asl_reader.cpp
@@ -187,10 +187,29 @@ void readChildObject(QIODevice &device, QDomElement *parent, QDomDocument *doc,
} else if (OSType == "alis") {
throw KisAslReaderUtils::ASLParseException("OSType 'alis' not implemented");
} else if (OSType == "tdta") {
- throw KisAslReaderUtils::ASLParseException("OSType 'tdta' not implemented");
+
+ if (key == "EngineData") {
+ // This is PSD text engine data, which outputs
+ // Carousel Object Structure (PDF) data, much like the "Txt2" additional info block.
+ quint32 len = 0.0;
+ SAFE_READ_EX(byteOrder, device, len);
+ QByteArray ba = device.read(len);
+
+ QDomCDATASection dataSection;
+ dataSection = doc->createCDATASection(ba.toBase64());
+ QDomElement dataElement = doc->createElement("node");
+ dataElement.setAttribute("type", "RawData");
+ dataElement.setAttribute("key", key);
+ dataElement.appendChild(dataSection);
+ parent->appendChild(dataElement);
+ } else {
+ throw KisAslReaderUtils::ASLParseException("OSType 'tdta' not implemented");
+ }
}
}
+
+
template<psd_byte_order byteOrder>
void readDescriptor(QIODevice &device, const QString &key, QDomElement *parent, QDomDocument *doc)
{
@@ -777,6 +796,108 @@ QDomDocument readFillLayerImpl(QIODevice &device)
return doc;
}
+template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
+QDomDocument readTypeToolObjectSettingsImpl(QIODevice &device);
+
+QDomDocument KisAslReader::readTypeToolObjectSettings(QIODevice &device, psd_byte_order byteOrder)
+{
+ switch (byteOrder) {
+ case psd_byte_order::psdLittleEndian:
+ return readTypeToolObjectSettingsImpl<psd_byte_order::psdLittleEndian>(device);
+ default:
+ return readTypeToolObjectSettingsImpl(device);
+ }
+}
+
+template<psd_byte_order byteOrder>
+QDomDocument readTypeToolObjectSettingsImpl(QIODevice &device)
+{
+ QDomDocument doc;
+
+ if (device.isSequential()) {
+ warnKrita << "WARNING: *** KisAslReader::readFillLayerPsdSection: the supplied"
+ << "IO device is sequential. Chances are that"
+ << "the fill config will *not* be loaded correctly!";
+ }
+ try {
+
+ {
+ quint16 descriptorVersion = GARBAGE_VALUE_MARK;
+ SAFE_READ_SIGNATURE_EX(byteOrder, device, descriptorVersion, 1);
+
+ }
+
+ // transform matrix.
+ quint64 xx = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, xx);
+ quint64 xy = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, xy);
+ quint64 yx = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, yx);
+ quint64 yy = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, yy);
+ quint64 tx = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, tx);
+ quint64 ty = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, ty);
+
+ {
+ quint16 textVersion = GARBAGE_VALUE_MARK;
+ SAFE_READ_SIGNATURE_EX(byteOrder, device, textVersion, 50);
+ quint32 descriptorVersion = GARBAGE_VALUE_MARK;
+ SAFE_READ_SIGNATURE_EX(byteOrder, device, descriptorVersion, 16);
+ }
+
+ QDomElement root = doc.createElement("asl");
+ doc.appendChild(root);
+
+ QDomElement transform = doc.createElement("transform");
+ transform.setAttribute("xx", QString::number(xx));
+ transform.setAttribute("xy", QString::number(xy));
+ transform.setAttribute("yx", QString::number(yx));
+ transform.setAttribute("yy", QString::number(yy));
+ transform.setAttribute("tx", QString::number(tx));
+ transform.setAttribute("ty", QString::number(ty));
+ //root.appendChild(transform);
+
+ // text layer data
+ Private::readDescriptor<byteOrder>(device, "", &root, &doc);
+
+ // warp data
+ {
+ quint16 textVersion = GARBAGE_VALUE_MARK;
+ SAFE_READ_SIGNATURE_EX(byteOrder, device, textVersion, 1);
+ quint32 descriptorVersion = GARBAGE_VALUE_MARK;
+ SAFE_READ_SIGNATURE_EX(byteOrder, device, descriptorVersion, 16);
+ }
+
+ Private::readDescriptor<byteOrder>(device, "", &root, &doc);
+
+ // bounding box
+ quint64 left = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, left);
+ quint64 top = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, top);
+ quint64 right = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, right);
+ quint64 bottom = GARBAGE_VALUE_MARK;
+ SAFE_READ_EX(byteOrder, device, bottom);
+
+ QDomElement bbox = doc.createElement("boundingBox");
+ bbox.setAttribute("left", QString::number(left));
+ bbox.setAttribute("top", QString::number(top));
+ bbox.setAttribute("right", QString::number(right));
+ bbox.setAttribute("bottom", QString::number(bottom));
+ //root.appendChild(bbox);
+
+
+ } catch (KisAslReaderUtils::ASLParseException &e) {
+ warnKrita << "WARNING: PSD: TySh 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 a8419d755f..54b78da76d 100644
--- a/libs/psdutils/asl/kis_asl_reader.h
+++ b/libs/psdutils/asl/kis_asl_reader.h
@@ -21,6 +21,8 @@ public:
static QDomDocument readLfx2PsdSection(QIODevice &device, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
static QDomDocument readFillLayer(QIODevice &device, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
+ static QDomDocument readTypeToolObjectSettings(QIODevice &device, psd_byte_order byteOrder = psd_byte_order::psdBigEndian);
+ //static QDomDocument readTypeToolWarp(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 a4af10d38b..5a4004111b 100644
--- a/libs/psdutils/asl/kis_asl_xml_parser.cpp
+++ b/libs/psdutils/asl/kis_asl_xml_parser.cpp
@@ -663,6 +663,22 @@ void parseElement(const QDomElement &el, const QString &parentPath, KisAslObject
} else if (type == "Boolean") {
int v = KisDomUtils::toInt(el.attribute("value", "0"));
catcher.addBoolean(buildPath(parentPath, key), v);
+ } else if (type == "RawData") {
+ QDomNode dataNode = el.firstChild();
+
+ if (!dataNode.isCDATASection()) {
+ warnKrita << "WARNING: failed to parse RawData XML section!";
+ return;
+ }
+
+ QDomCDATASection dataSection = dataNode.toCDATASection();
+ QByteArray data = dataSection.data().toLatin1();
+ data = QByteArray::fromBase64(data);
+
+ if (data.isEmpty()) {
+ warnKrita << "WARNING: failed to parse RawData XML section!";
+ }
+ catcher.addRawData(buildPath(parentPath, key), data);
} else {
warnKrita << "WARNING: XML (ASL) Unknown element type:" << type << ppVar(parentPath) << ppVar(key);
}
diff --git a/plugins/impex/psd/psd_loader.cpp b/plugins/impex/psd/psd_loader.cpp
index f941276b4f..d25771f274 100644
--- a/plugins/impex/psd/psd_loader.cpp
+++ b/plugins/impex/psd/psd_loader.cpp
@@ -15,6 +15,9 @@
#include <KoColorProfile.h>
#include <KoCompositeOp.h>
#include <KoUnit.h>
+#include <KoSvgTextShape.h>
+#include <KoSvgTextShapeMarkupConverter.h>
+#include <kis_shape_layer.h>
#include <kis_annotation.h>
#include <kis_types.h>
@@ -343,6 +346,30 @@ KisImportExportErrorCode PSDLoader::decode(QIODevice &io)
genlayer->setFilter(cfg);
layer = genlayer;
+
+ } else if (!layerRecord->infoBlocks.textData.isNull()) {
+ KisShapeLayerSP textLayer = new KisShapeLayer(m_doc->shapeController(), m_image, layerRecord->layerName, layerRecord->opacity);
+ KisAslCallbackObjectCatcher catcher;
+ psd_layer_type_shape text;
+ catcher.subscribeRawData("/TxLr/EngineData", std::bind(&psd_layer_type_shape::setEngineData, &text, _1));
+ catcher.subscribeUnitFloat("/TxLr/boundingBox/Left", "#Pnt", std::bind(&psd_layer_type_shape::setLeft, &text, _1));
+ catcher.subscribeUnitFloat("/TxLr/boundingBox/Top ", "#Pnt", std::bind(&psd_layer_type_shape::setTop, &text, _1));
+ catcher.subscribeUnitFloat("/TxLr/boundingBox/Rght", "#Pnt", std::bind(&psd_layer_type_shape::setRight, &text, _1));
+ catcher.subscribeUnitFloat("/TxLr/boundingBox/Btom", "#Pnt", std::bind(&psd_layer_type_shape::setBottom, &text, _1));
+ KisAslXmlParser parser;
+ parser.parseXML(layerRecord->infoBlocks.textData, catcher);
+ KoSvgTextShape *shape = new KoSvgTextShape();
+ KoSvgTextShapeMarkupConverter converter(shape);
+ QString svg;
+ QString styles;
+ bool res = converter.convertPSDTextEngineDataToSVG(text.engineData, &svg);
+ if (!res) {
+ qDebug() << converter.errors();
+ }
+ converter.convertFromSvg(svg, styles, m_image->bounds(), m_image->xRes()*72.0);
+ shape->setPosition(text.bounds.topLeft() - shape->boundingRect().topLeft());
+ textLayer->addShape(shape);
+ layer = textLayer;
} else {
layer = new KisPaintLayer(m_image, layerRecord->layerName, layerRecord->opacity);
if (!layerRecord->readPixelData(io, layer->paintDevice())) {