From 0e371a39ea19a6521e257187011b7864700cb9f6 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 5 Jun 2025 08:34:55 +0200 Subject: [PATCH] Add an envvar restoring Qt 5 behavior for vertical font metrics As a last resort for users who have existing Qt 5 applications and see differences in line metrics when porting to Qt 6, we introduce an environment variable which lets them restore the old behavior as a last resort. This is primarily meant as a porting tool, since we do have other tools, such as QFont::PreferTypoLineMetrics to work around issues with fonts that by mistake do not explicitly set the use-typo-metrics flag even if these are valid. Pick-to: 6.8 Fixes: QTBUG-134602 Change-Id: Id1d7829888d55247d2f07ee0a49b91ff34f26889 Reviewed-by: Eirik Aavitsland (cherry picked from commit 9a950b1ecb901cc885995d128768cc04cb55cfb1) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 488e21860409b1f09b187c94e6e318f4ff8ff0a7) --- src/gui/text/qfontengine.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 68b31a7841a..dd58975bc93 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -421,7 +421,14 @@ void QFontEngine::initializeHeightMetrics() const !getSfntTable(QFont::Tag("EBLC").value()).isEmpty() || !getSfntTable(QFont::Tag("CBLC").value()).isEmpty() || !getSfntTable(QFont::Tag("bdat").value()).isEmpty(); - if (!hasEmbeddedBitmaps) { + + // When porting applications from Qt 5 to Qt 6, users have noticed differences in line + // metrics due to the effort to consolidate these across platforms instead of using the + // system values directly. This environment variable gives a "last resort" for those users + // to tell Qt to prefer the metrics we get from the system, despite the fact these being + // inconsistent across platforms. + static bool useSystemLineMetrics = qEnvironmentVariableIntValue("QT_USE_SYSTEM_LINE_METRICS") > 0; + if (!hasEmbeddedBitmaps && !useSystemLineMetrics) { // Get HHEA table values if available processHheaTable();