mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-26 01:49:22 +00:00
Fix metrics of math characters with 0 width
It seems that QTextLayout does not handle properly a single character with 0 width. This breaks drawing of things like \not. No status line needed as this amends 24648404.
This commit is contained in:
parent
8740cd4c26
commit
81465da5d5
@ -178,16 +178,28 @@ int GuiFontMetrics::width(docstring const & s) const
|
|||||||
int * pw = strwidth_cache_[s];
|
int * pw = strwidth_cache_[s];
|
||||||
if (pw)
|
if (pw)
|
||||||
return *pw;
|
return *pw;
|
||||||
// For some reason QMetrics::width returns a wrong value with Qt5
|
|
||||||
// int w = metrics_.width(toqstr(s));
|
|
||||||
#endif
|
#endif
|
||||||
QTextLayout tl;
|
/* For some reason QMetrics::width returns a wrong value with Qt5
|
||||||
tl.setText(toqstr(s));
|
* with some arabic text. OTOH, QTextLayout is broken for single
|
||||||
tl.setFont(font_);
|
* characters with null width (like \not in mathed). Also, as a
|
||||||
tl.beginLayout();
|
* safety measure, always use QMetrics::width with our math fonts.
|
||||||
QTextLine line = tl.createLine();
|
*/
|
||||||
tl.endLayout();
|
int w = 0;
|
||||||
int w = int(line.naturalTextWidth());
|
if (s.length() == 1
|
||||||
|
#if QT_VERSION >= 0x040800
|
||||||
|
|| font_.styleName() == "LyX"
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
w = metrics_.width(toqstr(s));
|
||||||
|
else {
|
||||||
|
QTextLayout tl;
|
||||||
|
tl.setText(toqstr(s));
|
||||||
|
tl.setFont(font_);
|
||||||
|
tl.beginLayout();
|
||||||
|
QTextLine line = tl.createLine();
|
||||||
|
tl.endLayout();
|
||||||
|
w = int(line.naturalTextWidth());
|
||||||
|
}
|
||||||
#ifdef CACHE_METRICS_WIDTH
|
#ifdef CACHE_METRICS_WIDTH
|
||||||
strwidth_cache_.insert(s, new int(w), s.size() * sizeof(char_type));
|
strwidth_cache_.insert(s, new int(w), s.size() * sizeof(char_type));
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user