author | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
commit | 876e1a4724a7bd75dc642e295de354241096e028 (patch) (unidiff) | |
tree | a37c5dcc9d78e04bb6b859ab89d8cf81e6745087 /noncore/apps/opie-reader/FontControl.h | |
parent | 5fd6636ba3d94b48dd543887316c47c5388a43c2 (diff) | |
download | opie-876e1a4724a7bd75dc642e295de354241096e028.zip opie-876e1a4724a7bd75dc642e295de354241096e028.tar.gz opie-876e1a4724a7bd75dc642e295de354241096e028.tar.bz2 |
update - sorry it took so long. hope this works correctly
Diffstat (limited to 'noncore/apps/opie-reader/FontControl.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/FontControl.h | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h index d427680..02049d0 100644 --- a/noncore/apps/opie-reader/FontControl.h +++ b/noncore/apps/opie-reader/FontControl.h | |||
@@ -10,24 +10,36 @@ class FontControl | |||
10 | int * m_fontsizes; | 10 | int * m_fontsizes; |
11 | int m_size; | 11 | int m_size; |
12 | QString m_fontname; | 12 | QString m_fontname; |
13 | int m_maxsize; | 13 | int m_maxsize; |
14 | bool m_hasCourier; | ||
14 | public: | 15 | public: |
15 | FontControl(QString n = "helvetica", int size = 10) | 16 | FontControl(QString n = "helvetica", int size = 10) |
16 | : | 17 | : |
17 | m_fontsizes(NULL) | 18 | m_fontsizes(NULL), m_hasCourier(false) |
18 | { | 19 | { |
19 | ChangeFont(n, size); | 20 | ChangeFont(n, size); |
20 | } | 21 | } |
21 | ~FontControl() | 22 | ~FontControl() |
22 | { | 23 | { |
23 | if (m_fontsizes != NULL) delete [] m_fontsizes; | 24 | if (m_fontsizes != NULL) delete [] m_fontsizes; |
24 | } | 25 | } |
26 | void hasCourier(bool _b) { m_hasCourier = _b; } | ||
27 | bool hasCourier() { return m_hasCourier; } | ||
25 | QString name() { return m_fontname; } | 28 | QString name() { return m_fontname; } |
26 | int currentsize() { return m_fontsizes[m_size]; } | 29 | int currentsize() { return m_fontsizes[m_size]; } |
27 | int getsize(CStyle size) | 30 | int getsize(CStyle size) |
28 | { | 31 | { |
29 | return m_fontsizes[m_size+size.getFontSize()]; | 32 | int tgt = m_size+size.getFontSize(); |
33 | if (tgt < 0) | ||
34 | { | ||
35 | tgt = 0; | ||
36 | } | ||
37 | if (tgt >= m_maxsize) | ||
38 | { | ||
39 | tgt = m_maxsize - 1; | ||
40 | } | ||
41 | return m_fontsizes[tgt]; | ||
30 | } | 42 | } |
31 | int ascent() | 43 | int ascent() |
32 | { | 44 | { |
33 | QFont f(name(), currentsize()); | 45 | QFont f(name(), currentsize()); |
@@ -85,37 +97,8 @@ class FontControl | |||
85 | bool ChangeFont(QString& n) | 97 | bool ChangeFont(QString& n) |
86 | { | 98 | { |
87 | return ChangeFont(n, currentsize()); | 99 | return ChangeFont(n, currentsize()); |
88 | } | 100 | } |
89 | bool ChangeFont(QString& n, int tgt) | 101 | bool ChangeFont(QString& n, int tgt); |
90 | { | ||
91 | QValueList<int>::Iterator it; | ||
92 | QFontDatabase fdb; | ||
93 | QValueList<int> sizes = fdb.pointSizes(n); | ||
94 | if (sizes.count() == 0) | ||
95 | { | ||
96 | return false; | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | m_fontname = n; | ||
101 | m_maxsize = sizes.count(); | ||
102 | if (m_fontsizes != NULL) delete [] m_fontsizes; | ||
103 | m_fontsizes = new int[m_maxsize]; | ||
104 | uint i = 0; | ||
105 | uint best = 0; | ||
106 | for (it = sizes.begin(); it != sizes.end(); it++) | ||
107 | { | ||
108 | m_fontsizes[i] = (*it); | ||
109 | if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best])) | ||
110 | { | ||
111 | best = i; | ||
112 | } | ||
113 | i++; | ||
114 | } | ||
115 | m_size = best; | ||
116 | } | ||
117 | return true; | ||
118 | } | ||
119 | }; | 102 | }; |
120 | 103 | ||
121 | #endif | 104 | #endif |