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/docstring.h"
22 #include <QFontMetrics>
28 class GuiFontMetrics : public FontMetrics
31 GuiFontMetrics(QFont const & font);
33 virtual ~GuiFontMetrics() {}
35 virtual int maxAscent() const;
36 virtual int maxDescent() const;
37 virtual Dimension const defaultDimension() const;
38 virtual int em() const;
39 virtual int lineWidth() const;
40 virtual int underlinePos() const;
41 virtual int strikeoutPos() const;
42 virtual int width(char_type c) const;
43 virtual int ascent(char_type c) const;
44 virtual int descent(char_type c) const;
45 virtual int lbearing(char_type c) const;
46 virtual int rbearing(char_type c) const;
47 virtual int width(docstring const & s) const;
48 virtual int signedWidth(docstring const & s) const;
49 virtual int pos2x(docstring const & s, int pos, bool rtl, double ws) const;
50 virtual int x2pos(docstring const & s, int & x, bool rtl, double ws) const;
51 virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const;
52 virtual Dimension const dimension(char_type c) const;
54 virtual void rectText(docstring const & str,
58 virtual void buttonText(docstring const & str,
63 int width(QString const & str) const;
69 /// Metrics on the font
70 QFontMetrics metrics_;
72 /// Cache of char widths
73 mutable QHash<char_type, int> width_cache_;
75 /// Cache of string widths
76 mutable QCache<QByteArray, int> strwidth_cache_;
78 struct AscendDescend {
82 /// Cache of char ascends and descends
83 mutable QHash<char_type, AscendDescend> metrics_cache_;
84 /// fill in \c metrics_cache_ at specified value.
85 AscendDescend const fillMetricsCache(char_type) const;
87 /// Cache of char right bearings
88 mutable QHash<char_type, int> rbearing_cache_;
91 } // namespace frontend
94 #endif // GUI_FONT_METRICS_H