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: Load text objects from Txt2 chunk if available, fallback to TySh
Wolthera van Hövell tot Westerflier8f21787b57ce
diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp b/libs/flake/text/KoSvgTextShapeMarkupConverter.cppindex ebada28d7b..e4b42eb6c2 100644--- a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp+++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp@@ -1122,9 +1122,12 @@ bool KoSvgTextShapeMarkupConverter::convertSvgToDocument(const QString &svgText,QColor colorFromPSDStyleSheet(QJsonObject color) {QColor c(Qt::black);+ if (color.keys().contains("/Color")) {+ color = color["/Color"].toObject();+ }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());+ c = QColor::fromRgbF(values.at(1).toDouble(), values.at(2).toDouble(), values.at(3).toDouble(), 1);}return c;}@@ -1268,6 +1271,26 @@ QString stylesForPSDParagraphSheet(QJsonObject PSDParagraphSheet, QTransform sca//'everyline' uses a penalty based system like Knuth's method.unsupportedStyles << key;continue;+ } else if (key == "/ComposerEngine") {+ unsupportedStyles << key;+ continue;+ } else if (key == "/KurikaeshiMojiShori") {+ unsupportedStyles << key;+ continue;+ } else if (key == "/MojiKumiTable") {+ unsupportedStyles << key;+ continue;+ } else if (key == "/ParagraphDirection") {+ switch (PSDParagraphSheet.value(key).toInt()) {+ case 1:+ styles.append("direction:rtl");+ break;+ case 0:+ styles.append("direction:ltr");+ break;+ default:+ break;+ }} else {qWarning() << "Unknown PSD paragraph style key" << key << PSDParagraphSheet.value(key);}@@ -1298,6 +1321,8 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_psQStringList textDecor;QStringList baselineShift;QStringList fontVariantLigatures;+ QStringList fontVariantNumeric;+ QStringList fontFeatureSettings;for (int i=0; i < PSDStyleSheet.keys().size(); i++) {const QString key = PSDStyleSheet.keys().at(i);if (key == "/Font") {@@ -1314,7 +1339,7 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_psval = scale.map(QPointF(val, val)).y();styles.append("font-size:"+QString::number(val));continue;- } else if (key == "/AutoKerning") {+ } else if (key == "/AutoKerning" || key == "/AutoKern") {if (!PSDStyleSheet.value(key).toBool()) {styles.append("font-kerning: none");}@@ -1359,7 +1384,7 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_psdouble letterSpacing = (0.001 * PSDStyleSheet.value(key).toDouble());styles.append("letter-spacing:"+QString::number(letterSpacing)+"em");continue;- } else if (key == "BaselineShift") {+ } else if (key == "/BaselineShift") {if (PSDStyleSheet.value(key).toDouble() > 0) {double val = PSDStyleSheet.value(key).toDouble();val = scale.map(QPointF(val, val)).y();@@ -1383,6 +1408,7 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_ps} else if (key == "/FontBaseline") {// NOTE: This might also be better done with font-variant-position, though// we don't support synthetic font stuff, including super and sub script.+ // Actually, seems like this is specifically font-synthesisswitch (PSDStyleSheet.value(key).toInt()) {case 0:break;@@ -1396,32 +1422,123 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_psqDebug() << QString("Unknown value for %1:").arg(key) << PSDStyleSheet.value(key);}continue;- } else if (key == "/Underline") {+ } else if (key == "/FontOTPosition") {+ // NOTE: This might also be better done with font-variant-position, though+ // we don't support synthetic font stuff, including super and sub script.+ switch (PSDStyleSheet.value(key).toInt()) {+ case 0:+ break;+ case 1:+ styles.append("font-variant-position:super");+ break;+ case 2:+ styles.append("font-variant-position:sub");+ break;+ case 3:+ fontFeatureSettings.append("'numr' 1");+ break;+ case 4:+ fontFeatureSettings.append("'dnum' 1");+ break;+ default:+ qDebug() << QString("Unknown value for %1:").arg(key) << PSDStyleSheet.value(key);+ }+ continue;+ } else if (key == "/Underline" || key == "/UnderlinePosition") {if (PSDStyleSheet.value(key).toBool()) {textDecor.append("underline");}continue;- } else if (key == "/Strikethrough") {+ } else if (key == "/Strikethrough" || key == "/StrikethroughPosition") {if (PSDStyleSheet.value(key).toBool()) {textDecor.append("line-through");}continue;} else if (key == "/Ligatures") {- // font-variant: common-ligaturesif (!PSDStyleSheet.value(key).toBool()) {fontVariantLigatures.append("no-common-ligatures");}continue;- } else if (key == "/DLigatures") {- // font-variant: discretionary ligatures+ } else if (key == "/DLigatures" || key == "/DiscretionaryLigatures" || key == "/AlternateLigatures") {if (PSDStyleSheet.value(key).toBool()) {fontVariantLigatures.append("discretionary-ligatures");}continue;- } /* else if (key == "BaselineDirection") {- // unsure, might be vertical vs horizontal, but also might be default (2), ltr (1), rtl(0)?+ } else if (key == "/ContextualLigatures") {+ if (PSDStyleSheet.value(key).toBool()) {+ fontVariantLigatures.append("contextual");+ }+ continue;+ } else if (key == "/Fractions") {+ if (PSDStyleSheet.value(key).toBool()) {+ fontVariantNumeric.append("diagonal-fractions");+ }+ continue;+ } else if (key == "/Ordinals") {+ if (PSDStyleSheet.value(key).toBool()) {+ fontVariantNumeric.append("ordinal");+ }+ continue;+ } else if (key == "/Swash") {+ if (PSDStyleSheet.value(key).toBool()) {+ fontFeatureSettings.append("'swsh' 1");+ }+ continue;+ } else if (key == "/Titling") {+ if (PSDStyleSheet.value(key).toBool()) {+ fontFeatureSettings.append("'titl' 1");+ }+ continue;+ } else if (key == "/StylisticAlternates") {+ if (PSDStyleSheet.value(key).toBool()) {+ fontFeatureSettings.append("'salt' 1");+ }+ continue;+ } else if (key == "/Ornaments") {+ if (PSDStyleSheet.value(key).toBool()) {+ fontFeatureSettings.append("'ornm' 1");+ }+ continue;+ } else if (key == "/FigureStyle") {+ switch (PSDStyleSheet.value(key).toInt()) {+ case 0:+ break;+ case 1:+ fontVariantNumeric.append("tabular-nums");+ fontVariantNumeric.append("lining-nums");+ break;+ case 2:+ fontVariantNumeric.append("proportional-nums");+ fontVariantNumeric.append("oldstyle-nums");+ break;+ case 3:+ fontVariantNumeric.append("proportional-nums");+ fontVariantNumeric.append("lining-nums");+ break;+ case 4:+ fontVariantNumeric.append("tabular-nums");+ fontVariantNumeric.append("oldstyle-nums");+ break;+ default:+ qDebug() << QString("Unknown value for %1:").arg(key) << PSDStyleSheet.value(key);+ }+ continue;+ } else if (key == "/Italics") {+ // This is an educated guess: other italic happens via postscript name.+ if (PSDStyleSheet.value(key).toBool()) {+ fontFeatureSettings.append("'ital' 1");+ }+ continue;+ } else if (key == "/BaselineDirection") {+ if (PSDStyleSheet.value(key).toInt() == 1) {+ styles.append("text-orientation: upright");+ } else if (PSDStyleSheet.value(key).toInt() == 2) {+ styles.append("text-orientation: mixed");+ } else {+ qDebug() << key << PSDStyleSheet.value(key);+ }continue;- }*/ else if (key == "/Tsume") {+ } else if (key == "/Tsume") {// Reduce spacing around a single character. Partially related to text-spacing,// Tsume is reduction, Aki expansion, and both can be used as part of Mojikumi// However, in this particular case, the property seems to just reduce the space@@ -1487,7 +1604,7 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_psstyles.append("stroke:none");}continue;- } else if (key == "/OutlineWidth") {+ } else if (key == "/OutlineWidth" || key == "/LineWidth") {double val = PSDStyleSheet.value(key).toDouble();val = scale.map(QPointF(val, val)).y();styles.append("stroke-width:"+QString::number(val));@@ -1519,7 +1636,30 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_ps// number, which is odd, because it looks like it should be a point.// this controls how high or low the diacritic is on arabic text.continue;- }*/ else {+ }*/ else if (key == "/SlashedZero") {+ // font-variant: common-ligatures+ if (PSDStyleSheet.value(key).toBool()) {+ fontVariantNumeric.append("slashed-zero");+ }+ continue;+ } else if (key == "/StylisticSets") {+ int flags = PSDStyleSheet.value(key).toInt();+ if (flags & 1) {+ fontFeatureSettings.append("'ss01' 1");+ }+ if (flags & 2) {+ fontFeatureSettings.append("'ss02' 1");+ }+ if (flags & 4) {+ fontFeatureSettings.append("'ss03' 1");+ }+ if (flags & 8) {+ fontFeatureSettings.append("'ss04' 1");+ }+ // TODO: extend till ss20.++ continue;+ } else {if (key != "/FillFlag" && key != "/StrokeFlag" && key != "/AutoLeading") {qWarning() << "Unknown PSD character stylesheet style key" << key << PSDStyleSheet.value(key);}@@ -1540,11 +1680,19 @@ QString stylesForPSDStyleSheet(QJsonObject PSDStyleSheet, QMap<int, font_info_psif (!fontVariantLigatures.isEmpty()) {styles.append("font-variant-ligatures:"+fontVariantLigatures.join(" "));}+ if (!fontVariantNumeric.isEmpty()) {+ styles.append("font-variant-numeric:"+fontVariantNumeric.join(" "));+ }+ if (!fontFeatureSettings.isEmpty()) {+ styles.append("font-feature-settings:"+fontFeatureSettings.join(", "));+ }qWarning() << "Unsupported styles" << unsupportedStyles;return styles.join("; ");}-bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocument tySh,+bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(const QJsonDocument tySh,+ const QJsonDocument txt2,+ const int textIndex,QString *svgText,QString *svgStyles,QPointF &offset,@@ -1554,25 +1702,33 @@ bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocument{debugFlake << "Convert from psd engine data";+QJsonObject root = tySh.object();//qDebug() << "Parsed JSON Object" << root;+ bool loadFallback = txt2.isEmpty();+ QJsonObject docObjects = txt2.object().value("/DocumentObjects").toObject();- QJsonObject engineDict = root["/EngineDict"].toObject();- if (engineDict.isEmpty()) {+ QJsonObject textObject = docObjects.value("/TextObjects").toArray().at(textIndex).toObject();+ if (textObject.isEmpty() || loadFallback) {+ textObject = root["/EngineDict"].toObject();+ loadFallback = true;+ }+ if (textObject.isEmpty()) {d->errors << "No engine dict found in PSD engine data";return false;}QMap<int, font_info_psd> fontNames;- QJsonObject resourceDict = root["/ResourceDict"].toObject();+ QJsonObject resourceDict = loadFallback? root["/DocumentResources"].toObject(): txt2.object()["/DocumentResources"].toObject();if (resourceDict.isEmpty()) {d->errors << "No engine dict found in PSD engine data";return false;} else {// PSD only stores the postscript name, and we'll need a bit more information than that.- QJsonArray fonts = resourceDict["/FontSet"].toArray();+ QJsonArray fonts = loadFallback? resourceDict["/FontSet"].toArray(): resourceDict["/FontSet"].toObject()["/Resources"].toArray();for (int i = 0; i < fonts.size(); i++) {- QJsonObject font = fonts.at(i).toObject();+ QJsonObject font = loadFallback? fonts.at(i).toObject(): fonts.at(i).toObject()["/Resource"].toObject()["/Identifier"].toObject();+ //qDebug() << font;font_info_psd fontInfo;QString postScriptName = font.value("/Name").toString();QString foundPostScriptName;@@ -1582,72 +1738,101 @@ bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocumentfontInfo.weight,fontInfo.width,fontInfo.italic);+if (postScriptName != foundPostScriptName) {- d->errors << QString("Font %1 not found, substituting %2").arg(postScriptName).arg(foundPostScriptName);+ fontInfo.familyName = "sans-serif";+ d->errors << QString("Font %1 not found, substituting %2").arg(postScriptName).arg(fontInfo.familyName);}fontNames.insert(i, fontInfo);}}- QString paragraphStyle = isHorizontal? "writing-mode: horizontal-tb;": "writing-mode: vertical-rl;";- paragraphStyle += " white-space: pre-wrap;";+QString inlineSizeString;QRectF bounds;- QJsonObject rendered = engineDict["/Rendered"].toObject();- // rendering info...- if (!rendered.isEmpty()) {- QJsonObject shapeChild = rendered["/Shapes"].toObject()["/Children"].toArray()[0].toObject();- int shapeType = shapeChild["/ShapeType"].toInt();- if (shapeType == 1) {- QJsonArray BoxBounds = shapeChild["/Cookie"].toObject()["/Photoshop"].toObject()["/BoxBounds"].toArray();- bounds = QRectF(BoxBounds[0].toDouble(), BoxBounds[1].toDouble(), BoxBounds[2].toDouble(), BoxBounds[3].toDouble());- bounds = scaleToPt.mapRect(bounds);- if (isHorizontal) {- inlineSizeString = " inline-size:"+QString::number(bounds.width())+";";- } else {- inlineSizeString = " inline-size:"+QString::number(bounds.height())+";";- }- }- qDebug() << bounds;- }--+ // load text shapeKoPathShape *textShape = nullptr;- // For some reason, the easiest way to tell if shape-inside is to check whether the character range is set.double textPathStartOffset = -3;+ int textType = 0;bool reversed = false;- QJsonObject curve = root["/Curve"].toObject();- if (!curve.isEmpty()) {- QPainterPath textCurve;- QJsonArray points = curve["/Points"].toArray();- QJsonArray range = curve["/TextOnPathTRange"].toArray();- reversed = curve["/Reversed"].toBool();- int length = points.size()/8;- for (int i = 0; i < length; i++) {- int iAdjust = i*8;- QPointF p1(points[iAdjust ].toDouble(), points[iAdjust+1].toDouble());- QPointF p2(points[iAdjust+2].toDouble(), points[iAdjust+3].toDouble());- QPointF p3(points[iAdjust+4].toDouble(), points[iAdjust+5].toDouble());- QPointF p4(points[iAdjust+6].toDouble(), points[iAdjust+7].toDouble());-- if (i == 0 || textCurve.currentPosition() != p1) {- textCurve.moveTo(scaleToPt.map(p1));- }- if (p1==p2 && p3==p4) {- textCurve.lineTo(scaleToPt.map(p4));- } else {- textCurve.cubicTo(scaleToPt.map(p2), scaleToPt.map(p3), scaleToPt.map(p4));+ if (loadFallback) {+ QJsonObject rendered = textObject["/Rendered"].toObject();+ // rendering info...+ if (!rendered.isEmpty()) {+ QJsonObject shapeChild = rendered["/Shapes"].toObject()["/Children"].toArray()[0].toObject();+ int shapeType = shapeChild["/ShapeType"].toInt();+ if (shapeType == 1) {+ QJsonArray BoxBounds = shapeChild["/Cookie"].toObject()["/Photoshop"].toObject()["/BoxBounds"].toArray();+ bounds = QRectF(BoxBounds[0].toDouble(), BoxBounds[1].toDouble(), BoxBounds[2].toDouble(), BoxBounds[3].toDouble());+ bounds = scaleToPt.mapRect(bounds);+ if (isHorizontal) {+ inlineSizeString = " inline-size:"+QString::number(bounds.width())+";";+ } else {+ inlineSizeString = " inline-size:"+QString::number(bounds.height())+";";+ }}+ qDebug() << bounds;}- // When there's text-in-shape (instead of text-on-path), range seems to be between -3 and -3.- if (!range.isEmpty()) {- textPathStartOffset = range[0].toDouble();+ } else {+ QJsonObject view = textObject["/View"].toObject();+ int textFrameIndex = view["/Frames"].toArray()[0].toObject()["/Resource"].toInt();+ QJsonArray textFrameSet = resourceDict["/TextFrameSet"].toObject()["/Resources"].toArray();+ QJsonObject textFrame = textFrameSet.at(textFrameIndex).toObject()["/Resource"].toObject();+++ if (!textFrame.isEmpty()) {+ textType = textFrame["/Data"].toObject()["/Type"].toInt();+ //qDebug() << textFrame;++ if (textType > 0) {+ QPainterPath textCurve;+ QJsonObject data = textFrame["/Data"].toObject();+ QJsonArray points = textFrame["/Bezier"].toObject()["/Points"].toArray();+ QJsonArray range = data["/TextOnPathTRange"].toArray();+ QJsonArray fm = data["/FrameMatrix"].toArray();+ QJsonObject pathData = data["/PathData"].toObject();+ reversed = pathData["/Flip"].toBool();++ QJsonValue lineOrientation = data["/LineOrientation"];+ if (!lineOrientation.isUndefined()) {+ if (lineOrientation.toInt() == 2) {+ isHorizontal = false;+ }+ }+ QTransform frameMatrix = scaleToPt;+ if (fm.size() == 6) {+ frameMatrix = QTransform(fm[0].toDouble(), fm[1].toDouble(), fm[2].toDouble(), fm[3].toDouble(), fm[4].toDouble(), fm[5].toDouble());+ frameMatrix = frameMatrix * scaleToPt;+ }++ int length = points.size()/8;+ for (int i = 0; i < length; i++) {+ int iAdjust = i*8;+ QPointF p1(points[iAdjust ].toDouble(), points[iAdjust+1].toDouble());+ QPointF p2(points[iAdjust+2].toDouble(), points[iAdjust+3].toDouble());+ QPointF p3(points[iAdjust+4].toDouble(), points[iAdjust+5].toDouble());+ QPointF p4(points[iAdjust+6].toDouble(), points[iAdjust+7].toDouble());++ if (i == 0 || textCurve.currentPosition() != frameMatrix.map(p1)) {+ textCurve.moveTo(frameMatrix.map(p1));+ }+ if (p1==p2 && p3==p4) {+ textCurve.lineTo(frameMatrix.map(p4));+ } else {+ textCurve.cubicTo(frameMatrix.map(p2), frameMatrix.map(p3), frameMatrix.map(p4));+ }+ }+ if (textCurve.elementCount() > 1) {+ textShape = KoPathShape::createShapeFromPainterPath(textCurve);+ }+ if (!range.isEmpty()) {+ textPathStartOffset = range[0].toDouble();+ }+ }}- textShape = KoPathShape::createShapeFromPainterPath(textCurve);- qDebug() << curve;}-- QJsonObject documentResources = root["/DocumentResources"].toObject();+ QString paragraphStyle = isHorizontal? "writing-mode: horizontal-tb;": "writing-mode: vertical-rl;";+ paragraphStyle += " white-space: pre-wrap;";QBuffer svgBuffer;QBuffer styleBuffer;@@ -1680,7 +1865,7 @@ bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocumentsvgWriter.writeStartElement("text");- QJsonObject editor = engineDict["/Editor"].toObject();+ QJsonObject editor = loadFallback? textObject["/Editor"].toObject() : textObject["/Model"].toObject();QString text = "";if (editor.isEmpty()) {d->errors << "No editor dict found in PSD engine data";@@ -1690,24 +1875,27 @@ bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocumenttext.replace("\r", "\n");}- if (engineDict.contains("/AntiAlias")) {- int antiAliasing = engineDict["/AntiAlias"].toInt();- //0 = None, 1 = Sharp, 2 = Crisp, 3 = Strong, 4 = Smooth- if (antiAliasing) {- svgWriter.writeAttribute("text-rendering", "auto");- } else {- svgWriter.writeAttribute("text-rendering", "OptimizeSpeed");- }+ int antiAliasing = 0;+ antiAliasing = loadFallback? textObject["/AntiAlias"].toInt() : textObject["/StorySheet"].toObject()["/AntiAlias"].toInt();+ //0 = None, 1 = Sharp, 2 = Crisp, 3 = Strong, 4 = Smooth+ if (antiAliasing == 4) {+ svgWriter.writeAttribute("text-rendering", "auto");+ } else {+ svgWriter.writeAttribute("text-rendering", "OptimizeSpeed");}- QJsonObject paragraphRun = engineDict["/ParagraphRun"].toObject();+ QJsonObject paragraphRun = loadFallback? textObject["/ParagraphRun"].toObject() : editor["/ParagraphRun"].toObject();if (!paragraphRun.isEmpty()) {//QJsonArray runLengthArray = paragraphRun.value("RunLengthArray").toArray();QJsonArray runArray = paragraphRun["/RunArray"].toArray();- QJsonObject styleSheet = runArray[0].toObject()["/ParagraphSheet"].toObject()["/Properties"].toObject();+ QString features = loadFallback? "/Properties": "/Features";+ QJsonObject style = loadFallback? runArray.at(0).toObject() : runArray.at(0).toObject()["/RunData"].toObject();+ QJsonObject parasheet = loadFallback? runArray[0].toObject()["/ParagraphSheet"].toObject():+ runArray.at(0).toObject()["/RunData"].toObject()["/ParagraphSheet"].toObject();+ QJsonObject styleSheet = parasheet[features].toObject();QString styleString = stylesForPSDParagraphSheet(styleSheet, scaleToPt);- if (textPathStartOffset < 0) {+ if (textType < 2) {if (textShape) {offsetByAscent = false;paragraphStyle += " shape-inside:url(#textShape);";@@ -1734,7 +1922,7 @@ bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocument}bool textPathCreated = false;- if (textShape && textPathStartOffset >= 0) {+ if (textShape && textType == 2) {svgWriter.writeStartElement("textPath");textPathCreated = true;svgWriter.writeAttribute("path", textShape->toString());@@ -1744,32 +1932,37 @@ bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocumentsvgWriter.writeAttribute("startOffset", QString::number(textPathStartOffset));}- QJsonObject styleRun = engineDict.value("/StyleRun").toObject();+ QJsonObject styleRun = loadFallback? textObject.value("/StyleRun").toObject(): editor.value("/StyleRun").toObject();if (styleRun.isEmpty()) {d->errors << "No styleRun dict found in PSD engine data";return false;} else {+ QString features = loadFallback? "/StyleSheetData": "/Features";QJsonArray runLengthArray = styleRun.value("/RunLengthArray").toArray();QJsonArray runArray = styleRun.value("/RunArray").toArray();- if (runLengthArray.isEmpty() && runArray.isEmpty()) {+ if (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();+ QJsonObject style = loadFallback? runArray.at(0).toObject() : runArray.at(0).toObject()["/RunData"].toObject();+ QJsonObject styleSheet = style.value("/StyleSheet").toObject().value(features).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();+ style = loadFallback? runArray.at(i).toObject() : runArray.at(i).toObject()["/RunData"].toObject();+ int l = loadFallback? runLengthArray.at(i).toInt(): runArray.at(i).toObject().value("/Length").toInt();++ QJsonObject newStyleSheet = style.value("/StyleSheet").toObject().value(features).toObject();+ if (newStyleSheet == styleSheet) {+ length += l;} else {svgWriter.writeStartElement("tspan");svgWriter.writeAttribute("style", stylesForPSDStyleSheet(styleSheet, fontNames, scaleToPt));svgWriter.writeCharacters(text.mid(pos, length));svgWriter.writeEndElement();- styleSheet = newStyle;+ styleSheet = newStyleSheet;pos += length;- length = runLengthArray.at(i).toInt();+ length = l;}}svgWriter.writeStartElement("tspan");@@ -1792,6 +1985,7 @@ bool KoSvgTextShapeMarkupConverter::convertPSDTextEngineDataToSVG(QJsonDocument}*svgText = QString::fromUtf8(svgBuffer.data()).trimmed();*svgStyles = QString::fromUtf8(styleBuffer.data()).trimmed();+ //qDebug() << *svgText;return true;}diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.h b/libs/flake/text/KoSvgTextShapeMarkupConverter.hindex a122d2527c..36ccab1cfa 100644--- a/libs/flake/text/KoSvgTextShapeMarkupConverter.h+++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.h@@ -84,7 +84,9 @@ public:*/bool convertSvgToDocument(const QString &svgText, QTextDocument *doc);- bool convertPSDTextEngineDataToSVG(QJsonDocument tySh,+ bool convertPSDTextEngineDataToSVG(const QJsonDocument tySh,+ const QJsonDocument txt2,+ const int textIndex,QString *svgText,QString *svgStyles,QPointF &offset,diff --git a/libs/psd/psd_additional_layer_info_block.cpp b/libs/psd/psd_additional_layer_info_block.cppindex 20111fc1c2..e711f6b5c4 100644--- a/libs/psd/psd_additional_layer_info_block.cpp+++ b/libs/psd/psd_additional_layer_info_block.cpp@@ -17,6 +17,7 @@#include <asl/kis_asl_reader_utils.h>#include <asl/kis_asl_writer.h>#include <asl/kis_asl_writer_utils.h>+#include <cos/kis_txt2_utls.h>PsdAdditionalLayerInfoBlock::PsdAdditionalLayerInfoBlock(const PSDHeader &header)@@ -318,9 +319,9 @@ void PsdAdditionalLayerInfoBlock::readImpl(QIODevice &io)} else if (key == "CgEd") {} else if (key == "Txt2") { // global text data, basically the same as an Illustrator text object.// Docs say "first 4 are length", this is not true for this particular block, only when in ASL is first 4 length.- //QByteArray ba = io.read(blockSize);- //KisCosParser p;- //qDebug() << p.parseCosToJson(&ba);+ QByteArray ba = io.read(blockSize);+ KisCosParser p;+ txt2Data = KisTxt2Utils::uncompressKeys(p.parseCosToJson(&ba));} else if (key == "pths") {} else if (key == "anFX") {} else if (key == "FMsk") {diff --git a/libs/psd/psd_additional_layer_info_block.h b/libs/psd/psd_additional_layer_info_block.hindex 1cc50780ac..f8fe7a871e 100644--- a/libs/psd/psd_additional_layer_info_block.h+++ b/libs/psd/psd_additional_layer_info_block.h@@ -833,6 +833,9 @@ struct KRITAPSD_EXPORT psd_layer_type_shape {KisCosParser parser;engineData = parser.parseCosToJson(&ba);}+ void setIndex(int val) {+ textIndex = val;+ }void setTop(float val) {bounds.setTop(val);}@@ -854,6 +857,7 @@ struct KRITAPSD_EXPORT psd_layer_type_shape {}static void setupCatcher(const QString path, KisAslCallbackObjectCatcher &catcher, psd_layer_type_shape *data) {+ catcher.subscribeInteger(path + "/TxLr/TextIndex", std::bind(&psd_layer_type_shape::setIndex, data, std::placeholders::_1));catcher.subscribeRawData(path + "/TxLr/EngineData", std::bind(&psd_layer_type_shape::setEngineData, data, std::placeholders::_1));catcher.subscribeEnum(path + "/TxLr/Ornt", "Ornt", std::bind(&psd_layer_type_shape::setWritingMode, data, std::placeholders::_1));catcher.subscribeUnitFloat(path + "/TxLr/bounds/Left", "#Pnt", std::bind(&psd_layer_type_shape::setLeft, data, std::placeholders::_1));@@ -1188,7 +1192,10 @@ public:QString unicodeLayerName;QDomDocument layerStyleXml;+QVector<QDomDocument> embeddedPatterns;+ QJsonDocument txt2Data;+quint16 labelColor{0}; // layer color.QDomDocument fillConfig;diff --git a/libs/psdutils/CMakeLists.txt b/libs/psdutils/CMakeLists.txtindex 00620316e9..48a33b5138 100644--- a/libs/psdutils/CMakeLists.txt+++ b/libs/psdutils/CMakeLists.txt@@ -12,6 +12,7 @@ set(kritapsdutils_LIB_SRCScos/kis_cos_parser.cppcos/kis_cos_writer.cpp+ cos/kis_txt2_utls.cpp)kis_add_library(kritapsdutils SHARED ${kritapsdutils_LIB_SRCS})diff --git a/libs/psdutils/cos/kis_txt2_utls.cpp b/libs/psdutils/cos/kis_txt2_utls.cppnew file mode 100644index 0000000000..26750abe94--- /dev/null+++ b/libs/psdutils/cos/kis_txt2_utls.cpp@@ -0,0 +1,810 @@+/*+ * SPDX-FileCopyrightText: 2023 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include "kis_txt2_utls.h"+#include <QJsonObject>+#include <QJsonValue>+#include <QJsonArray>++QJsonObject uncompressColor(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;+ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ if (key == "/0") {+ QJsonObject color = val.toObject();+ QJsonObject newColor;+ Q_FOREACH(QString key, color.keys()) {+ if (key == "/1") {+ newColor.insert("/Values", color.value(key));+ } else if (key == "/0") {+ newColor.insert("/Type", color.value(key));+ } else {+ newColor.insert(key, color.value(key));+ }+ }+ newObject.insert("/Color", newColor);+ } else if (key == "/99") {+ newObject.insert("/StreamTag", val);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressStyleSheetFeatures(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ const QMap<QString, QString> keyList{+ {"/0", "/Font"},+ {"/1", "/FontSize"},+ {"/2", "/FauxBold"},+ {"/3", "/FauxItalic"},+ {"/4", "/AutoLeading"},++ {"/5", "/Leading"},+ {"/6", "/HorizontalScale"},+ {"/7", "/VerticalScale"},+ {"/8", "/Tracking"},+ {"/9", "/BaselineShift"},++ {"/10", "/CharacterRotation"},+ {"/11", "/AutoKern"},+ {"/12", "/FontCaps"},+ {"/13", "/FontBaseline"},+ {"/14", "/FontOTPosition"},++ {"/15", "/StrikethroughPosition"},+ {"/16", "/UnderlinePosition"},+ {"/17", "/UnderlineOffset"},+ {"/18", "/Ligatures"},+ {"/19", "/DiscretionaryLigatures"},++ {"/20", "/ContextualLigatures"},+ {"/21", "/AlternateLigatures"},+ {"/22", "/OldStyle"},+ {"/23", "/Fractions"},+ {"/24", "/Ordinals"},++ {"/25", "/Swash"},+ {"/26", "/Titling"},+ {"/27", "/ConnectionForms"},+ {"/28", "/StylisticAlternates"},+ {"/29", "/Ornaments"},++ {"/30", "/FigureStyle"},+ {"/31", "/ProportionalMetrics"},+ {"/32", "/Kana"},+ {"/33", "/Italics"},+ {"/34", "/Ruby"},++ {"/35", "/BaselineDirection"},+ {"/36", "/Tsume"},+ {"/37", "/StyleRunAlignment"},+ {"/38", "/Language"},+ {"/39", "/JapaneseAlternateFeature"},++ {"/40", "/EnableWariChu"},+ {"/41", "/WariChuLineCount"},+ {"/42", "/WariChuLineGap"},+ {"/43", "/WariChuSubLineAmount"},+ {"/44", "/WariChuWidowAmount"},++ {"/45", "/WariChuOrphanAmount"},+ {"/46", "/WariChuJustification"},+ {"/47", "/TCYUpDownAdjustment"},+ {"/48", "/TCYLeftRightAdjustment"},+ {"/49", "/LeftAki"},++ {"/50", "/RightAki"},+ {"/51", "/JiDori"},+ {"/52", "/NoBreak"},+ //{"/53", "/FillColor"},+ //{"/54", "/StrokeColor"},++ {"/55", "/Blend"},+ {"/56", "/FillFlag"},+ {"/57", "/StrokeFlag"},+ {"/58", "/FillFirst"},+ {"/59", "/FillFirst"},++ {"/60", "/StrokeOverPrint"},+ {"/61", "/LineCap"},+ {"/62", "/LineJoin"},+ {"/63", "/LineWidth"},+ {"/64", "/MiterLimit"},++ {"/65", "/LineDashOffset"},+ {"/66", "/LineDashArray"},+ {"/67", "/Type"},+ {"/68", "/Kashidas"},+ {"/69", "/DirOverride"},++ {"/70", "/DigitSet"},+ {"/71", "/DiacVPos"},+ {"/72", "/DiacXOffset"},+ {"/73", "/DiacYOffset"},+ {"/74", "/OverlapSwash"},++ {"/75", "/JustificationAlternates"},+ {"/76", "/StretchedAlternates"},+ {"/77", "/FillVisibleFlag"},+ {"/78", "/StrokeVisibleFlag"},+ //{"/79", "/FillBackgroundColor"},++ {"/80", "/FillBackgroundFlag"},+ {"/81", "/UnderlineStyle"},+ {"/82", "/DashedUnderlineGapLength"},+ {"/83", "/DashedUnderlineDashLength"},+ {"/84", "/SlashedZero"},++ {"/85", "/StylisticSets"},+ {"/86", "/CustomFeature"},+ {"/87", "/MarkYDistFromBaseline"},+ {"/88", "/AutoMydfb"},+ {"/89", "/RefFontSize"},++ {"/90", "/FontSizeRefType"},+ {"/92", "/MagicLineGap"},+ {"/92", "/MagicWordGap"},+ };++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ if (key == "/53") {+ newObject.insert("/FillColor", uncompressColor(val.toObject()));+ } else if (key == "/54") {+ newObject.insert("/StrokeColor", uncompressColor(val.toObject()));+ } else if (key == "/79") {+ newObject.insert("/FillBackgroundColor", uncompressColor(val.toObject()));+ } else if (keyList.keys().contains(key)) {+ newObject.insert(keyList.value(key), val);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressParagraphSheetFeatures(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ const QMap<QString, QString> keyList{+ {"/0", "/Justification"},+ {"/1", "/FirstLineIndent"},+ {"/2", "/StartIndent"},+ {"/3", "/EndIndent"},+ {"/4", "/SpaceBefore"},++ {"/5", "/SpaceAfter"},+ {"/6", "/DropCaps"},+ {"/7", "/AutoLeading"},+ {"/8", "/LeadingType"},+ {"/9", "/AutoHyphenate"},++ {"/10", "/HyphenatedWordSize"},+ {"/11", "/PreHyphen"},+ {"/12", "/PostHyphen"},+ {"/13", "/ConsecutiveHyphens"},+ {"/14", "/Zone"},++ {"/15", "/HyphenateCapitalized"},+ {"/16", "/HyphenationPreference"},+ {"/17", "/WordSpacing"},+ {"/18", "/LetterSpacing"},+ {"/19", "/GlyphSpacing"},++ {"/20", "/SingleWordJustification"},+ {"/21", "/Hanging"},+ {"/22", "/AutoTCY"},+ {"/23", "/KeepTogether"},+ {"/24", "/BurasagariType"},++ {"/25", "/KinsokuOrder"},+ {"/26", "/Kinsoku"},+ {"/27", "/KurikaeshiMojiShori"},+ {"/28", "/MojiKumiTable"},+ {"/29", "/EveryLineComposer"},++ {"/30", "/TabStops"},+ {"/31", "/DefaultTabWidth"},+ //{"/32", "/DefaultStyle"},+ {"/33", "/ParagraphDirection"},+ {"/34", "/JustificationMethod"},++ {"/35", "/ComposerEngine"},+ {"/36", "/ListStyle"},+ {"/37", "/ListTier"},+ {"/38", "/ListSkip"},+ {"/39", "/ListOffset"},++ {"/40", "/KashidaWidth"}+ };++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ if (key == "/32") {+ newObject.insert("/DefaultStyle", uncompressStyleSheetFeatures(val.toObject()));+ } else if (keyList.keys().contains(key)) {+ newObject.insert(keyList.value(key), val);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressKeysStyleSheetSet(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ QJsonArray resources = object.value("/0").toArray();+ QJsonArray newResources;++ Q_FOREACH(QJsonValue val, resources) {+ QJsonObject resource = val.toObject().value("/0").toObject();+ QJsonObject newResource;+ Q_FOREACH(QString key, resource.keys()) {+ QMap<QString, QString> keyList {{"/0", "/Name"}, {"/5", "/Parent"}, {"/97", "/UUID"}};+ QJsonValue rdVal = resource.value(key);+ if (key == "/6") {+ newResource.insert("/Features", uncompressStyleSheetFeatures(rdVal.toObject()));+ } else if (keyList.keys().contains(key)) {+ newResource.insert(keyList.value(key), rdVal);+ } else {+ newResource.insert(key, rdVal);+ }+ }++ newResources.append(QJsonObject({{"/Resource", newResource}}));+ }+ newObject.insert("/Resources", newResources);+ return newObject;+}++QJsonObject uncompressKeysParagraphSheetSet(const QJsonObject object) {+ qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;+ QJsonArray resources = object.value("/0").toArray();+ QJsonArray newResources;++ const QMap<QString, QString> keyList {{"/0", "/Name"}, {"/6", "/Parent"}, {"/97", "/UUID"}};++ Q_FOREACH(QJsonValue val, resources) {+ QJsonObject resource = val.toObject().value("/0").toObject();+ QJsonObject newResource;+ Q_FOREACH(QString key, resource.keys()) {+ QJsonValue rdVal = resource.value(key);+ if (key == "/5") {+ newResource.insert("/Features", uncompressParagraphSheetFeatures(rdVal.toObject()));+ } else if (keyList.keys().contains(key)) {+ newResource.insert(keyList.value(key), rdVal);+ } else {+ newResource.insert(key, rdVal);+ }+ }++ newResources.append(QJsonObject({{"/Resource", newResource}}));+ }+ newObject.insert("/Resources", newResources);+ return newObject;+}++QJsonObject uncompressTextFrameData(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;+ const QMap<QString, QString> keyList {+ {"/0", "/Type"},+ {"/1", "/LineOrientation"},+ {"/2", "/FrameMatrix"},+ {"/3", "/RowCount"},+ {"/4", "/ColumnCount"},++ {"/5", "/RowMajorOrder"},+ {"/6", "/TextOnPathTRange"},+ {"/7", "/RowGutter"},+ {"/8", "/ColumnGutter"},+ {"/9", "/Spacing"},++ {"/10", "/FirstBaseAlignment"},+ // {"/11", "/PathData"},+ //{"/12", ""},+ {"/13", "/VerticalAlignment"},+ };++ const QMap<QString, QString> pathDataList {+ {"/0", "/Flip"},+ {"/1", "/Effect"},+ {"/2", "/Alignment"},+ {"/4", "/Spacing"},+ {"/18", "/Spacing2"},+ };++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ if (key == "/11") {+ QJsonObject data = val.toObject();+ QJsonObject newData;+ Q_FOREACH(QString key2, data.keys()) {+ if (pathDataList.keys().contains(key2)) {+ newData.insert(pathDataList.value(key2), data.value(key2));+ } else {+ newData.insert(key2, data.value(key2));+ }+ }+ newObject.insert("/PathData", newData);+ } else if (keyList.keys().contains(key)) {+ newObject.insert(keyList.value(key), val);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressKeysTextFrameSet(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ QJsonArray resources = object.value("/0").toArray();+ QJsonArray newResources;+ const QMap<QString, QString> keyList {+ {"/0", "/Position"},+ {"/1", "/Bezier"},+ //{"/2", "/Data"},+ {"/97", "/UUID"}+ };++ Q_FOREACH(QJsonValue val, resources) {+ QJsonObject resource = val.toObject().value("/0").toObject();+ QJsonObject newResource;+ Q_FOREACH(QString key2, resource.keys()) {+ QJsonValue rdVal = resource.value(key2);+ if (key2 == "/5") {+ newResource.insert("/Features", uncompressStyleSheetFeatures(rdVal.toObject()));+ } else if (key2 == "/1") {+ QJsonValue pList = rdVal.toObject().value("/0");++ newResource.insert("/Bezier", QJsonObject({{"/Points", pList}}));+ } else if (key2 == "/2") {+ newResource.insert("/Data", uncompressTextFrameData(rdVal.toObject()));+ } else if (keyList.keys().contains(key2)) {+ newResource.insert(keyList.value(key2), rdVal);+ } else {+ newResource.insert(key2, rdVal);+ }+ }++ newResources.append(QJsonObject({{"/Resource", newResource}}));+ }+ newObject.insert("/Resources", newResources);+ return newObject;+}++QJsonObject uncompressKeysKinsokuSet(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ QJsonArray resources = object.value("/0").toArray();+ QJsonArray newResources;++ const QMap<QString, QString> keyList {{"/0", "/Name"}, {"/5", "/Data"}};+ const QMap<QString, QString> idKeyList {{"/0", "/NoStart"}, {"/1", "/NoEnd"}, {"/2", "/Keep"}, {"/3", "/Hanging"}, {"/4", "/PredefinedTag"}};+++ Q_FOREACH(QJsonValue val, resources) {+ QJsonObject resource = val.toObject().value("/0").toObject();+ QJsonObject newResource;+ Q_FOREACH(QString key, resource.keys()) {+ if (key == "/5") {+ QJsonObject id = resource.value(key).toObject();+ QJsonObject newId;+ Q_FOREACH(QString key2, id.keys()) {+ QJsonValue idVal = id.value(key2);+ if (idKeyList.keys().contains(key2)) {+ newId.insert(idKeyList.value(key2), idVal);+ } else {+ newId.insert(key2, idVal);+ }+ }+ newResource.insert("/Data", newId);+ } else if (keyList.keys().contains(key)) {+ newResource.insert(keyList.value(key), resource.value(key));+ } else {+ newResource.insert(key, resource.value(key));+ }+ }++ newResources.append(QJsonObject({{"/Resource", newResource}}));+ }+ newObject.insert("/Resources", newResources);+ return newObject;+}++QJsonObject uncompressKeysMojiKumiTableSet(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ newObject.insert(key, val);+ }+ return newObject;+}++QJsonObject uncompressKeysMojiKumiCodeToClassSet(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ newObject.insert(key, val);+ }+ return newObject;+}++QJsonObject uncompressKeysFontSet(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ QJsonArray resources = object.value("/0").toArray();+ QJsonArray newResources;++ const QMap<QString, QString> keyList {{"/99", "/StreamTag"}, {"/97", "/UUID"}};+ const QMap<QString, QString> idKeyList {{"/0", "/Name"}, {"/2", "/Type"}, {"/4", "/MMAxis"}, {"/5", "/VersionString"}};+++ Q_FOREACH(QJsonValue val, resources) {+ QJsonObject resource = val.toObject().value("/0").toObject();+ QJsonObject newResource;+ Q_FOREACH(QString key, resource.keys()) {+ if (key == "/0") {+ QJsonObject id = resource.value(key).toObject();+ QJsonObject newId;+ Q_FOREACH(QString key2, id.keys()) {+ QJsonValue idVal = id.value(key2);+ if (idKeyList.keys().contains(key2)) {+ newId.insert(idKeyList.value(key2), idVal);+ } else {+ newId.insert(key2, idVal);+ }+ }+ newResource.insert("/Identifier", newId);+ } else if (keyList.keys().contains(key)) {+ newResource.insert(keyList.value(key), resource.value(key));+ } else {+ newResource.insert(key, resource.value(key));+ }+ }++ newResources.append(QJsonObject({{"/Resource", newResource}}));+ }+ newObject.insert("/Resources", newResources);+ return newObject;+}++QJsonObject uncompressKeysDocumentResources(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);++ if (key == "/1") {+ newObject.insert("/FontSet", uncompressKeysFontSet(val.toObject()));+ } else if (key == "/2") {+ newObject.insert("/MojiKumiCodeToClassSet", uncompressKeysMojiKumiCodeToClassSet(val.toObject()));+ } else if (key == "/3") {+ newObject.insert("/MojiKumiTableSet", uncompressKeysMojiKumiTableSet(val.toObject()));+ } else if (key == "/4") {+ newObject.insert("/KinsokuSet", uncompressKeysKinsokuSet(val.toObject()));+ } else if (key == "/5") {+ newObject.insert("/StyleSheetSet", uncompressKeysStyleSheetSet(val.toObject()));+ } else if (key == "/6") {+ newObject.insert("/ParagraphSheetSet", uncompressKeysParagraphSheetSet(val.toObject()));+ } else if (key == "/8") {+ newObject.insert("/TextFrameSet", uncompressKeysTextFrameSet(val.toObject()));+ } else if (key == "/9") {+ newObject.insert("/ListStyleSet", val);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++/*------- Document Objects ----------*/++QJsonObject uncompressKeysTextModel(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ const QMap<QString, QString> runStyleKeyList {{"/0", "/Name"}, {"/5", "/Parent"}, {"/97", "/UUID"}};++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);++ if (key == "/0") {+ newObject.insert("/Text", val);+ } else if (key == "/5") {+ QJsonArray array = val.toObject().value("/0").toArray();+ QJsonArray newArray;++ Q_FOREACH(QJsonValue run, array) {+ QJsonObject runDataSheet = run.toObject().value("/0").toObject().value("/0").toObject();+ QJsonObject newDataSheet;++ Q_FOREACH(QString key2, runDataSheet.keys()) {+ QJsonValue rdVal = runDataSheet.value(key2);+ if (key2 == "/5") {+ newDataSheet.insert("/Features", uncompressParagraphSheetFeatures(rdVal.toObject()));+ } else if (key2 == "/6") {+ newDataSheet.insert("/Parent", rdVal);+ } else if (runStyleKeyList.keys().contains(key)) {+ newDataSheet.insert(runStyleKeyList.value(key2), rdVal);+ } else {+ newDataSheet.insert(key2, rdVal);+ }+ }++ QJsonObject newSheet = {{"/ParagraphSheet", newDataSheet}};+ QJsonObject newRunData = {{"/RunData", newSheet}};+ newRunData.insert("/Length", run.toObject().value("/1"));+ newArray.append(newRunData);+ }+ QJsonObject arrayParent = {{"/RunArray", newArray}};+ newObject.insert("/ParagraphRun", arrayParent);+ } else if (key == "/6") {+ QJsonArray array = val.toObject().value("/0").toArray();+ QJsonArray newArray;++ Q_FOREACH(QJsonValue run, array) {+ QJsonObject runDataSheet = run.toObject().value("/0").toObject().value("/0").toObject();+ QJsonObject newDataSheet;++ Q_FOREACH(QString key2, runDataSheet.keys()) {+ QJsonValue rdVal = runDataSheet.value(key2);+ if (key2 == "/6") {+ newDataSheet.insert("/Features", uncompressStyleSheetFeatures(rdVal.toObject()));+ } else if (key2 == "/5") {+ newDataSheet.insert("/Parent", rdVal);+ } else if (runStyleKeyList.keys().contains(key)) {+ newDataSheet.insert(runStyleKeyList.value(key2), rdVal);+ } else {+ newDataSheet.insert(key2, rdVal);+ }+ }++ QJsonObject newSheet = {{"/StyleSheet", newDataSheet}};+ QJsonObject newRunData = {{"/RunData", newSheet}};+ newRunData.insert("/Length", run.toObject().value("/1"));+ newArray.append(newRunData);+ }+ QJsonObject arrayParent = {{"/RunArray", newArray}};+ newObject.insert("/StyleRun", arrayParent);+ } else if (key == "/10") {+ newObject.insert("/StorySheet", val);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressStrikeDef(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;+ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);++ if (key == "/99") {+ newObject.insert("/StreamTag", val);+ } else if (key == "/0") {+ newObject.insert("/Bounds", val);+ } else if (key == "/1") {+ newObject.insert("/Transform", val);+ } else if (key == "/5") {+ newObject.insert("/ChildProcession", val);+ } else if (key == "/6") {+ QJsonArray array = val.toArray();+ QJsonArray newArray;+ Q_FOREACH(QJsonValue entry, array) {+ newArray.append(uncompressStrikeDef(entry.toObject()));+ }+ newObject.insert("/Children", newArray);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressKeysTextView(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;+ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);++ if (key == "/0") {+ QJsonArray array = val.toArray();+ QJsonArray newArray;+ Q_FOREACH(QJsonValue entry, array) {+ QJsonValue resource = entry.toObject().value("/0");++ newArray.append(QJsonObject({{"/Resource", resource}}));+ }++ newObject.insert("/Frames", newArray);+ } else if (key == "/2") {+ QJsonArray array = val.toArray();+ QJsonArray newArray;+ Q_FOREACH(QJsonValue entry, array) {+ newArray.append(uncompressStrikeDef(entry.toObject()));+ }+ newObject.insert("/Strikes", newArray);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressKeysTextObject(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);++ if (key == "/0") {+ newObject.insert("/Model", uncompressKeysTextModel(val.toObject()));+ } else if (key == "/1") {+ newObject.insert("/View", uncompressKeysTextView(val.toObject()));+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressSmartQuoteSettings(const QJsonObject object) {+ QJsonObject newObject;+ const QMap<QString, QString> keyList {+ {"/0", "/Language"},+ {"/1", "/OpenDoubleQuote"},+ {"/2", "/CloseDoubleQuote"},+ {"/3", "/OpenSingleQuote"},+ {"/4", "/CloseSingleQuote"},++ };++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ if (keyList.keys().contains(key)) {+ newObject.insert(keyList.value(key), val);+ } else {+ newObject.insert(key, val);+ }+ }+ return newObject;+}++QJsonObject uncompressHiddenGlyphSettings(const QJsonObject object) {+ QJsonObject newObject;++ if (object.keys().contains("/0")) {+ newObject.insert("/AlternateGlyphFont", object.value("/0"));+ }+ if (object.keys().contains("/1")) {+ QJsonArray array = object.value("/1").toArray();+ QJsonArray newArray;+ Q_FOREACH(QJsonValue entry, array) {+ QJsonObject newEntry;+ newObject.insert("/WhitespaceCharacter", newEntry.value("/0"));+ newObject.insert("/AlternateCharacter", newEntry.value("/1"));+ newArray.append(newObject);+ }+ newObject.insert("/WhitespaceCharacterMapping", newArray);+ }++ return newObject;+}++QJsonObject uncompressKeysDocumentSettings(const QJsonObject object) {+ QJsonObject newObject;+ const QMap<QString, QString> keyList {+ //{"/0", "/HiddenGlyphFont"},+ {"/1", "/NormalStyleSheet"},+ {"/2", "/NormalParagraphSheet"},+ {"/3", "/SuperscriptSize"},+ {"/4", "/SuperscriptPosition"},++ {"/5", "/SubscriptSize"},+ {"/6", "/SubscriptPosition"},+ {"/7", "/SmallCapSize"},+ {"/8", "/UseSmartQuotes"},+ //{"/9", "/SmartQuoteSets"},++ //{"/10", ""},+ {"/11", "/GreekingSize"},+ //{"/12", ""},+ //{"/13", ""},+ //{"/14", ""},++ {"/15", "/LinguisticSettings"},+ {"/16", "/UseSmartLists"},+ {"/17", "/DefaultStoryDir"},+ };++ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);+ if (key == "/0") {+ newObject.insert("/HiddenGlyphFont", uncompressHiddenGlyphSettings(val.toObject()));+ } else if (key == "/9") {+ QJsonArray array = val.toArray();+ QJsonArray newArray;+ Q_FOREACH(QJsonValue entry, array) {+ newArray.append(uncompressSmartQuoteSettings(entry.toObject()));+ }+ newObject.insert("/SmartQuoteSets", newArray);+ } else if (keyList.keys().contains(key)) {+ newObject.insert(keyList.value(key), val);+ } else {+ newObject.insert(key, val);+ }+ }++ return newObject;+}++QJsonObject uncompressKeysDocumentObjects(const QJsonObject object) {+ //qDebug() << Q_FUNC_INFO;+ QJsonObject newObject;+ Q_FOREACH(QString key, object.keys()) {+ QJsonValue val = object.value(key);++ if (key == "/0") {+ newObject.insert("/DocumentSettings", uncompressKeysDocumentSettings(val.toObject()));+ } else if (key == "/1") {+ QJsonArray array = val.toArray();+ QJsonArray newArray;+ Q_FOREACH(QJsonValue entry, array) {+ newArray.append(uncompressKeysTextObject(entry.toObject()));+ }+ newObject.insert("/TextObjects", newArray);+ } else if (key == "/2") {+ newObject.insert("/OriginalNormalStyleFeatures", uncompressStyleSheetFeatures(val.toObject()));+ } else if (key == "/3") {+ newObject.insert("/OriginalNormalParagraphFeatures", uncompressParagraphSheetFeatures(val.toObject()));+ } else {+ newObject.insert(key, val);+ }+ }++ return newObject;+}++QJsonDocument KisTxt2Utils::uncompressKeys(QJsonDocument doc)+{+ QJsonDocument newDoc;++ QJsonObject root = doc.object();+ QJsonObject newRoot;+ Q_FOREACH(QString key, root.keys()) {+ if (key == "/0") {+ newRoot.insert("/DocumentResources", uncompressKeysDocumentResources(root.value(key).toObject()));+ } else if (key == "/1") {+ newRoot.insert("/DocumentObjects", uncompressKeysDocumentObjects(root.value(key).toObject()));+ } else {+ newRoot.insert(key, root.value(key));+ }+ }+ newDoc.setObject(newRoot);+ return newDoc;+}diff --git a/libs/psdutils/cos/kis_txt2_utls.h b/libs/psdutils/cos/kis_txt2_utls.hnew file mode 100644index 0000000000..70dda1a93d--- /dev/null+++ b/libs/psdutils/cos/kis_txt2_utls.h@@ -0,0 +1,42 @@+/*+ * SPDX-FileCopyrightText: 2023 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#ifndef KIS_TXT2_UTLS_H+#define KIS_TXT2_UTLS_H++#include <QJsonDocument>+#include "kritapsdutils_export.h"++/**+ * @brief The KisTxt2Utils class+ *+ * Utils for handling text engine data inside the Txt2 additional info block.+ * This is a global section info block, which contains more extensive data to+ * the TySh additional info block.+ */+class KRITAPSDUTILS_EXPORT KisTxt2Utils+{+public:++ /**+ * @brief uncompressKeys+ * One of the problems with the Txt2 block is that older versions of photoshop (cs2-cs3 era)+ * stored the dictionary keys as names, while new versions stores it as numbers. This function+ * translates the numbers to the names.+ *+ * Thankfully the inkscape devs had already figured out the numbers and their keys, so+ * special thanks to them for documenting that:+ *+ * https://gitlab.com/inkscape/extras/extension-ai/-/blob/main/+ * docs/specification_amendments/text_documents.md?ref_type=heads+ *+ * @param doc input txt2 doc.+ * @return documented with keys translated to names.+ */+ static QJsonDocument uncompressKeys(QJsonDocument doc);+};++#endif // KIS_TXT2_UTLS_Hdiff --git a/plugins/impex/psd/psd_loader.cpp b/plugins/impex/psd/psd_loader.cppindex d3d3173f53..9b82175e21 100644--- a/plugins/impex/psd/psd_loader.cpp+++ b/plugins/impex/psd/psd_loader.cpp@@ -430,6 +430,8 @@ KisImportExportErrorCode PSDLoader::decode(QIODevice &io)QTransform scaleToPt = QTransform::fromScale(m_image->xRes(), m_image->yRes()).inverted();bool res = converter.convertPSDTextEngineDataToSVG(text.engineData,+ layerSection.globalInfoSection.txt2Data,+ text.textIndex,&svg, &styles,offset1, offsetByAscent,text.isHorizontal, scaleToPt);