[LyX/2.4.x] QFontMetrics::xHeight() is not always the ascent of 'x'

Jean-Marc Lasgouttes lasgouttes at lyx.org
Wed Oct 16 11:13:48 UTC 2024


commit 3cab29486d9dc0a43448af8865fc3dc0ae2df9ed
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Mon Sep 23 19:15:20 2024 +0200

    QFontMetrics::xHeight() is not always the ascent of 'x'
    
    Use the real ascent of glyph 'x' as LyX 2.3.x did.
    It can make a difference at least on Windows with many fonts.
    
    Fixes bug #13100.
    
    (cherry picked from commit 194b53ef9d2896664772a12c0038eedd717daec3)
---
 src/frontends/qt/GuiFontMetrics.cpp | 5 +++--
 status.24x                          | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/frontends/qt/GuiFontMetrics.cpp b/src/frontends/qt/GuiFontMetrics.cpp
index f0300f16ea..5b9805a079 100644
--- a/src/frontends/qt/GuiFontMetrics.cpp
+++ b/src/frontends/qt/GuiFontMetrics.cpp
@@ -114,7 +114,7 @@ inline QChar const ucs4_to_qchar(char_type const ucs4)
 
 
 GuiFontMetrics::GuiFontMetrics(QFont const & font)
-	: font_(font), metrics_(font, 0), xheight_(metrics_.xHeight()),
+	: font_(font), metrics_(font, 0), xheight_(-metrics_.boundingRect('x').top()),
 	  strwidth_cache_(strwidth_cache_max_cost),
 	  breakstr_cache_(breakstr_cache_max_cost),
 	  qtextlayout_cache_(qtextlayout_cache_max_size)
@@ -163,7 +163,8 @@ int GuiFontMetrics::em() const
 
 int GuiFontMetrics::xHeight() const
 {
-//	LATTEST(metrics_.xHeight() == ascent('x'));
+	// This is not alays true on Windows (see #13100).
+	// LATTEST(metrics_.xHeight() == ascent('x'));
 	return xheight_;
 }
 
diff --git a/status.24x b/status.24x
index 12d7102455..9967ed9556 100644
--- a/status.24x
+++ b/status.24x
@@ -35,6 +35,8 @@ What's new
   These two settings are mutually exclusive by default and we signal
   that within UI now. Workarounds can be found our and hyperref manual.
 
+- Fix display of superscripts on Windows (bug 13100).
+
 
 * DOCUMENTATION AND LOCALIZATION
 


More information about the lyx-cvs mailing list