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

Move caret slant info into metrics, fix selecting italic font faces.

Wolthera van Hövell tot Westerflierac8d9221f3b9
diff --git a/libs/flake/text/KoCssTextUtils.cpp b/libs/flake/text/KoCssTextUtils.cpp
index 054983ba41..1f86f210e4 100644
--- a/libs/flake/text/KoCssTextUtils.cpp
+++ b/libs/flake/text/KoCssTextUtils.cpp
@@ -578,7 +578,7 @@ void KoCssTextUtils::removeText(QString &text, int &start, int length)
qreal KoCssTextUtils::cssSelectFontStyleValue(const QVector<qreal> &values, const qreal targetValue, const qreal defaultValue, const qreal defaultValueUpper, const bool shouldNotReturnDefault)
{
if(values.isEmpty()) {
- return defaultValue;
+ return targetValue;
}
// follow the CSS Fonts selection mechanism.
// See https://drafts.csswg.org/css-fonts-4/#font-style-matching
diff --git a/libs/flake/text/KoFFWWSConverter.cpp b/libs/flake/text/KoFFWWSConverter.cpp
index 11847f1fc6..e2568344c0 100644
--- a/libs/flake/text/KoFFWWSConverter.cpp
+++ b/libs/flake/text/KoFFWWSConverter.cpp
@@ -1106,8 +1106,9 @@ QVector<KoFFWWSConverter::FontFileEntry> KoFFWWSConverter::candidatesForCssValue
QVector<FontFamilyNode> obliques;
if (wws->isVariable) {
+ qreal slantValue = info.slantMode == QFont::StyleItalic? 11: info.autoSlant? 14: info.slantValue;
italics = findNodesByAxis(candidates, ITALIC_TAG, 1.0, 0.0, 0.0);
- obliques = findNodesByAxis(candidates, SLANT_TAG, -info.slantValue, 0.0, 0.0);
+ obliques = findNodesByAxis(candidates, SLANT_TAG, -slantValue, 0.0, 0.0);
}
if (italics.isEmpty() && obliques.isEmpty()) {
Q_FOREACH(const FontFamilyNode &node, candidates) {
diff --git a/libs/flake/text/KoFontRegistry.cpp b/libs/flake/text/KoFontRegistry.cpp
index b8de026e98..dbe618009d 100644
--- a/libs/flake/text/KoFontRegistry.cpp
+++ b/libs/flake/text/KoFontRegistry.cpp
@@ -812,7 +812,7 @@ KoSvgText::FontMetrics KoFontRegistry::generateFontMetrics(FT_FaceSP face, bool
// metrics
- const QVector<hb_ot_metrics_tag_t> metricTags ({
+ QVector<hb_ot_metrics_tag_t> metricTags ({
HB_OT_METRICS_TAG_X_HEIGHT,
HB_OT_METRICS_TAG_CAP_HEIGHT,
HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_OFFSET,
@@ -825,6 +825,18 @@ KoSvgText::FontMetrics KoFontRegistry::generateFontMetrics(FT_FaceSP face, bool
HB_OT_METRICS_TAG_STRIKEOUT_SIZE,
});
+ if (isHorizontal) {
+ metricTags.append(HB_OT_METRICS_TAG_HORIZONTAL_CARET_RISE);
+ metricTags.append(HB_OT_METRICS_TAG_HORIZONTAL_CARET_RUN);
+ metricTags.append(HB_OT_METRICS_TAG_HORIZONTAL_CARET_OFFSET);
+ metrics.caretRise = 1;
+ } else {
+ metricTags.append(HB_OT_METRICS_TAG_VERTICAL_CARET_RISE);
+ metricTags.append(HB_OT_METRICS_TAG_VERTICAL_CARET_RUN);
+ metricTags.append(HB_OT_METRICS_TAG_VERTICAL_CARET_OFFSET);
+ metrics.caretRun = 1;
+ }
+
for (auto it = metricTags.begin(); it!= metricTags.end(); it++) {
char c[4];
hb_tag_to_string(*it, c);
@@ -832,10 +844,10 @@ KoSvgText::FontMetrics KoFontRegistry::generateFontMetrics(FT_FaceSP face, bool
hb_position_t origin = 0;
if (useFallback) {
hb_ot_metrics_get_position_with_fallback(font.data(), *it, &origin);
- } else {
- hb_ot_metrics_get_position(font.data(), *it, &origin);
+ metrics.setMetricsValueByTag(tagName, origin);
+ } else if (hb_ot_metrics_get_position(font.data(), *it, &origin)) {
+ metrics.setMetricsValueByTag(tagName, origin);
}
- metrics.setMetricsValueByTag(tagName, origin);
}
// Baselines.
diff --git a/libs/flake/text/KoSvgText.cpp b/libs/flake/text/KoSvgText.cpp
index 79f72de98f..0403e5d249 100644
--- a/libs/flake/text/KoSvgText.cpp
+++ b/libs/flake/text/KoSvgText.cpp
@@ -1407,6 +1407,10 @@ FontMetrics::FontMetrics(qreal fontSizeInPt, bool isHorizontal)
hangingBaseline = (fontSize / 5) * 3;
+ caretRun = 0;
+ caretRise = 1;
+ caretOffset = 0;
+
} else {
zeroAdvance = fontSize;
spaceAdvance = fontSize;
@@ -1423,6 +1427,10 @@ FontMetrics::FontMetrics(qreal fontSizeInPt, bool isHorizontal)
alphabeticBaseline = ascender - (fontSize / 5) * 4;
hangingBaseline = alphabeticBaseline + ((fontSize / 5) * 3);
+
+ caretRun = 1;
+ caretRise = 0;
+ caretOffset = 0;
}
ideographicFaceUnderBaseline = descender;
@@ -1531,6 +1539,18 @@ void FontMetrics::setMetricsValueByTag(const QLatin1String &tag, int32_t value)
underlineThickness = value;
} else if (tag == "undo") {
underlineOffset = value;
+ } else if (tag == "hcrs") {
+ caretRise = value;
+ } else if (tag == "hcrn") {
+ caretRun = value;
+ } else if (tag == "hcof") {
+ caretOffset = value;
+ } else if (tag == "vcrs") {
+ caretRise = value;
+ } else if (tag == "vcrs") {
+ caretRise = value;
+ } else if (tag == "vcrs") {
+ caretRise = value;
}
}
diff --git a/libs/flake/text/KoSvgText.h b/libs/flake/text/KoSvgText.h
index 60d8320d2a..647026175b 100644
--- a/libs/flake/text/KoSvgText.h
+++ b/libs/flake/text/KoSvgText.h
@@ -348,6 +348,11 @@ struct FontMetrics : public boost::equality_comparable<FontMetrics> {
qint32 lineThroughOffset; ///< offset of strike-through from alphabetic baseline.
qint32 lineThroughThickness; ///< strikethrough thickness, from font.
+ /// These are only used to determine the caret slant proportion.
+ qint32 caretRun;
+ qint32 caretRise;
+ qint32 caretOffset;
+
FontMetrics () {
}
diff --git a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp b/libs/flake/text/KoSvgTextShape_p_glyphs.cpp
index de484ed7f1..828b04df29 100644
--- a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp
+++ b/libs/flake/text/KoSvgTextShape_p_glyphs.cpp
@@ -509,16 +509,11 @@ bool KoSvgTextShape::Private::loadGlyph(const QTransform &ftTF,
CursorInfo cursorInfo = charResult.cursorInfo;
qreal lineHeight = (charResult.metrics.ascender-charResult.metrics.descender) * bitmapScale;
qreal descender = charResult.metrics.descender * bitmapScale;
+ qint32 offset = charResult.metrics.caretOffset;
if (isHorizontal) {
- hb_position_t run = 0;
- hb_position_t rise = 1;
- hb_position_t offset = 0;
- hb_ot_metrics_get_position_with_fallback(font.data(), HB_OT_METRICS_TAG_HORIZONTAL_CARET_RUN, &run);
- hb_ot_metrics_get_position_with_fallback(font.data(), HB_OT_METRICS_TAG_HORIZONTAL_CARET_RISE, &rise);
- hb_ot_metrics_get_position_with_fallback(font.data(), HB_OT_METRICS_TAG_HORIZONTAL_CARET_OFFSET, &offset);
qreal slope = 0;
- if (run != 0 && rise !=0) {
- slope = double(run)/double(rise);
+ if (charResult.metrics.caretRun != 0 && charResult.metrics.caretRise !=0) {
+ slope = double(charResult.metrics.caretRun)/double(charResult.metrics.caretRise);
if (offset == 0) {
offset = descender * slope;
}
@@ -542,15 +537,9 @@ bool KoSvgTextShape::Private::loadGlyph(const QTransform &ftTF,
cursorInfo.offsets = positions;
} else {
- hb_position_t run = 1;
- hb_position_t rise = 0;
- hb_position_t offset = 0;
- hb_ot_metrics_get_position_with_fallback(font.data(), HB_OT_METRICS_TAG_VERTICAL_CARET_RUN, &run);
- hb_ot_metrics_get_position_with_fallback(font.data(), HB_OT_METRICS_TAG_VERTICAL_CARET_RISE, &rise);
- hb_ot_metrics_get_position_with_fallback(font.data(), HB_OT_METRICS_TAG_VERTICAL_CARET_OFFSET, &offset);
qreal slope = 0;
- if (run != 0 && rise !=0) {
- slope = double(rise)/double(run);
+ if (charResult.metrics.caretRun != 0 && charResult.metrics.caretRise !=0) {
+ slope = double(charResult.metrics.caretRun)/double(charResult.metrics.caretRise);
if (offset == 0) {
offset = descender * slope;
}