commit b079bfe4c80ff1706f5d2c15b6e717149231d9df
Author: Enrico Forestieri <for...@lyx.org>
Date:   Tue Aug 13 22:51:40 2024 +0200
    Improve detection of our math fonts
    
    It turns out that Qt font selection via style name is broken on
    Windows (QTBUG-101436). As we use our own style name for discriminating
    our math fonts and applying proper kerning, we need a fallback method.
    With this commit we check for the family name when the style name does
    not match. In computing the kerning we also consider the right bearing
    reported by the font instead of the width of the enclosing bounding box,
    as this produces better results (see bug 13087).
    
    Fixes #13087.
    
    (cherry picked from commit d632753dea7cd3985f64b0c7e9db055c5a6c48f4)
---
 src/frontends/qt/GuiFontLoader.cpp  | 9 +++++++++
 src/frontends/qt/GuiFontLoader.h    | 3 +++
 src/frontends/qt/GuiFontMetrics.cpp | 7 +++++--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/frontends/qt/GuiFontLoader.cpp 
b/src/frontends/qt/GuiFontLoader.cpp
index 453d1260ea..0ef922cac7 100644
--- a/src/frontends/qt/GuiFontLoader.cpp
+++ b/src/frontends/qt/GuiFontLoader.cpp
@@ -44,6 +44,15 @@ int const num_math_fonts = sizeof(math_fonts) / 
sizeof(*math_fonts);
 
 namespace lyx {
 
+bool isMathFamily(QString const & name)
+{
+       for (int i = 0; i < num_math_fonts; ++i) {
+               if (math_fonts[i] == name)
+                       return true;
+       }
+       return false;
+}
+
 namespace frontend {
 
 /**
diff --git a/src/frontends/qt/GuiFontLoader.h b/src/frontends/qt/GuiFontLoader.h
index 40c15f5ea0..21e24a7ef4 100644
--- a/src/frontends/qt/GuiFontLoader.h
+++ b/src/frontends/qt/GuiFontLoader.h
@@ -13,11 +13,14 @@
 #define GUI_FONTLOADER_H
 
 class QFont;
+class QString;
 
 namespace lyx {
 
 class FontInfo;
 
+bool isMathFamily(QString const & name);
+
 namespace frontend {
 
 class GuiFontMetrics;
diff --git a/src/frontends/qt/GuiFontMetrics.cpp 
b/src/frontends/qt/GuiFontMetrics.cpp
index 631aecc062..f0300f16ea 100644
--- a/src/frontends/qt/GuiFontMetrics.cpp
+++ b/src/frontends/qt/GuiFontMetrics.cpp
@@ -11,6 +11,7 @@
 
 #include <config.h>
 
+#include "GuiFontLoader.h"
 #include "GuiFontMetrics.h"
 
 #include "qt_helpers.h"
@@ -276,10 +277,12 @@ int GuiFontMetrics::width(docstring const & s) const
        */
        int w = 0;
        // is the string a single character from a math font ?
-       bool const math_char = s.length() == 1 && font_.styleName() == "LyX";
+       // we have to also explicitly check for the family, see bug 13087
+       bool const math_char = s.length() == 1
+               && (font_.styleName() == "LyX" || isMathFamily(font_.family()));
        if (math_char) {
                QString const qs = toqstr(s);
-               int br_width = metrics_.boundingRect(qs).width();
+               int br_width = rbearing(s[0]);
 #if QT_VERSION >= 0x050b00
                int s_width = metrics_.horizontalAdvance(qs);
 #else
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to