diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2019-12-06 07:13:28 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-04-22 16:18:57 +0200 |
commit | f761ad3cd9ad1252f24b76ae413298dc7bed8af3 (patch) | |
tree | 0cdce90553fc85a773f3255c27024c41d1236f24 /src/gui/text/qfontengine_p.h | |
parent | 7d8093df55f0bf76465add4ceb3732286971d849 (diff) |
Use consistent vertical metrics on all platforms
Qt assumes that ascent+descent is the bounding height of the
text, but for historical reasons, the ascent for some fonts
will not contain the diacritics. On Windows, the preference
is to use data from the OS/2 table which were explicitly
invented to work around this, but on other platforms we
are not respecting this table. This causes a text layout
that looks fine on Windows to have overlapping characters
on e.g. macOS.
To make vertical metrics (ascent, descent, leading) consistent
across all platforms, we don't blindly trust the values we get
from the underlying font system, but apply in the following order:
1. If OS/2 table exists and USE_TYPO_METRICS flag is set, we
use the typo metrics from OS/2 table
2. If OS/2 table exists and USE_TYPO_METRICS flag is not set,
we use winAscent/winDescent from OS/2 and the line gap from
HHEA table.
3. If no OS/2 table exists, we try to get ascent, descent and
line gap from the HHEA table.
4. If the HHEA table does not exist (not an SFNT), we fall back
to the system-provided metrics. (on macOS, we know the
system-provided metrics will match the data in HHEA, so we
skip parsing that table and use the data from CoreText if
there is no OS/2 table).
Task-number: QTBUG-80554
Change-Id: I41e6561a99513698c8e42451b4ec98bd5eb6892f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/gui/text/qfontengine_p.h')
-rw-r--r-- | src/gui/text/qfontengine_p.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index 0fa8f8e826..50f3948311 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -221,10 +221,10 @@ public: virtual glyph_metrics_t boundingBox(glyph_t glyph, const QTransform &matrix); glyph_metrics_t tightBoundingBox(const QGlyphLayout &glyphs); - virtual QFixed ascent() const = 0; + virtual QFixed ascent() const; virtual QFixed capHeight() const = 0; - virtual QFixed descent() const = 0; - virtual QFixed leading() const = 0; + virtual QFixed descent() const; + virtual QFixed leading() const; virtual QFixed xHeight() const; virtual QFixed averageCharWidth() const; @@ -369,6 +369,15 @@ protected: inline void setUserData(const QVariant &userData) { m_userData = userData; } QFixed calculatedCapHeight() const; + mutable QFixed m_ascent; + mutable QFixed m_descent; + mutable QFixed m_leading; + mutable bool m_heightMetricsQueried; + + virtual void initializeHeightMetrics() const; + virtual bool processHheaTable() const; + virtual bool processOS2Table() const; + private: struct GlyphCacheEntry { GlyphCacheEntry(); @@ -388,7 +397,6 @@ private: mutable qreal m_minLeftBearing; mutable qreal m_minRightBearing; - }; Q_DECLARE_TYPEINFO(QFontEngine::KernPair, Q_PRIMITIVE_TYPE); |