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