3 * \file GuiFontMetrics.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
12 #ifndef GUI_FONT_METRICS_H
13 #define GUI_FONT_METRICS_H
15 #include "frontends/FontMetrics.h"
17 #include "support/Cache.h"
18 #include "support/docstring.h"
21 #include <QFontMetrics>
23 #include <QTextLayout>
30 class GuiFontMetrics : public FontMetrics
33 GuiFontMetrics(QFont const & font);
35 virtual ~GuiFontMetrics() {}
37 virtual int maxAscent() const;
38 virtual int maxDescent() const;
39 virtual Dimension const defaultDimension() const;
40 virtual int em() const;
41 virtual int lineWidth() const;
42 virtual int underlinePos() const;
43 virtual int strikeoutPos() const;
44 virtual int width(char_type c) const;
45 virtual int ascent(char_type c) const;
46 virtual int descent(char_type c) const;
47 virtual int lbearing(char_type c) const;
48 virtual int rbearing(char_type c) const;
49 virtual int width(docstring const & s) const;
50 virtual int signedWidth(docstring const & s) const;
51 virtual int pos2x(docstring const & s, int pos, bool rtl, double ws) const;
52 virtual int x2pos(docstring const & s, int & x, bool rtl, double ws) const;
53 virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const;
54 virtual Dimension const dimension(char_type c) const;
56 virtual void rectText(docstring const & str,
60 virtual void buttonText(docstring const & str,
66 int countExpanders(docstring const & str) const;
68 int width(QString const & str) const;
70 /// Return a pointer to a cached QTextLayout object
71 std::shared_ptr<QTextLayout const>
72 getTextLayout(docstring const & s, bool const rtl,
73 double const wordspacing) const;
77 std::pair<int, int> breakAt_helper(docstring const & s, int const x,
78 bool const rtl, bool const force) const;
83 /// Metrics on the font
84 QFontMetrics metrics_;
86 /// Cache of char widths
87 mutable QHash<char_type, int> width_cache_;
88 /// Cache of string widths
89 mutable Cache<docstring, int> strwidth_cache_;
91 mutable Cache<docstring, std::pair<int, int>> breakat_cache_;
92 /// Cache for QTextLayout
93 mutable Cache<docstring, std::shared_ptr<QTextLayout>> qtextlayout_cache_;
95 struct AscendDescend {
99 /// Cache of char ascends and descends
100 mutable QHash<char_type, AscendDescend> metrics_cache_;
101 /// fill in \c metrics_cache_ at specified value.
102 AscendDescend const fillMetricsCache(char_type) const;
104 /// Cache of char right bearings
105 mutable QHash<char_type, int> rbearing_cache_;
109 } // namespace frontend
112 #endif // GUI_FONT_METRICS_H