]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiFontMetrics.cpp
Regenerate previews after zoom (#11919)
[features.git] / src / frontends / qt / GuiFontMetrics.cpp
1 /**
2  * \file GuiFontMetrics.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiFontMetrics.h"
15
16 #include "qt_helpers.h"
17
18 #include "Dimension.h"
19
20 #include "support/convert.h"
21 #include "support/debug.h"
22 #include "support/lassert.h"
23 #include "support/lyxlib.h"
24 #include "support/textutils.h"
25
26 #define DISABLE_PMPROF
27 #include "support/pmprof.h"
28
29 #include <QByteArray>
30 #include <QRawFont>
31 #include <QtEndian>
32
33 #if QT_VERSION >= 0x050100
34 #include <QtMath>
35 #else
36 #define qDegreesToRadians(degree) (degree * (M_PI / 180))
37 #endif
38
39 using namespace std;
40 using namespace lyx::support;
41
42 /* Define what mechanisms are used to enforce text direction. There
43  * are two methods that work with different Qt versions. Here we try
44  * to use both methods together.
45  */
46 // Define to use unicode override characters to force direction
47 #define BIDI_USE_OVERRIDE
48 // Define to use QTextLayout flag to force direction
49 #define BIDI_USE_FLAG
50
51 #if !defined(BIDI_USE_OVERRIDE) && !defined(BIDI_USE_FLAG)
52 #  error "Define at least one of BIDI_USE_OVERRIDE or BIDI_USE_FLAG"
53 #endif
54
55
56 #if QT_VERSION < 0x050000
57 inline uint qHash(double key)
58 {
59         return qHash(QByteArray(reinterpret_cast<char const *>(&key), sizeof(key)));
60 }
61 #endif
62
63
64 namespace std {
65
66 /*
67  * Argument-dependent lookup implies that this function shall be
68  * declared in the namespace of its argument. But this is std
69  * namespace, since lyx::docstring is just std::basic_string<wchar_t>.
70  */
71 uint qHash(lyx::docstring const & s)
72 {
73         return qHash(QByteArray(reinterpret_cast<char const *>(s.data()),
74                                 s.size() * sizeof(lyx::docstring::value_type)));
75 }
76
77 } // namespace std
78
79 namespace lyx {
80 namespace frontend {
81
82
83 namespace {
84 // Maximal size/cost for various caches. See QCache documentation to
85 // see what cost means.
86
87 // Limit strwidth_cache_ total cost to 1MB of string data.
88 int const strwidth_cache_max_cost = 1024 * 1024;
89 // Limit breakstr_cache_ total cost to 10MB of string data.
90 // This is useful for documents with very large insets.
91 int const breakstr_cache_max_cost = 10 * 1024 * 1024;
92 // Qt 5.x already has its own caching of QTextLayout objects
93 // but it does not seem to work well on MacOS X.
94 #if (QT_VERSION < 0x050000) || defined(Q_OS_MAC)
95 // Limit qtextlayout_cache_ size to 500 elements (we do not know the
96 // size of the QTextLayout objects anyway).
97 int const qtextlayout_cache_max_size = 500;
98 #else
99 // Disable the cache
100 int const qtextlayout_cache_max_size = 0;
101 #endif
102
103
104 /**
105  * Convert a UCS4 character into a QChar.
106  * This is a hack (it does only make sense for the common part of the UCS4
107  * and UTF16 encodings) and should not be used.
108  * This does only exist because of performance reasons (a real conversion
109  * using iconv is too slow on windows).
110  *
111  * This is no real conversion but a simple cast in reality. This is the reason
112  * why this works well for symbol fonts used in mathed too, even though
113  * these are not real ucs4 characters. These are codepoints in the
114  * computer modern fonts used, nothing unicode related.
115  * See comment in GuiPainter::text() for more explanation.
116  **/
117 inline QChar const ucs4_to_qchar(char_type const ucs4)
118 {
119         LATTEST(is_utf16(ucs4));
120         return QChar(static_cast<unsigned short>(ucs4));
121 }
122 } // namespace
123
124
125 GuiFontMetrics::GuiFontMetrics(QFont const & font)
126         : font_(font), metrics_(font, 0),
127           strwidth_cache_(strwidth_cache_max_cost),
128           breakstr_cache_(breakstr_cache_max_cost),
129           qtextlayout_cache_(qtextlayout_cache_max_size)
130 {
131         // Determine italic slope
132         double const defaultSlope = tan(qDegreesToRadians(19.0));
133         QRawFont raw = QRawFont::fromFont(font);
134         QByteArray post(raw.fontTable("post"));
135         if (post.length() == 0) {
136                 slope_ = defaultSlope;
137                 LYXERR(Debug::FONT, "Screen font doesn't have 'post' table.");
138         } else {
139                 // post table description:
140                 // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6post.html
141                 int32_t italicAngle = qFromBigEndian(*reinterpret_cast<int32_t *>(post.data() + 4));
142                 double angle = italicAngle / 65536.0; // Fixed-point 16.16 to floating-point
143                 slope_ = -tan(qDegreesToRadians(angle));
144                 // Correct italic fonts with zero slope
145                 if (slope_ == 0.0 && font.italic())
146                         slope_ = defaultSlope;
147                 LYXERR(Debug::FONT, "Italic slope: " << slope_);
148         }
149         // If those characters have a non-zero width, we need to avoid them.
150         // This happens with Qt4 with monospace fonts
151         needs_naked_ = width(QString() + QChar(0x2060) + QChar(0x202d) + QChar(0x202e)) > 0;
152         // if (needs_naked_)
153         //      LYXERR0("Font " << font.family() << " needs naked text layouts!");
154 }
155
156
157 int GuiFontMetrics::maxAscent() const
158 {
159         return metrics_.ascent();
160 }
161
162
163 int GuiFontMetrics::maxDescent() const
164 {
165         // We add 1 as the value returned by QT is different than X
166         // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
167         // FIXME: check this
168         return metrics_.descent() + 1;
169 }
170
171
172 int GuiFontMetrics::em() const
173 {
174         return QFontInfo(font_).pixelSize();
175 }
176
177
178 int GuiFontMetrics::xHeight() const
179 {
180 //      LATTEST(metrics_.xHeight() == ascent('x'));
181         return metrics_.xHeight();
182 }
183
184
185 int GuiFontMetrics::lineWidth() const
186 {
187         return metrics_.lineWidth();
188 }
189
190
191 int GuiFontMetrics::underlinePos() const
192 {
193         return metrics_.underlinePos();
194 }
195
196
197 int GuiFontMetrics::strikeoutPos() const
198 {
199         return metrics_.strikeOutPos();
200 }
201
202
203 bool GuiFontMetrics::italic() const
204 {
205         return font_.italic();
206 }
207
208
209 double GuiFontMetrics::italicSlope() const
210 {
211         return slope_;
212 }
213
214
215 namespace {
216 int const outOfLimitMetric = -10000;
217 }
218
219
220 int GuiFontMetrics::lbearing(char_type c) const
221 {
222         int value = lbearing_cache_.value(c, outOfLimitMetric);
223         if (value != outOfLimitMetric)
224                 return value;
225
226         if (is_utf16(c))
227                 value = metrics_.leftBearing(ucs4_to_qchar(c));
228         else {
229                 // FIXME: QFontMetrics::leftBearing does not support the
230                 //        full unicode range. Once it does, we could use:
231                 // metrics_.leftBearing(toqstr(docstring(1, c)));
232                 value = 0;
233         }
234
235         lbearing_cache_.insert(c, value);
236
237         return value;
238 }
239
240
241 int GuiFontMetrics::rbearing(char_type c) const
242 {
243         int value = rbearing_cache_.value(c, outOfLimitMetric);
244         if (value != outOfLimitMetric)
245                 return value;
246
247         // Qt rbearing is from the right edge of the char's width().
248         if (is_utf16(c)) {
249                 QChar sc = ucs4_to_qchar(c);
250                 value = width(c) - metrics_.rightBearing(sc);
251         } else {
252                 // FIXME: QFontMetrics::leftBearing does not support the
253                 //        full unicode range. Once it does, we could use:
254                 // metrics_.rightBearing(toqstr(docstring(1, c)));
255                 value = width(c);
256         }
257
258         rbearing_cache_.insert(c, value);
259
260         return value;
261 }
262
263
264 int GuiFontMetrics::width(docstring const & s) const
265 {
266         PROFILE_THIS_BLOCK(width);
267         if (int * wid_p = strwidth_cache_.object_ptr(s))
268                 return *wid_p;
269         PROFILE_CACHE_MISS(width);
270         /* Several problems have to be taken into account:
271          * * QFontMetrics::width does not returns a wrong value with Qt5 with
272          *   some arabic text, since the glyph-shaping operations are not
273          *   done (documented in Qt5).
274          * * QTextLayout is broken for single characters with null width
275          *   (like \not in mathed).
276          * * While QTextLine::horizontalAdvance is the right thing to use
277      *   for text strings, it does not give a good result with some
278      *   characters like the \int (gyph 4) of esint.
279
280          * The metrics of some of our math fonts (eg. esint) are such that
281          * QTextLine::horizontalAdvance leads, more or less, in the middle
282          * of a symbol. This is the horizontal position where a subscript
283          * should be drawn, so that the superscript has to be moved rightward.
284          * This is done when the kerning() method of the math insets returns
285          * a positive value. The problem with this choice is that navigating
286          * a formula becomes weird. For example, a selection extends only over
287          * about half of the symbol. In order to avoid this, with our math
288          * fonts we use QTextLine::naturalTextWidth, so that a superscript can
289          * be drawn right after the symbol, and move the subscript leftward by
290          * recording a negative value for the kerning.
291         */
292         int w = 0;
293         // is the string a single character from a math font ?
294 #if QT_VERSION >= 0x040800
295         bool const math_char = s.length() == 1 && font_.styleName() == "LyX";
296 #else
297         bool const math_char = s.length() == 1;
298 #endif
299         if (math_char) {
300                 QString const qs = toqstr(s);
301                 int br_width = metrics_.boundingRect(qs).width();
302 #if QT_VERSION >= 0x050b00
303                 int s_width = metrics_.horizontalAdvance(qs);
304 #else
305                 int s_width = metrics_.width(qs);
306 #endif
307                 // keep value 0 for math chars with width 0
308                 if (s_width != 0)
309                         w = max(br_width, s_width);
310         } else {
311                 QTextLayout tl;
312                 tl.setText(toqstr(s));
313                 tl.setFont(font_);
314                 tl.beginLayout();
315                 QTextLine line = tl.createLine();
316                 tl.endLayout();
317                 w = iround(line.horizontalAdvance());
318         }
319         strwidth_cache_.insert(s, w, s.size() * sizeof(char_type));
320         return w;
321 }
322
323
324 int GuiFontMetrics::width(QString const & ucs2) const
325 {
326         return width(qstring_to_ucs4(ucs2));
327 }
328
329
330 int GuiFontMetrics::signedWidth(docstring const & s) const
331 {
332         if (s.empty())
333                 return 0;
334
335         if (s[0] == '-')
336                 return -width(s.substr(1, s.size() - 1));
337         else
338                 return width(s);
339 }
340
341
342 uint qHash(TextLayoutKey const & key)
343 {
344         double params = (2 * key.rtl - 1) * key.ws;
345         return std::qHash(key.s) ^ ::qHash(params);
346 }
347
348
349 // This holds a translation table between the original string and the
350 // QString that we can use with QTextLayout.
351 struct TextLayoutHelper
352 {
353         /// Create the helper
354         /// \c s is the original string
355         /// \c isrtl is true if the string is right-to-left
356         /// \c naked is true to disable the insertion of zero width annotations
357         /// FIXME: remove \c naked argument when Qt4 support goes away.
358         TextLayoutHelper(docstring const & s, bool isrtl, bool naked = false);
359
360         /// translate QString index to docstring index
361         docstring::size_type qpos2pos(int qpos) const
362         {
363                 return lower_bound(pos2qpos_.begin(), pos2qpos_.end(), qpos) - pos2qpos_.begin();
364         }
365
366         /// Translate docstring index to QString index
367         int pos2qpos(docstring::size_type pos) const { return pos2qpos_[pos]; }
368
369         // The original string
370         docstring docstr;
371         // The mirror string
372         QString qstr;
373         // is string right-to-left?
374         bool rtl;
375
376 private:
377         // This vector contains the QString pos for each string position
378         vector<int> pos2qpos_;
379 };
380
381
382 TextLayoutHelper::TextLayoutHelper(docstring const & s, bool isrtl, bool naked)
383         : docstr(s), rtl(isrtl)
384 {
385         // Reserve memory for performance purpose
386         pos2qpos_.reserve(s.size());
387         qstr.reserve(2 * s.size());
388
389         /* Qt will not break at a leading or trailing space, and we need
390          * that sometimes, see http://www.lyx.org/trac/ticket/9921.
391          *
392          * To work around the problem, we enclose the string between
393          * word joiner characters so that the QTextLayout algorithm will
394          * agree to break the text at these extremal spaces.
395          */
396         // Unicode character WORD JOINER
397         QChar const word_joiner(0x2060);
398         if (!naked)
399                 qstr += word_joiner;
400
401 #ifdef BIDI_USE_OVERRIDE
402         /* Unicode override characters enforce drawing direction
403          * Source: http://www.iamcal.com/understanding-bidirectional-text/
404          * Left-to-right override is 0x202d and right-to-left override is 0x202e.
405          */
406         if (!naked)
407                 qstr += QChar(rtl ? 0x202e : 0x202d);
408 #endif
409
410         // Now translate the string character-by-character.
411         bool was_space = false;
412         for (char_type const c : s) {
413                 // insert a word joiner character between consecutive spaces
414                 bool const is_space = isSpace(c);
415                 if (!naked && is_space && was_space)
416                         qstr += word_joiner;
417                 was_space = is_space;
418                 // Remember the QString index at this point
419                 pos2qpos_.push_back(qstr.size());
420                 // Performance: UTF-16 characters are easier
421                 if (is_utf16(c))
422                         qstr += ucs4_to_qchar(c);
423                 else
424                         qstr += toqstr(c);
425         }
426
427         // Final word joiner (see above)
428         if (!naked)
429                 qstr += word_joiner;
430
431         // Add virtual position at the end of the string
432         pos2qpos_.push_back(qstr.size());
433
434         //QString dump = qstr;
435         //LYXERR0("TLH: " << dump.replace(word_joiner, "|").toStdString());
436 }
437
438
439 namespace {
440
441 shared_ptr<QTextLayout>
442 getTextLayout_helper(TextLayoutHelper const & tlh, double const wordspacing,
443                      QFont font)
444 {
445         auto const ptl = make_shared<QTextLayout>();
446         ptl->setCacheEnabled(true);
447         font.setWordSpacing(wordspacing);
448         ptl->setFont(font);
449 #ifdef BIDI_USE_FLAG
450         /* Use undocumented flag to enforce drawing direction
451          * FIXME: This does not work with Qt 5.11 (ticket #11284).
452          */
453         ptl->setFlags(tlh.rtl ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight);
454 #endif
455         ptl->setText(tlh.qstr);
456
457         ptl->beginLayout();
458         ptl->createLine();
459         ptl->endLayout();
460
461         return ptl;
462 }
463
464 }
465
466 shared_ptr<QTextLayout const>
467 GuiFontMetrics::getTextLayout(TextLayoutHelper const & tlh,
468                               double const wordspacing) const
469 {
470         PROFILE_THIS_BLOCK(getTextLayout_TLH);
471         TextLayoutKey key{tlh.docstr, tlh.rtl, wordspacing};
472         if (auto ptl = qtextlayout_cache_[key])
473                 return ptl;
474         PROFILE_CACHE_MISS(getTextLayout_TLH);
475         auto const ptl = getTextLayout_helper(tlh, wordspacing, font_);
476         qtextlayout_cache_.insert(key, ptl);
477         return ptl;
478 }
479
480
481 shared_ptr<QTextLayout const>
482 GuiFontMetrics::getTextLayout(docstring const & s, bool const rtl,
483                               double const wordspacing) const
484 {
485         PROFILE_THIS_BLOCK(getTextLayout);
486         TextLayoutKey key{s, rtl, wordspacing};
487         if (auto ptl = qtextlayout_cache_[key])
488                 return ptl;
489         PROFILE_CACHE_MISS(getTextLayout);
490         TextLayoutHelper tlh(s, rtl, needs_naked_);
491         auto const ptl = getTextLayout_helper(tlh, wordspacing, font_);
492         qtextlayout_cache_.insert(key, ptl);
493         return ptl;
494 }
495
496
497 int GuiFontMetrics::pos2x(docstring const & s, int pos, bool const rtl,
498                           double const wordspacing) const
499 {
500         TextLayoutHelper tlh(s, rtl, needs_naked_);
501         auto ptl = getTextLayout(tlh, wordspacing);
502         // pos can be negative, see #10506.
503         int const qpos = tlh.pos2qpos(max(pos, 0));
504         return static_cast<int>(ptl->lineForTextPosition(qpos).cursorToX(qpos));
505 }
506
507
508 int GuiFontMetrics::x2pos(docstring const & s, int & x, bool const rtl,
509                           double const wordspacing) const
510 {
511         TextLayoutHelper tlh(s, rtl, needs_naked_);
512         auto ptl = getTextLayout(tlh, wordspacing);
513         QTextLine const & tline = ptl->lineForTextPosition(0);
514         int qpos = tline.xToCursor(x);
515         int newx = static_cast<int>(tline.cursorToX(qpos));
516         // The value of qpos may be wrong in rtl text (see ticket #10569).
517         // To work around this, let's have a look at adjacent positions to
518         // see whether we find closer matches.
519         if (rtl && newx < x) {
520                 while (qpos > 0) {
521                         int const xm = static_cast<int>(tline.cursorToX(qpos - 1));
522                         if (abs(xm - x) < abs(newx - x)) {
523                                 --qpos;
524                                 newx = xm;
525                         } else
526                                 break;
527                 }
528         } else if (rtl && newx > x) {
529                 while (qpos < tline.textLength()) {
530                         int const xp = static_cast<int>(tline.cursorToX(qpos + 1));
531                         if (abs(xp - x) < abs(newx - x)) {
532                                 ++qpos;
533                                 newx = xp;
534                         } else
535                                 break;
536                 }
537         }
538         // correct x value to the actual cursor position.
539         x = newx;
540
541         return tlh.qpos2pos(qpos);
542 }
543
544
545 FontMetrics::Breaks
546 GuiFontMetrics::breakString_helper(docstring const & s, int first_wid, int wid,
547                                    bool rtl, bool force) const
548 {
549         TextLayoutHelper const tlh(s, rtl, needs_naked_);
550
551         QTextLayout tl;
552 #ifdef BIDI_USE_FLAG
553         /* Use undocumented flag to enforce drawing direction
554          * FIXME: This does not work with Qt 5.11 (ticket #11284).
555          */
556         tl.setFlags(rtl ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight);
557 #endif
558         tl.setText(tlh.qstr);
559         tl.setFont(font_);
560         QTextOption to;
561         /*
562          * Some Asian languages split lines anywhere (no notion of
563          * word). It seems that QTextLayout is not aware of this fact.
564          * See for reference:
565          *    https://en.wikipedia.org/wiki/Line_breaking_rules_in_East_Asian_languages
566          *
567          * FIXME: Something shall be done about characters which are
568          * not allowed at the beginning or end of line.
569          */
570         to.setWrapMode(force ? QTextOption::WrapAtWordBoundaryOrAnywhere
571                              : QTextOption::WordWrap);
572         tl.setTextOption(to);
573
574         bool first = true;
575         tl.beginLayout();
576         while(true) {
577                 QTextLine line = tl.createLine();
578                 if (!line.isValid())
579                         break;
580                 line.setLineWidth(first ? first_wid : wid);
581                 first = false;
582         }
583         tl.endLayout();
584
585         Breaks breaks;
586         int pos = 0;
587         for (int i = 0 ; i < tl.lineCount() ; ++i) {
588                 QTextLine const & line = tl.lineAt(i);
589                 int const line_epos = line.textStart() + line.textLength();
590                 int const epos = tlh.qpos2pos(line_epos);
591                 // This does not take trailing spaces into account, except for the last line.
592                 int const wid = iround(line.naturalTextWidth());
593                 // If the line is not the last one, trailing space is always omitted.
594                 int nspc_wid = wid;
595                 // For the last line, compute the width without trailing space
596                 if (i + 1 == tl.lineCount() && !s.empty() && isSpace(s.back())
597                     && line.textStart() <= tlh.pos2qpos(s.size() - 1))
598                         nspc_wid = iround(line.cursorToX(tlh.pos2qpos(s.size() - 1)));
599                 breaks.emplace_back(epos - pos, wid, nspc_wid);
600                 pos = epos;
601         }
602
603         return breaks;
604 }
605
606
607 uint qHash(BreakStringKey const & key)
608 {
609         // assume widths are less than 10000. This fits in 32 bits.
610         uint params = key.force + 2 * key.rtl + 4 * key.first_wid + 10000 * key.wid;
611         return std::qHash(key.s) ^ ::qHash(params);
612 }
613
614
615 FontMetrics::Breaks GuiFontMetrics::breakString(docstring const & s, int first_wid, int wid,
616                                                 bool rtl, bool force) const
617 {
618         PROFILE_THIS_BLOCK(breakString);
619         if (s.empty())
620                 return Breaks();
621
622         BreakStringKey key{s, first_wid, wid, rtl, force};
623         Breaks brks;
624         if (auto * brks_ptr = breakstr_cache_.object_ptr(key))
625                 brks = *brks_ptr;
626         else {
627                 PROFILE_CACHE_MISS(breakString);
628                 brks = breakString_helper(s, first_wid, wid, rtl, force);
629                 breakstr_cache_.insert(key, brks, sizeof(key) + s.size() * sizeof(char_type));
630         }
631         return brks;
632 }
633
634
635 void GuiFontMetrics::rectText(docstring const & str,
636         int & w, int & ascent, int & descent) const
637 {
638         // FIXME: let offset depend on font (this is Inset::TEXT_TO_OFFSET)
639         int const offset = 4;
640
641         w = width(str) + offset;
642         ascent = metrics_.ascent() + offset / 2;
643         descent = metrics_.descent() + offset / 2;
644 }
645
646
647 void GuiFontMetrics::buttonText(docstring const & str, const int offset,
648         int & w, int & ascent, int & descent) const
649 {
650         rectText(str, w, ascent, descent);
651         w += offset;
652 }
653
654
655 Dimension const GuiFontMetrics::defaultDimension() const
656 {
657         return Dimension(0, maxAscent(), maxDescent());
658 }
659
660
661 Dimension const GuiFontMetrics::dimension(char_type c) const
662 {
663         return Dimension(width(c), ascent(c), descent(c));
664 }
665
666
667 GuiFontMetrics::AscendDescend const GuiFontMetrics::fillMetricsCache(
668                 char_type c) const
669 {
670         QRect r;
671         if (is_utf16(c))
672                 r = metrics_.boundingRect(ucs4_to_qchar(c));
673         else
674                 r = metrics_.boundingRect(toqstr(docstring(1, c)));
675
676         AscendDescend ad = { -r.top(), r.bottom() + 1};
677         // We could as well compute the width but this is not really
678         // needed for now as it is done directly in width() below.
679         metrics_cache_.insert(c, ad);
680
681         return ad;
682 }
683
684
685 int GuiFontMetrics::width(char_type c) const
686 {
687         int value = width_cache_.value(c, outOfLimitMetric);
688         if (value != outOfLimitMetric)
689                 return value;
690
691 #if QT_VERSION >= 0x050b00
692         if (is_utf16(c))
693                 value = metrics_.horizontalAdvance(ucs4_to_qchar(c));
694         else
695                 value = metrics_.horizontalAdvance(toqstr(docstring(1, c)));
696 #else
697         if (is_utf16(c))
698                 value = metrics_.width(ucs4_to_qchar(c));
699         else
700                 value = metrics_.width(toqstr(docstring(1, c)));
701 #endif
702
703         width_cache_.insert(c, value);
704
705         return value;
706 }
707
708
709 int GuiFontMetrics::ascent(char_type c) const
710 {
711         static AscendDescend const outOfLimitAD =
712                 {outOfLimitMetric, outOfLimitMetric};
713         AscendDescend value = metrics_cache_.value(c, outOfLimitAD);
714         if (value.ascent != outOfLimitMetric)
715                 return value.ascent;
716
717         value = fillMetricsCache(c);
718         return value.ascent;
719 }
720
721
722 int GuiFontMetrics::descent(char_type c) const
723 {
724         static AscendDescend const outOfLimitAD =
725                 {outOfLimitMetric, outOfLimitMetric};
726         AscendDescend value = metrics_cache_.value(c, outOfLimitAD);
727         if (value.descent != outOfLimitMetric)
728                 return value.descent;
729
730         value = fillMetricsCache(c);
731         return value.descent;
732 }
733
734 } // namespace frontend
735 } // namespace lyx