]> git.lyx.org Git - features.git/commitdiff
Use correct width for \fint
authorEnrico Forestieri <forenr@lyx.org>
Sat, 29 Aug 2020 18:10:26 +0000 (20:10 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 29 Aug 2020 18:10:26 +0000 (20:10 +0200)
Both QTextLine::naturalTextWidth() and QTextLine::horizontalAdvance()
return the same value for \fint. However, examining esint10.ttf with
fontforge does not reveal any issue with the metrics. The fact that
\fint seems to be the only affected symbol might be due to its code
point, which corresponds to a space, so that maybe Qt makes some
assumptions on the metrics.

As QTextLine::naturalTextWidth() returns the width of the line that is
occupied by text, in the case of a single symbol we can obtain the
same value by using the width of the rectangle bounding the symbol.

src/frontends/qt/GuiFontMetrics.cpp

index 9ff027eb089b8a1e68b70827b2497818452a6e0e..361125056ee82eac4f2a504d7719975ae9074f87 100644 (file)
@@ -245,18 +245,18 @@ int GuiFontMetrics::width(docstring const & s) const
 #else
        bool const math_char = s.length() == 1;
 #endif
-       // keep value 0 for math chars with width 0
-       if (!math_char || metrics_.width(toqstr(s)) != 0) {
+       if (math_char) {
+               // keep value 0 for math chars with width 0
+               if (metrics_.width(toqstr(s)) != 0)
+                       w = metrics_.boundingRect(toqstr(s)).width();
+       } else {
                QTextLayout tl;
                tl.setText(toqstr(s));
                tl.setFont(font_);
                tl.beginLayout();
                QTextLine line = tl.createLine();
                tl.endLayout();
-               if (math_char)
-                       w = iround(line.naturalTextWidth());
-               else
-                       w = iround(line.horizontalAdvance());
+               w = iround(line.horizontalAdvance());
        }
        strwidth_cache_.insert(s, w, s.size() * sizeof(char_type));
        return w;