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 text: allow saving the first shape-inside.

Wolthera van Hövell tot Westerflier96ac4b50e939
diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
index af2cee78fe..b4d4489979 100644
--- a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
+++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
@@ -2234,8 +2234,9 @@ QVariantHash gatherParagraphStyle(QDomElement el,
QString val = style.split(":").last().trimmed();
cssStyles.insert(key, val);
}
- if (el.hasAttribute("text-anchor")) {
- cssStyles.insert("text-anchor", el.attribute("text-anchor", "start"));
+ for (int i = 0; i < el.attributes().length(); i++) {
+ const QDomAttr attr = el.attributes().item(i).toAttr();
+ cssStyles.insert(attr.name(), attr.value());
}
int alignVal = 0;
int anchorVal = 0;
@@ -2277,8 +2278,8 @@ QVariantHash gatherParagraphStyle(QDomElement el,
return QVariantHash{{"/Name", ""}, {"/Parent", 0}, {"/Features", paragraphStyleSheet}};
}
-bool KoSvgTextShapeMarkupConverter::convertToPSDTextEngineData(const QString &svgText,
- QRectF &boundingBox,
+bool KoSvgTextShapeMarkupConverter::convertToPSDTextEngineData(const QString &svgText, QRectF &boundingBox,
+ const QList<KoShape *> &shapesInside,
QVariantHash &txt2,
int &textIndex,
QString &textTotal,
@@ -2361,29 +2362,65 @@ bool KoSvgTextShapeMarkupConverter::convertToPSDTextEngineData(const QString &sv
bounds = QRectF();
}
- QVariantHash Strike;
- int shapeType = bounds.isEmpty()? 0: 1; // 0 point, 1 paragraph, but what does that make text-on-path?
+ int shapeType = bounds.isEmpty()? 0: 1; ///< 0 point, 1 paragraph, 2 text-on-path.
int writingDirection = isHorizontal? 0: 2;
- Strike["/Transform"] = QVariantHash {{"/Origin", QVariantList({0.0, 0.0})}};
- QRectF boundsPix = scaleToPx.mapRect(bounds);
- Strike.insert("/Bounds", QVariantList({0, 0, boundsPix.width(), boundsPix.height()}));
- Strike.insert("/StreamTag", "/PathSelectGroupCharacter");
- Strike.insert("/ChildProcession", 0);
- view.insert("/Strikes", QVariantList({Strike}));
view.insert("/RenderedData", QVariantList());
const int textFrameIndex = textFrames.size();
QVariantHash newTextFrame;
QVariantHash newTextFrameData;
newTextFrameData.insert("/LineOrientation", writingDirection);
- newTextFrameData.insert("/Type", shapeType);
- QVariantList points;
- //TODO: write points
+
+ QList<QPointF> points;
+
+ KoPathShape *textShape = nullptr;
+ Q_FOREACH(KoShape *shape, shapesInside) {
+ KoPathShape *p = dynamic_cast<KoPathShape*>(shape);
+ if (p) {
+ textShape = p;
+ break;
+ }
+ }
+ if (textShape) {
+ for (int i = 0; i<textShape->subpathPointCount(0); i++) {
+ KoPathSegment s = textShape->segmentByIndex(KoPathPointIndex(0, i));
+ points.append(s.first()->point());
+ points.append(s.first()->controlPoint2());
+ points.append(s.second()->controlPoint1());
+ points.append(s.second()->point());
+ }
+ } else if (!bounds.isEmpty()) {
+ points.append(bounds.topLeft());
+ points.append(bounds.topLeft());
+ points.append(bounds.topRight());
+ points.append(bounds.topRight());
+ points.append(bounds.topRight());
+ points.append(bounds.topRight());
+ points.append(bounds.bottomRight());
+ points.append(bounds.bottomRight());
+ points.append(bounds.bottomRight());
+ points.append(bounds.bottomRight());
+ points.append(bounds.bottomLeft());
+ points.append(bounds.bottomLeft());
+ points.append(bounds.bottomLeft());
+ points.append(bounds.bottomLeft());
+ points.append(bounds.topLeft());
+ points.append(bounds.topLeft());
+ }
if (!points.isEmpty()) {
- newTextFrame.insert("/Bezier", QVariantHash({{"/Points", points}}));
+ QVariantList p;
+ for(int i = 0; i < points.size(); i++) {
+ QPointF p2 = scaleToPx.map(points.at(i));
+ p.append(p2.x());
+ p.append(p2.y());
+ }
+ qDebug() << p;
+ newTextFrame.insert("/Bezier", QVariantHash({{"/Points", p}}));
+ shapeType = 1;
}
+ newTextFrameData.insert("/Type", shapeType);
newTextFrame.insert("/Data", newTextFrameData);
view.insert("/Frames", QVariantList({QVariantHash({{"/Resource", textFrameIndex}})}));
diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.h b/libs/flake/text/KoSvgTextShapeMarkupConverter.h
index 531444cb26..cd6b7831c3 100644
--- a/libs/flake/text/KoSvgTextShapeMarkupConverter.h
+++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.h
@@ -17,6 +17,7 @@
class QRectF;
class KoSvgTextShape;
+class KoShape;
/**
* KoSvgTextShapeMarkupConverter is a utility class for converting a
@@ -95,6 +96,7 @@ public:
QTransform scaleToPt = QTransform());
bool convertToPSDTextEngineData(const QString &svgText,
QRectF &boundingBox,
+ const QList<KoShape *> &shapesInside,
QVariantHash &txt2,
int &textIndex,
QString &textTotal,
diff --git a/libs/psd/psd_layer_section.cpp b/libs/psd/psd_layer_section.cpp
index 94fe3516f4..2d95cc2c27 100644
--- a/libs/psd/psd_layer_section.cpp
+++ b/libs/psd/psd_layer_section.cpp
@@ -673,28 +673,19 @@ void PSDLayerMaskSection::writePsdImpl(QIODevice &io, KisNodeSP rootLayer, psd_c
textData.boundingBox = text->boundingRect().normalized();
textData.bounds = text->outlineRect().normalized();
- convert.convertToPSDTextEngineData(svgtext, textData.bounds, globalInfoSection.txt2Data, textData.textIndex, textData.text, textData.isHorizontal, FlaketoPixels);
- textData.engineData = KisTxt2Utils::tyShFromTxt2(globalInfoSection.txt2Data, textData.textIndex);
+ convert.convertToPSDTextEngineData(svgtext, textData.bounds, text->shapesInside(), globalInfoSection.txt2Data, textData.textIndex, textData.text, textData.isHorizontal, FlaketoPixels);
+ textData.engineData = KisTxt2Utils::tyShFromTxt2(globalInfoSection.txt2Data, FlaketoPixels.mapRect(textData.boundingBox), textData.textIndex);
textCount += 1;
- QTransform offset;
if (!text->shapesInside().isEmpty()) {
textData.bounds = text->outlineRect().normalized();
}
if (!textData.bounds.isEmpty()) {
- if (text->shapesInside().isEmpty()) {
- offset = QTransform::fromTranslate(textData.bounds.left(), textData.bounds.top());
- }
- if (textData.isHorizontal) {
- textData.bounds.translate(QPointF(-textData.bounds.left(), 0));
- } else {
- textData.bounds.translate(QPointF(0, -textData.bounds.top()));
- }
textData.boundingBox = FlaketoPixels.mapRect(textData.boundingBox);
textData.bounds = FlaketoPixels.mapRect(textData.bounds);
} else {
textData.boundingBox = QRectF();
}
- textData.transform = FlaketoPixels.inverted() * offset * text->absoluteTransformation() * FlaketoPixels;
+ textData.transform = FlaketoPixels.inverted() * text->absoluteTransformation() * FlaketoPixels;
} else {
KoPathShape *pathShape = dynamic_cast<KoPathShape*>(shapeLayer->shapes().first());
if (pathShape){
diff --git a/libs/psdutils/cos/kis_txt2_utls.cpp b/libs/psdutils/cos/kis_txt2_utls.cpp
index 8efd91b3ed..1f4a9a0758 100644
--- a/libs/psdutils/cos/kis_txt2_utls.cpp
+++ b/libs/psdutils/cos/kis_txt2_utls.cpp
@@ -9,6 +9,7 @@
#include <QVariant>
#include <QVariantList>
#include <QDebug>
+#include <QRectF>
QVariantHash uncompressColor(const QVariantHash object) {
//qDebug() << Q_FUNC_INFO;
@@ -1266,7 +1267,7 @@ static QVariantHash simplifyParagraphSheet(const QVariantHash complex) {
return simple;
}
-QVariantHash KisTxt2Utils::tyShFromTxt2(const QVariantHash Txt2, int textIndex)
+QVariantHash KisTxt2Utils::tyShFromTxt2(const QVariantHash Txt2, const QRectF boundsInPx, int textIndex)
{
QVariantHash tySh;
@@ -1343,7 +1344,6 @@ QVariantHash KisTxt2Utils::tyShFromTxt2(const QVariantHash Txt2, int textIndex)
engineDict.insert("/StyleRun", styleRun);
// rendered data...
- const QVariantHash strikes = view.value("/Strikes").toList().value(0).toHash();
const int frameIndex = view.value("/Frames").toList().value(0).toHash().value("/Resource").toInt();
const QVariantHash textFrame = textFrames.value(frameIndex).toHash().value("/Resource").toHash();
const QVariantHash textFrameData = textFrame.value("/Data").toHash();
@@ -1358,7 +1358,7 @@ QVariantHash KisTxt2Utils::tyShFromTxt2(const QVariantHash Txt2, int textIndex)
photoshop["/PointBase"] = QVariantList({0.0, 0.0});
} else if (shapeType == 1) {
// this is the bounding box of the paragraph shape.
- photoshop["/BoxBounds"] = strikes.value("/Bounds");
+ photoshop["/BoxBounds"] = QVariantList({0.0, 0.0, boundsInPx.width(), boundsInPx.height()});
}
QVariantHash renderChild = QVariantHash{
{"/ShapeType", shapeType},
diff --git a/libs/psdutils/cos/kis_txt2_utls.h b/libs/psdutils/cos/kis_txt2_utls.h
index 8ee7ed51b5..ccb650ca5c 100644
--- a/libs/psdutils/cos/kis_txt2_utls.h
+++ b/libs/psdutils/cos/kis_txt2_utls.h
@@ -54,7 +54,7 @@ public:
* @param textIndex the text object index for which to generate the tySh data.
* @return the tySh variantHash
*/
- static QVariantHash tyShFromTxt2(const QVariantHash Txt2, int textIndex);
+ static QVariantHash tyShFromTxt2(const QVariantHash Txt2, const QRectF boundsInPx, int textIndex);
};
#endif // KIS_TXT2_UTLS_H