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 int maxAscent() const override;
38 int maxDescent() const override;
39 Dimension const defaultDimension() const override;
40 int em() const override;
41 int xHeight() const override;
42 int lineWidth() const override;
43 int underlinePos() const override;
44 int strikeoutPos() const override;
45 bool italic() const override;
46 double italicSlope() const override;
47 int width(char_type c) const override;
48 int ascent(char_type c) const override;
49 int descent(char_type c) const override;
50 int lbearing(char_type c) const override;
51 int rbearing(char_type c) const override;
52 int width(docstring const & s) const override;
53 int signedWidth(docstring const & s) const override;
54 int pos2x(docstring const & s, int pos, bool rtl, double ws) const override;
55 int x2pos(docstring const & s, int & x, bool rtl, double ws) const override;
56 bool breakAt(docstring & s, int & x, bool rtl, bool force) const override;
57 Dimension const dimension(char_type c) const override;
59 void rectText(docstring const & str,
62 int & descent) const override;
63 void buttonText(docstring const & str,
67 int & descent) const override;
69 int countExpanders(docstring const & str) const override;
71 int width(QString const & str) const;
73 /// Return a pointer to a cached QTextLayout object
74 std::shared_ptr<QTextLayout const>
75 getTextLayout(docstring const & s, bool const rtl,
76 double const wordspacing) const;
80 std::pair<int, int> breakAt_helper(docstring const & s, int const x,
81 bool const rtl, bool const force) const;
86 /// Metrics on the font
87 QFontMetrics metrics_;
89 /// Slope of italic font
92 /// Cache of char widths
93 mutable QHash<char_type, int> width_cache_;
94 /// Cache of string widths
95 mutable Cache<docstring, int> strwidth_cache_;
97 mutable Cache<docstring, std::pair<int, int>> breakat_cache_;
98 /// Cache for QTextLayout
99 mutable Cache<docstring, std::shared_ptr<QTextLayout>> qtextlayout_cache_;
101 struct AscendDescend {
105 /// Cache of char ascends and descends
106 mutable QHash<char_type, AscendDescend> metrics_cache_;
107 /// fill in \c metrics_cache_ at specified value.
108 AscendDescend const fillMetricsCache(char_type) const;
110 /// Cache of char left bearings
111 mutable QHash<char_type, int> lbearing_cache_;
112 /// Cache of char right bearings
113 mutable QHash<char_type, int> rbearing_cache_;
117 } // namespace frontend
120 #endif // GUI_FONT_METRICS_H