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: load and save more properties.

Wolthera van Hövell tot Westerflier134adf9b8f42
diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
index d5bb697fa8..656143dcd8 100644
--- a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
+++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp
@@ -1325,6 +1325,7 @@ QString stylesForPSDStyleSheet(QVariantHash PSDStyleSheet, QMap<int, font_info_p
QStringList baselineShift;
QStringList fontVariantLigatures;
QStringList fontVariantNumeric;
+ QStringList fontVariantCaps;
QStringList fontFeatureSettings;
for (int i=0; i < PSDStyleSheet.keys().size(); i++) {
const QString key = PSDStyleSheet.keys().at(i);
@@ -1399,7 +1400,7 @@ QString stylesForPSDStyleSheet(QVariantHash PSDStyleSheet, QMap<int, font_info_p
case 0:
break;
case 1:
- styles.append("font-variant-caps:all-small-caps");
+ fontVariantCaps.append("all-small-caps");
break;
case 2:
styles.append("text-transform:uppercase");
@@ -1489,7 +1490,7 @@ QString stylesForPSDStyleSheet(QVariantHash PSDStyleSheet, QMap<int, font_info_p
continue;
} else if (key == "/Titling") {
if (PSDStyleSheet.value(key).toBool()) {
- fontFeatureSettings.append("'titl' 1");
+ fontVariantCaps.append("titling-caps");
}
continue;
} else if (key == "/StylisticAlternates") {
@@ -1502,7 +1503,7 @@ QString stylesForPSDStyleSheet(QVariantHash PSDStyleSheet, QMap<int, font_info_p
fontFeatureSettings.append("'ornm' 1");
}
continue;
- } else if (key == "/FigureStyle") {
+ } else if (key == "/FigureStyle") {
switch (PSDStyleSheet.value(key).toInt()) {
case 0:
break;
@@ -1584,6 +1585,14 @@ QString stylesForPSDStyleSheet(QVariantHash PSDStyleSheet, QMap<int, font_info_p
styles.append("word-break: keep-all");
}
continue;
+ }else if (key == "/DirOverride") {
+ QString dir = PSDStyleSheet.value(key).toBool()? "rtl": "ltr";
+ // Prevents word from breaking... I guess word-break???
+ if (PSDStyleSheet.value(key).toBool()) {
+ styles.append("direction: "+dir);
+ styles.append("unicode-bidi: isolate");
+ }
+ continue;
} else if (key == "/FillColor") {
bool fill = true;
if (PSDStyleSheet.keys().contains("/FillFlag")) {
@@ -1662,6 +1671,34 @@ QString stylesForPSDStyleSheet(QVariantHash PSDStyleSheet, QMap<int, font_info_p
// TODO: extend till ss20.
continue;
+ } else if (key == "/LineCap") {
+ switch (PSDStyleSheet.value(key).toInt()) {
+ case 0:
+ styles.append("stroke-linecap: butt");
+ break;
+ case 1:
+ styles.append("stroke-linecap: round");
+ break;
+ case 2:
+ styles.append("stroke-linecap: square");
+ break;
+ default:
+ styles.append("stroke-linecap: butt");
+ }
+ } else if (key == "/LineJoin") {
+ switch (PSDStyleSheet.value(key).toInt()) {
+ case 0:
+ styles.append("stroke-linejoin: miter");
+ break;
+ case 1:
+ styles.append("stroke-linejoin: round");
+ break;
+ case 2:
+ styles.append("stroke-linejoin: bevel");
+ break;
+ default:
+ styles.append("stroke-linejoin: miter");
+ }
} else {
if (key != "/FillFlag" && key != "/StrokeFlag" && key != "/AutoLeading") {
qWarning() << "Unknown PSD character stylesheet style key" << key << PSDStyleSheet.value(key);
@@ -1686,6 +1723,9 @@ QString stylesForPSDStyleSheet(QVariantHash PSDStyleSheet, QMap<int, font_info_p
if (!fontVariantNumeric.isEmpty()) {
styles.append("font-variant-numeric:"+fontVariantNumeric.join(" "));
}
+ if (!fontVariantCaps.isEmpty()) {
+ styles.append("font-variant-caps:"+fontVariantCaps.join(" "));
+ }
if (!fontFeatureSettings.isEmpty()) {
styles.append("font-feature-settings:"+fontFeatureSettings.join(", "));
}
@@ -2079,8 +2119,6 @@ QVariantHash styleToPSDStylesheet(const QMap<QString, QString> cssStyles,
QVariantHash parentStyle, QTransform scaleToPx) {
QVariantHash styleSheet = parentStyle;
-
-
Q_FOREACH(QString key, cssStyles.keys()) {
QString val = cssStyles.value(key);
@@ -2097,9 +2135,20 @@ QVariantHash styleToPSDStylesheet(const QMap<QString, QString> cssStyles,
double space = val.toDouble();
double size = styleSheet["/FontSize"].toDouble();
styleSheet["/Leading"] = (space*size);
+ styleSheet["/AutoLeading"] = false;
} else if (key == "font-kerning") {
if (val == "none") {
- styleSheet["AutoKern"] = 0;
+ styleSheet["/AutoKern"] = 0;
+ }
+ } else if (key == "baseline-shift") {
+ if (val == "super") {
+ styleSheet["/FontBaseline"] = 1;
+ } else if (val == "super") {
+ styleSheet["/FontBaseline"] = 2;
+ } else {
+ double offset = val.toDouble();
+ offset = scaleToPx.map(QPointF(offset, offset)).y();
+ styleSheet["/BaselineShift"] = offset;
}
} else if (key == "text-decoration") {
QStringList decor = val.split(" ");
@@ -2117,6 +2166,8 @@ QVariantHash styleToPSDStylesheet(const QMap<QString, QString> cssStyles,
Q_FOREACH(QString param, params) {
if (param == "small-caps" || param == "all-small-caps") {
styleSheet["/FontCaps"] = 1;
+ } else if (param == "titling-caps") {
+ styleSheet["/Titling"] = true;
} else if (param == "no-common-ligatures"){
styleSheet["/Ligatures"] = false;
} else if (param == "discretionary-ligatures"){
@@ -2129,6 +2180,10 @@ QVariantHash styleToPSDStylesheet(const QMap<QString, QString> cssStyles,
styleSheet["/Ordinals"] = true;
} else if (param == "slashed-zero"){
styleSheet["/SlashedZero"] = true;
+ } else if (param == "super") {
+ styleSheet["/FontOTPosition"] = 1;
+ } else if (param == "sub") {
+ styleSheet["/FontOTPosition"] = 2;
}
}
if (tab && old) {
@@ -2151,6 +2206,10 @@ QVariantHash styleToPSDStylesheet(const QMap<QString, QString> cssStyles,
styleSheet["/Ornaments"] = true;
} else if (param.trimmed() == "'ital' 1") {
styleSheet["/Italics"] = true;
+ } else if (param.trimmed() == "'numr' 1") {
+ styleSheet["/FontOTPosition"] = 3;
+ } else if (param.trimmed() == "'dnum' 1") {
+ styleSheet["/FontOTPosition"] = 4;
}
}
} else if (key == "text-orientation") {
@@ -2160,6 +2219,9 @@ QVariantHash styleToPSDStylesheet(const QMap<QString, QString> cssStyles,
styleSheet["/BaselineDirection"] = 2;
}
} else if (key == "word-break") {
+ styleSheet["/NoBreak"] = val == "keep-all";
+ } else if (key == "direction") {
+ styleSheet["/DirOverride"] = val == "ltr"? 0 :1;
} else {
qDebug() << "Unsupported css-style:" << key << val;
}
@@ -2312,20 +2374,21 @@ QVariantHash gatherParagraphStyle(QDomElement el,
if (val == "justify center") {alignVal = 4;}
if (val == "justify end") {alignVal = 5;}
if (val == "justify") {alignVal = 6;}
- }
- if (key == "text-anchor") {
+ } else if (key == "text-anchor") {
if (val == "start") {anchorVal = 0;}
if (val == "middle") {anchorVal = 2;}
if (val == "end") {anchorVal = 1;}
- }
- if (key == "writing-mode") {
+ } else if (key == "writing-mode") {
if (val == "horizontal-tb") {
isHorizontal = true;
} else {
isHorizontal = false;
}
- }
- if (key == "inline-size") {
+ } else if (key == "direction") {
+ paragraphStyleSheet["/ParagraphDirection"] = val == "ltr"? 0 :1;
+ } else if (key == "line-height") {
+ paragraphStyleSheet["/AutoLeading"] = val.toDouble();
+ } else if (key == "inline-size") {
*inlineSize = val;
}
}