Diffstat (limited to 'noncore/apps/opie-reader/FontControl.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/FontControl.h | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h index 02049d0..5681496 100644 --- a/noncore/apps/opie-reader/FontControl.h +++ b/noncore/apps/opie-reader/FontControl.h | |||
@@ -1,104 +1,153 @@ | |||
1 | #ifndef __FONTCONTROL_H | 1 | #ifndef __FONTCONTROL_H |
2 | #define __FONTCONTROL_H | 2 | #define __FONTCONTROL_H |
3 | 3 | ||
4 | #include <qfontdatabase.h> | 4 | #include <qfontdatabase.h> |
5 | #include <qfontmetrics.h> | 5 | #include <qfontmetrics.h> |
6 | #include "StyleConsts.h" | 6 | #include "StyleConsts.h" |
7 | 7 | ||
8 | class FontControl | 8 | class FontControl |
9 | { | 9 | { |
10 | int * m_fontsizes; | 10 | int * m_fontsizes; |
11 | int m_size; | 11 | int m_size, g_size; |
12 | QString m_fontname; | 12 | QString m_fontname; |
13 | QString m_fixedfontname; | ||
13 | int m_maxsize; | 14 | int m_maxsize; |
14 | bool m_hasCourier; | 15 | bool m_hasCourier; |
16 | int m_leading, m_extraspace; | ||
17 | unsigned char m_basesize; | ||
15 | public: | 18 | public: |
19 | void setBaseSize(unsigned char _s) { m_basesize = _s; } | ||
20 | unsigned char getBaseSize() { return m_basesize; } | ||
21 | int gzoom(); | ||
16 | FontControl(QString n = "helvetica", int size = 10) | 22 | FontControl(QString n = "helvetica", int size = 10) |
17 | : | 23 | : |
18 | m_fontsizes(NULL), m_hasCourier(false) | 24 | m_fontsizes(NULL), m_hasCourier(false), m_leading(0), m_extraspace(0) |
19 | { | 25 | { |
20 | ChangeFont(n, size); | 26 | ChangeFont(n, size); |
21 | } | 27 | } |
22 | ~FontControl() | 28 | ~FontControl() |
23 | { | 29 | { |
24 | if (m_fontsizes != NULL) delete [] m_fontsizes; | 30 | if (m_fontsizes != NULL) delete [] m_fontsizes; |
25 | } | 31 | } |
26 | void hasCourier(bool _b) { m_hasCourier = _b; } | 32 | void hasCourier(bool _b, const QString& _nm) |
33 | { | ||
34 | m_hasCourier = _b; | ||
35 | m_fixedfontname = _nm; | ||
36 | } | ||
37 | QString& fixedfontname() { return m_fixedfontname; } | ||
27 | bool hasCourier() { return m_hasCourier; } | 38 | bool hasCourier() { return m_hasCourier; } |
28 | QString name() { return m_fontname; } | 39 | QString name() { return m_fontname; } |
29 | int currentsize() { return m_fontsizes[m_size]; } | 40 | int currentsize() { return m_fontsizes[m_size]; } |
30 | int getsize(CStyle size) | 41 | int getsize(const CStyle& size) |
31 | { | 42 | { |
32 | int tgt = m_size+size.getFontSize(); | 43 | int tgt = m_size+size.getFontSize(); |
33 | if (tgt < 0) | 44 | if (tgt < 0) |
34 | { | 45 | { |
35 | tgt = 0; | 46 | tgt = 0; |
36 | } | 47 | } |
37 | if (tgt >= m_maxsize) | 48 | if (tgt >= m_maxsize) |
38 | { | 49 | { |
39 | tgt = m_maxsize - 1; | 50 | tgt = m_maxsize - 1; |
40 | } | 51 | } |
41 | return m_fontsizes[tgt]; | 52 | return m_fontsizes[tgt]; |
42 | } | 53 | } |
43 | int ascent() | 54 | int ascent() |
44 | { | 55 | { |
45 | QFont f(name(), currentsize()); | 56 | QFont f(name(), currentsize()); |
46 | QFontMetrics fm(f); | 57 | QFontMetrics fm(f); |
47 | return fm.ascent(); | 58 | return fm.ascent(); |
48 | } | 59 | } |
49 | int ascent(CStyle ch) | 60 | int ascent(const CStyle& ch) |
50 | { | 61 | { |
51 | QFont f(name(), getsize(ch)); | 62 | QFont f(name(), getsize(ch)); |
52 | QFontMetrics fm(f); | 63 | QFontMetrics fm(f); |
53 | return fm.ascent(); | 64 | return fm.ascent(); |
54 | } | 65 | } |
55 | int descent() | 66 | int descent() |
56 | { | 67 | { |
57 | QFont f(name(), currentsize()); | 68 | QFont f(name(), currentsize()); |
58 | QFontMetrics fm(f); | 69 | QFontMetrics fm(f); |
59 | return fm.descent(); | 70 | return fm.descent(); |
60 | } | 71 | } |
61 | int descent(CStyle ch) | 72 | int descent(const CStyle& ch) |
62 | { | 73 | { |
63 | QFont f(name(), getsize(ch)); | 74 | QFont f(name(), getsize(ch)); |
64 | QFontMetrics fm(f); | 75 | QFontMetrics fm(f); |
65 | return fm.descent(); | 76 | return fm.descent(); |
66 | } | 77 | } |
67 | int lineSpacing() | 78 | int lineSpacing() |
68 | { | 79 | { |
69 | QFont f(name(), currentsize()); | 80 | QFont f(name(), currentsize()); |
70 | QFontMetrics fm(f); | 81 | QFontMetrics fm(f); |
71 | return fm.lineSpacing(); | 82 | return fm.lineSpacing(); |
72 | } | 83 | } |
73 | int lineSpacing(CStyle ch) | 84 | int lineSpacing(const CStyle& ch) |
74 | { | 85 | { |
75 | QFont f(name(), getsize(ch)); | 86 | QFont f(name(), getsize(ch)); |
76 | QFontMetrics fm(f); | 87 | QFontMetrics fm(f); |
77 | return fm.lineSpacing(); | 88 | return fm.lineSpacing(); |
78 | } | 89 | } |
79 | bool decreasesize() | 90 | bool decreasesize() |
80 | { | 91 | { |
92 | /* | ||
81 | if (--m_size < 0) | 93 | if (--m_size < 0) |
82 | { | 94 | { |
83 | m_size = 0; | 95 | m_size = 0; |
84 | return false; | 96 | return false; |
85 | } | 97 | } |
86 | else return true; | 98 | else return true; |
99 | */ | ||
100 | if (g_size-- == m_size) | ||
101 | { | ||
102 | if (--m_size < 0) | ||
103 | { | ||
104 | m_size = 0; | ||
105 | } | ||
106 | } | ||
107 | // qDebug("Font:%d Graphics:%d", m_size, g_size); | ||
108 | return true; | ||
87 | } | 109 | } |
88 | bool increasesize() | 110 | bool increasesize() |
89 | { | 111 | { |
112 | /* | ||
90 | if (++m_size >= m_maxsize) | 113 | if (++m_size >= m_maxsize) |
91 | { | 114 | { |
92 | m_size = m_maxsize - 1; | 115 | m_size = m_maxsize - 1; |
93 | return false; | 116 | return false; |
94 | } | 117 | } |
95 | else return true; | 118 | else return true; |
119 | */ | ||
120 | if (g_size++ == m_size) | ||
121 | { | ||
122 | if (++m_size >= m_maxsize) | ||
123 | { | ||
124 | m_size = m_maxsize - 1; | ||
125 | } | ||
126 | } | ||
127 | // qDebug("Font:%d Graphics:%d", m_size, g_size); | ||
128 | return true; | ||
96 | } | 129 | } |
97 | bool ChangeFont(QString& n) | 130 | bool ChangeFont(QString& n) |
98 | { | 131 | { |
99 | return ChangeFont(n, currentsize()); | 132 | return ChangeFont(n, currentsize()); |
100 | } | 133 | } |
101 | bool ChangeFont(QString& n, int tgt); | 134 | bool ChangeFont(QString& n, int tgt); |
135 | void setlead(int _lead) | ||
136 | { | ||
137 | m_leading = _lead; | ||
138 | } | ||
139 | int getlead() | ||
140 | { | ||
141 | return m_leading; | ||
142 | } | ||
143 | void setextraspace(int _lead) | ||
144 | { | ||
145 | m_extraspace = _lead; | ||
146 | } | ||
147 | int getextraspace() | ||
148 | { | ||
149 | return m_extraspace; | ||
150 | } | ||
102 | }; | 151 | }; |
103 | 152 | ||
104 | #endif | 153 | #endif |