author | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
commit | 118d03d815a7615b9c53363218a7ac45b3f4c514 (patch) (unidiff) | |
tree | 356953e2413cddcec0f35bd47bb6439767da7051 /noncore/apps/opie-reader/CDrawBuffer.cpp | |
parent | 00894537decf01c5a5cdc565b2740b5e67a2e90f (diff) | |
download | opie-118d03d815a7615b9c53363218a7ac45b3f4c514.zip opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.gz opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.bz2 |
Incorporated TimWs current source tree and make it compile
Diffstat (limited to 'noncore/apps/opie-reader/CDrawBuffer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CDrawBuffer.cpp | 281 |
1 files changed, 226 insertions, 55 deletions
diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp index ca220e6..77b76fb 100644 --- a/noncore/apps/opie-reader/CDrawBuffer.cpp +++ b/noncore/apps/opie-reader/CDrawBuffer.cpp | |||
@@ -1,17 +1,19 @@ | |||
1 | #include "CDrawBuffer.h" | 1 | #include "CDrawBuffer.h" |
2 | #include "FontControl.h" | 2 | #include "FontControl.h" |
3 | #include <qfontmetrics.h> | 3 | #include <qfontmetrics.h> |
4 | #include <qpainter.h> | 4 | #include <qpainter.h> |
5 | #include <qpixmap.h> | 5 | #include <qpixmap.h> |
6 | #include <qimage.h> | ||
7 | #include "useqpe.h" | ||
6 | #include "opie.h" | 8 | #include "opie.h" |
7 | 9 | ||
8 | CDrawBuffer::~CDrawBuffer() | 10 | CDrawBuffer::~CDrawBuffer() |
9 | { | 11 | { |
10 | while (!segs.isEmpty()) segs.erase(0); | 12 | while (!segs.isEmpty()) segs.erase(0); |
11 | } | 13 | } |
12 | 14 | ||
13 | void CDrawBuffer::setright(CDrawBuffer& rhs, int f) | 15 | void CDrawBuffer::setright(CDrawBuffer& rhs, int f) |
14 | { | 16 | { |
15 | int i; | 17 | int i; |
16 | len = rhs.len; | 18 | len = rhs.len; |
17 | fc = rhs.fc; | 19 | fc = rhs.fc; |
@@ -33,62 +35,64 @@ void CDrawBuffer::setright(CDrawBuffer& rhs, int f) | |||
33 | 35 | ||
34 | segs.push_back(textsegment(st,next->style)); | 36 | segs.push_back(textsegment(st,next->style)); |
35 | } | 37 | } |
36 | } | 38 | } |
37 | for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i]; | 39 | for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i]; |
38 | (*this)[i-f] = '\0'; | 40 | (*this)[i-f] = '\0'; |
39 | len = i; | 41 | len = i; |
40 | } | 42 | } |
41 | 43 | ||
42 | CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | 44 | CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) |
43 | { | 45 | { |
44 | int i; | 46 | int i; |
45 | // qDebug("Trying 2"); | 47 | // //qDebug("Trying 2"); |
46 | len = rhs.len; | 48 | len = rhs.len; |
47 | m_maxstyle = rhs.m_maxstyle; | 49 | m_maxstyle = rhs.m_maxstyle; |
48 | m_ascent = rhs.m_ascent; | 50 | m_ascent = rhs.m_ascent; |
49 | m_descent = rhs.m_descent; | 51 | m_descent = rhs.m_descent; |
50 | m_lineSpacing = rhs.m_lineSpacing; | 52 | m_lineSpacing = rhs.m_lineSpacing; |
51 | m_lineExtraSpacing = rhs.m_lineExtraSpacing; | 53 | m_lineExtraSpacing = rhs.m_lineExtraSpacing; |
52 | while (!segs.isEmpty()) | 54 | while (!segs.isEmpty()) |
53 | { | 55 | { |
54 | segs.erase(0); | 56 | segs.erase(0); |
55 | } | 57 | } |
56 | for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++) | 58 | for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++) |
57 | { | 59 | { |
58 | segs.push_back(*iter); | 60 | segs.push_back(*iter); |
59 | } | 61 | } |
60 | for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i]; | 62 | for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i]; |
61 | (*this)[i] = '\0'; | 63 | (*this)[i] = '\0'; |
62 | len = i; | 64 | len = i; |
63 | // qDebug("Tried 2"); | 65 | // //qDebug("Tried 2"); |
64 | return *this; | 66 | return *this; |
65 | } | 67 | } |
66 | 68 | ||
67 | CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) | 69 | CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) |
68 | { | 70 | { |
69 | int i; | 71 | int i; |
70 | while (!segs.isEmpty()) | 72 | while (!segs.isEmpty()) |
71 | { | 73 | { |
72 | segs.erase(0); | 74 | segs.erase(0); |
73 | } | 75 | } |
74 | segs.push_back(textsegment(0, CStyle())); | 76 | segs.push_back(textsegment(0, CStyle())); |
75 | for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; | 77 | for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; |
76 | (*this)[i] = '\0'; | 78 | (*this)[i] = '\0'; |
77 | len = i; | 79 | len = i; |
78 | return *this; | 80 | return *this; |
79 | } | 81 | } |
80 | 82 | ||
81 | void CDrawBuffer::empty() | 83 | void CDrawBuffer::empty() |
82 | { | 84 | { |
85 | m_bSop = false; | ||
86 | m_bEop = false; | ||
83 | len = 0; | 87 | len = 0; |
84 | (*this)[0] = 0; | 88 | (*this)[0] = 0; |
85 | while (!segs.isEmpty()) | 89 | while (!segs.isEmpty()) |
86 | { | 90 | { |
87 | segs.erase(0); | 91 | segs.erase(0); |
88 | } | 92 | } |
89 | segs.push_back(textsegment(0,CStyle())); | 93 | segs.push_back(textsegment(0,CStyle())); |
90 | m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; | 94 | m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; |
91 | m_bEof = false; | 95 | m_bEof = false; |
92 | } | 96 | } |
93 | 97 | ||
94 | void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) | 98 | void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) |
@@ -102,278 +106,445 @@ void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) | |||
102 | { | 106 | { |
103 | segs.push_back(textsegment(len, _style)); | 107 | segs.push_back(textsegment(len, _style)); |
104 | } | 108 | } |
105 | (*this)[len++] = ch; | 109 | (*this)[len++] = ch; |
106 | } | 110 | } |
107 | 111 | ||
108 | void CDrawBuffer::truncate(int n) | 112 | void CDrawBuffer::truncate(int n) |
109 | { | 113 | { |
110 | len = n; | 114 | len = n; |
111 | (*this)[n] = 0; | 115 | (*this)[n] = 0; |
112 | } | 116 | } |
113 | 117 | ||
114 | int CDrawBuffer::width(int numchars) | 118 | int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _border) |
115 | { | 119 | { |
120 | int gzoom = fc->gzoom(); | ||
116 | int currentx = 0, end = 0; | 121 | int currentx = 0, end = 0; |
117 | QString text = toQString(data()); | 122 | QString text = (numchars < 0) ? toQString(data()) : toQString(data(), numchars); |
118 | CList<textsegment>::iterator textstart = segs.begin(); | 123 | CList<textsegment>::iterator textstart = segs.begin(); |
124 | int extraspace = 0; | ||
125 | bool just = (onscreen && !m_bEop && textstart->style.getJustify() == m_AlignJustify); | ||
126 | int spaces = 0; | ||
127 | int spacesofar = 0; | ||
128 | int spacenumber = 0; | ||
129 | int nonspace = 0; | ||
130 | if (just) | ||
131 | { | ||
132 | for (int i = 0; i < len; i++) | ||
133 | { | ||
134 | if ((*this)[i] != ' ') | ||
135 | { | ||
136 | nonspace = i; | ||
137 | break; | ||
138 | } | ||
139 | } | ||
140 | #ifdef _WINDOWS | ||
141 | for (i = nonspace; i < len; i++) | ||
142 | #else | ||
143 | for (int i = nonspace; i < len; i++) | ||
144 | #endif | ||
145 | { | ||
146 | if ((*this)[i] == ' ') | ||
147 | { | ||
148 | spaces++; | ||
149 | } | ||
150 | } | ||
151 | if (spaces == 0) | ||
152 | { | ||
153 | just = false; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width()); | ||
158 | if (extraspace == 0) just = false; | ||
159 | } | ||
160 | } | ||
119 | CList<textsegment>::iterator textend = textstart; | 161 | CList<textsegment>::iterator textend = textstart; |
120 | do | 162 | do |
121 | { | 163 | { |
122 | textend++; | 164 | textend++; |
123 | end = (textend != segs.end()) ? textend->start : length(); | 165 | end = (textend != segs.end()) ? textend->start : len; |
124 | if (numchars >= 0 && end > numchars) | 166 | if (numchars >= 0 && end > numchars) |
125 | { | 167 | { |
126 | end = numchars; | 168 | end = numchars; |
127 | } | 169 | } |
128 | CStyle currentstyle = textstart->style; | 170 | CStyle currentstyle = textstart->style; |
129 | if (currentstyle.isPicture()) | 171 | if (currentstyle.isPicture()) |
130 | { | 172 | { |
131 | currentx += currentstyle.getPicture()->width(); | 173 | if (currentstyle.canScale()) |
174 | { | ||
175 | currentx += (gzoom*currentstyle.getPicture()->width())/100; | ||
176 | } | ||
177 | else | ||
178 | { | ||
179 | currentx += currentstyle.getPicture()->width(); | ||
180 | } | ||
132 | } | 181 | } |
133 | else | 182 | else |
134 | { | 183 | { |
135 | if (currentstyle.isMono() && !fc->hasCourier()) | 184 | if (currentstyle.isMono() && !fc->hasCourier()) |
136 | { | 185 | { |
137 | int cw = (7*fc->getsize(currentstyle))/10; | 186 | int cw = (7*fc->getsize(currentstyle))/10; |
138 | currentx += cw*(end-textstart->start); | 187 | currentx += cw*(end-textstart->start); |
139 | } | 188 | } |
140 | else | 189 | else |
141 | { | 190 | { |
142 | QFont f(currentstyle.isMono() ? QString("courier") : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); | 191 | QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); |
143 | // f.setUnderline(currentstyle.isUnderline()); | 192 | // f.setUnderline(currentstyle.isUnderline()); |
144 | QString str = text.mid(textstart->start, end-textstart->start); | 193 | QString str = text.mid(textstart->start, end-textstart->start); |
145 | QFontMetrics fm(f); | 194 | QFontMetrics fm(f); |
146 | currentx += fm.width(str); | 195 | if (just) |
196 | { | ||
197 | int lastspace = -1; | ||
198 | int nsp = 0; | ||
199 | int cx = currentx; | ||
200 | while ((nsp = str.find(" ", lastspace+1)) >= 0) | ||
201 | { | ||
202 | if (nsp > nonspace) | ||
203 | { | ||
204 | spacenumber++; | ||
205 | int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar; | ||
206 | QString nstr = str.mid(lastspace+1, nsp-lastspace); | ||
207 | int lw = fm.width(nstr); | ||
208 | cx += lw+nexttoadd; | ||
209 | spacesofar += nexttoadd; | ||
210 | lastspace = nsp; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | QString nstr = str.mid(lastspace+1, nsp-lastspace); | ||
215 | // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); | ||
216 | int lw = fm.width(nstr); | ||
217 | cx += lw; | ||
218 | lastspace = nsp; | ||
219 | } | ||
220 | } | ||
221 | QString nstr = str.right(str.length()-1-lastspace); | ||
222 | cx += fm.width(nstr); | ||
223 | currentx = cx; | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | currentx += fm.width(str); | ||
228 | } | ||
147 | } | 229 | } |
148 | } | 230 | } |
149 | textstart = textend; | 231 | textstart = textend; |
150 | } | 232 | } |
151 | while (textend != segs.end() && end != numchars); | 233 | while (textend != segs.end() && end != numchars && textstart->start < len); |
152 | return currentx; | 234 | return currentx; |
153 | } | 235 | } |
154 | 236 | ||
155 | int CDrawBuffer::leftMargin() | 237 | int CDrawBuffer::leftMargin() |
156 | { | 238 | { |
157 | return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style))/6; | 239 | return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style)+3)/6; |
158 | } | 240 | } |
159 | 241 | ||
160 | int CDrawBuffer::rightMargin() | 242 | int CDrawBuffer::rightMargin() |
161 | { | 243 | { |
162 | return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style))/6; | 244 | return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style)+3)/6; |
163 | } | 245 | } |
164 | 246 | ||
165 | int CDrawBuffer::offset(int scwidth) | 247 | int CDrawBuffer::offset(int scwidth, unsigned char _border) |
166 | { | 248 | { |
167 | int currentx = BORDER; | 249 | int currentx = _border; |
168 | switch(segs.begin()->style.getJustify()) | 250 | switch(segs.begin()->style.getJustify()) |
169 | { | 251 | { |
170 | case m_AlignRight: | 252 | case m_AlignRight: |
171 | { | 253 | { |
172 | currentx = scwidth - BORDER - rightMargin() - width(); | 254 | currentx = scwidth - _border - rightMargin() - width(); |
173 | } | 255 | } |
174 | break; | 256 | break; |
175 | case m_AlignCentre: | 257 | case m_AlignCentre: |
176 | { | 258 | { |
177 | currentx = ( | 259 | currentx = ( |
178 | scwidth + | 260 | scwidth + |
179 | leftMargin() - rightMargin() | 261 | leftMargin() - rightMargin() |
180 | - width())/2; | 262 | - width())/2; |
181 | } | 263 | } |
182 | break; | 264 | break; |
183 | case m_AlignJustify: | 265 | case m_AlignJustify: |
184 | case m_AlignLeft: | 266 | case m_AlignLeft: |
185 | currentx = BORDER + leftMargin(); | 267 | currentx = _border + leftMargin(); |
186 | break; | 268 | break; |
187 | } | 269 | } |
188 | return currentx; | 270 | return currentx; |
189 | } | 271 | } |
190 | 272 | ||
191 | void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth) | 273 | void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned char _border) |
192 | { | 274 | { |
193 | int currentx = offset(scwidth); | 275 | int gzoom = fc->gzoom(); |
276 | int currentx = offset(scwidth, _border); | ||
194 | QString text = toQString(data()); | 277 | QString text = toQString(data()); |
195 | CList<textsegment>::iterator textstart = segs.begin(); | 278 | CList<textsegment>::iterator textstart = segs.begin(); |
196 | /* | 279 | int extraspace = 0; |
197 | StyleType align = textstart->style.getJustify(); | 280 | bool just = (!m_bEop && textstart->style.getJustify() == m_AlignJustify); |
198 | switch (align) | 281 | int spaces = 0; |
282 | int spacesofar = 0; | ||
283 | int spacenumber = 0; | ||
284 | int nonspace = 0; | ||
285 | if (just) | ||
199 | { | 286 | { |
200 | case CStyle::m_AlignRight: | 287 | for (int i = 0; i < len; i++) |
201 | { | 288 | { |
202 | currentx = scwidth - width() - 2*BORDER; | 289 | if ((*this)[i] != ' ') |
290 | { | ||
291 | nonspace = i; | ||
292 | break; | ||
293 | } | ||
203 | } | 294 | } |
204 | break; | 295 | #ifdef _WINDOWS |
205 | case CStyle::m_AlignCentre: | 296 | for (i = nonspace; i < len; i++) |
297 | #else | ||
298 | for (int i = nonspace; i < len; i++) | ||
299 | #endif | ||
206 | { | 300 | { |
207 | currentx = (scwidth - width())/2 - BORDER; | 301 | if ((*this)[i] == ' ') |
302 | { | ||
303 | spaces++; | ||
304 | } | ||
305 | } | ||
306 | if (spaces == 0) | ||
307 | { | ||
308 | just = false; | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width()); | ||
313 | if (extraspace == 0) just = false; | ||
208 | } | 314 | } |
209 | break; | ||
210 | case CStyle::m_AlignJustify: | ||
211 | case CStyle::m_AlignLeft: | ||
212 | break; | ||
213 | } | 315 | } |
214 | */ | ||
215 | CList<textsegment>::iterator textend = textstart; | 316 | CList<textsegment>::iterator textend = textstart; |
216 | do | 317 | do |
217 | { | 318 | { |
218 | textend++; | 319 | textend++; |
219 | int end = (textend != segs.end()) ? textend->start : length(); | 320 | int end = (textend != segs.end()) ? textend->start : len; |
220 | CStyle currentstyle = textstart->style; | 321 | CStyle currentstyle = textstart->style; |
221 | QFont f((currentstyle.isMono() && fc->hasCourier()) ? QString("courier") : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); | 322 | QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); |
222 | //f.setUnderline(currentstyle.isUnderline()); | 323 | //f.setUnderline(currentstyle.isUnderline()); |
223 | //if (currentstyle.isUnderline()) qDebug("UNDERLINE"); | 324 | //if (currentstyle.isUnderline()) qDebug("UNDERLINE"); |
224 | _p->setFont(f); | 325 | _p->setFont(f); |
225 | QString str = text.mid(textstart->start, end-textstart->start); | 326 | QString str = text.mid(textstart->start, end-textstart->start); |
226 | #ifdef OPIE | 327 | #if defined(OPIE) || !defined(USEQPE) |
227 | _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100)); | 328 | _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100)); |
228 | #else | 329 | #else |
229 | _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10)); | 330 | _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10)); |
230 | #endif | 331 | #endif |
332 | int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2; | ||
231 | if (_bMono) | 333 | if (_bMono) |
232 | { | 334 | { |
233 | if (currentstyle.isUnderline()) | 335 | if (currentstyle.isUnderline()) |
234 | { | 336 | { |
235 | _p->drawLine( currentx, _y, currentx + str.length()*_charWidth, _y); | 337 | _p->drawLine( currentx, _y+voffset, currentx + str.length()*_charWidth, _y+voffset); |
236 | } | 338 | } |
237 | if (currentstyle.isStrikethru()) | 339 | if (currentstyle.isStrikethru()) |
238 | { | 340 | { |
239 | int ascent = fc->ascent(currentstyle)/3; | 341 | int ascent = fc->ascent(currentstyle)/3; |
240 | _p->drawLine( currentx, _y-ascent, currentx + str.length()*_charWidth, _y-ascent); | 342 | _p->drawLine( currentx, _y-ascent+voffset, currentx + str.length()*_charWidth, _y-ascent+voffset); |
241 | } | 343 | } |
242 | for (int i = 0; i < str.length(); i++) | 344 | for (int i = 0; i < str.length(); i++) |
243 | { | 345 | { |
244 | _p->drawText( currentx + i*_charWidth, _y, QString(str[i])); | 346 | _p->drawText( currentx + i*_charWidth, _y+voffset, QString(str[i])); |
245 | } | 347 | } |
246 | currentx += str.length()*_charWidth; | 348 | currentx += str.length()*_charWidth; |
247 | } | 349 | } |
248 | else | 350 | else |
249 | { | 351 | { |
250 | if (currentstyle.isPicture()) | 352 | if (currentstyle.isPicture()) |
251 | { | 353 | { |
354 | int ht = (gzoom*currentstyle.getPicture()->height())/100; | ||
355 | int wt = (gzoom*currentstyle.getPicture()->width())/100; | ||
252 | int ascent = fc->ascent(currentstyle)/2; | 356 | int ascent = fc->ascent(currentstyle)/2; |
253 | int yoffset = currentstyle.getPicture()->height()/2 + ascent; | 357 | int yoffset = ht/2 + ascent; |
254 | _p->drawPixmap( currentx, _y-yoffset, *(currentstyle.getPicture())); | 358 | |
255 | currentx += currentstyle.getPicture()->width(); | 359 | QPixmap pc; |
360 | if (gzoom != 100 && currentstyle.canScale()) | ||
361 | { | ||
362 | QImage im = currentstyle.getPicture()->smoothScale(wt,ht); | ||
363 | pc.convertFromImage(im); | ||
364 | } | ||
365 | else | ||
366 | { | ||
367 | pc.convertFromImage(*currentstyle.getPicture()); | ||
368 | } | ||
369 | _p->drawPixmap( currentx, _y-yoffset, pc ); | ||
370 | currentx += wt; | ||
256 | } | 371 | } |
257 | else | 372 | else |
258 | { | 373 | { |
259 | if (currentstyle.isMono() && !fc->hasCourier()) | 374 | if (currentstyle.isMono() && !fc->hasCourier()) |
260 | { | 375 | { |
261 | int cw = (7*fc->getsize(currentstyle))/10; | 376 | int cw = (7*fc->getsize(currentstyle))/10; |
262 | int w = cw*(end-textstart->start); | 377 | int w = cw*(end-textstart->start); |
263 | if (currentstyle.isUnderline()) | 378 | if (currentstyle.isUnderline()) |
264 | { | 379 | { |
265 | _p->drawLine( currentx, _y, currentx + w, _y); | 380 | _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset); |
266 | } | 381 | } |
267 | if (currentstyle.isStrikethru()) | 382 | if (currentstyle.isStrikethru()) |
268 | { | 383 | { |
269 | int ascent = fc->ascent(currentstyle)/3; | 384 | int ascent = fc->ascent(currentstyle)/3; |
270 | _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent); | 385 | _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset); |
271 | } | 386 | } |
272 | QString str = text.mid(textstart->start, end-textstart->start); | 387 | QString str = text.mid(textstart->start, end-textstart->start); |
273 | 388 | ||
274 | for (int i = 0; i < str.length(); i++) | 389 | for (unsigned int i = 0; i < str.length(); i++) |
275 | { | 390 | { |
276 | _p->drawText( currentx, _y, QString(str[i])); | 391 | #ifdef _WINDOWS |
392 | _p->drawText( currentx, _y+voffset, QString(str.at(i))); | ||
393 | #else | ||
394 | _p->drawText( currentx, _y+voffset, QString(str[i])); | ||
395 | #endif | ||
277 | currentx += cw; | 396 | currentx += cw; |
278 | } | 397 | } |
279 | } | 398 | } |
280 | else | 399 | else |
281 | { | 400 | { |
282 | QFontMetrics fm(f); | 401 | QFontMetrics fm(f); |
283 | int w = fm.width(str); | 402 | int w; |
403 | if (just) | ||
404 | { | ||
405 | int lastspace = -1; | ||
406 | int nsp = 0; | ||
407 | int cx = currentx; | ||
408 | while ((nsp = str.find(" ", lastspace+1)) >= 0) | ||
409 | { | ||
410 | if (nsp+textstart->start >= nonspace) | ||
411 | { | ||
412 | spacenumber++; | ||
413 | int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar; | ||
414 | QString nstr = str.mid(lastspace+1, nsp-lastspace); | ||
415 | // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); | ||
416 | int lw = fm.width(nstr); | ||
417 | _p->drawText( cx, _y+voffset, nstr); | ||
418 | cx += lw+nexttoadd; | ||
419 | spacesofar += nexttoadd; | ||
420 | lastspace = nsp; | ||
421 | } | ||
422 | else | ||
423 | { | ||
424 | QString nstr = str.mid(lastspace+1, nsp-lastspace); | ||
425 | // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); | ||
426 | int lw = fm.width(nstr); | ||
427 | _p->drawText( cx, _y+voffset, nstr); | ||
428 | cx += lw; | ||
429 | lastspace = nsp; | ||
430 | } | ||
431 | } | ||
432 | QString nstr = str.right(str.length()-1-lastspace); | ||
433 | _p->drawText( cx, _y+voffset, nstr); | ||
434 | cx += fm.width(nstr); | ||
435 | w = cx - currentx; | ||
436 | } | ||
437 | else | ||
438 | { | ||
439 | _p->drawText( currentx, _y+voffset, str); | ||
440 | w = fm.width(str); | ||
441 | } | ||
284 | if (currentstyle.isUnderline()) | 442 | if (currentstyle.isUnderline()) |
285 | { | 443 | { |
286 | _p->drawLine( currentx, _y, currentx + w, _y); | 444 | _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset); |
287 | } | 445 | } |
288 | if (currentstyle.isStrikethru()) | 446 | if (currentstyle.isStrikethru()) |
289 | { | 447 | { |
290 | int ascent = fc->ascent(currentstyle)/3; | 448 | int ascent = fc->ascent(currentstyle)/3; |
291 | _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent); | 449 | _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset); |
292 | } | 450 | } |
293 | _p->drawText( currentx, _y, str); | ||
294 | currentx += w; | 451 | currentx += w; |
295 | } | 452 | } |
296 | } | 453 | } |
297 | } | 454 | } |
298 | textstart = textend; | 455 | textstart = textend; |
299 | } | 456 | } |
300 | while (textend != segs.end() && textstart->start < length()-1); | 457 | while (textend != segs.end() && textstart->start < len); |
301 | } | 458 | } |
302 | 459 | ||
303 | CStyle CDrawBuffer::laststyle() | 460 | CStyle CDrawBuffer::laststyle() |
304 | { | 461 | { |
305 | return segs.last().style; | 462 | return segs.last().style; |
306 | } | 463 | } |
307 | 464 | ||
308 | linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) | 465 | linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) |
309 | { | 466 | { |
310 | int end = 0; | 467 | int end = 0; |
311 | CStyle currentstyle; | 468 | CStyle currentstyle; |
312 | CList<textsegment>::iterator textstart = segs.begin(); | 469 | CList<textsegment>::iterator textstart = segs.begin(); |
313 | CList<textsegment>::iterator textend = textstart; | 470 | CList<textsegment>::iterator textend = textstart; |
314 | do | 471 | do |
315 | { | 472 | { |
316 | textend++; | 473 | textend++; |
317 | end = (textend != segs.end()) ? textend->start : length(); | 474 | end = (textend != segs.end()) ? textend->start : len; |
318 | currentstyle = textstart->style; | 475 | currentstyle = textstart->style; |
319 | /* | 476 | /* |
320 | if (currentstyle.isPicture()) qDebug("Passed thru picture"); | 477 | if (currentstyle.isPicture()) qDebug("Passed thru picture"); |
321 | if (currentstyle.getLink()) qDebug("Passed thru link"); | 478 | if (currentstyle.getLink()) qDebug("Passed thru link"); |
322 | qDebug("islink:%d - %d", numchars, end); | 479 | //qDebug("islink:%d - %d", numchars, end); |
323 | */ | 480 | */ |
324 | textstart = textend; | 481 | textstart = textend; |
325 | } | 482 | } |
326 | while (textend != segs.end() && end <= numchars); | 483 | while (textend != segs.end() && end <= numchars); |
327 | // if (currentstyle.isPicture()) qDebug("Clicked on picture"); | 484 | // if (currentstyle.isPicture()) qDebug("Clicked on picture"); |
328 | if (currentstyle.getPictureLink()) | 485 | if (currentstyle.getPictureLink()) |
329 | { | 486 | { |
330 | tgt = currentstyle.getPictureLinkData(); | 487 | tgt = currentstyle.getPictureLinkData(); |
331 | return ePicture; | 488 | return ePicture; |
332 | } | 489 | } |
333 | if (currentstyle.getLink()) | 490 | if (currentstyle.getLink()) |
334 | { | 491 | { |
335 | tgt = currentstyle.getData(); | 492 | tgt = currentstyle.getData(); |
336 | return eLink; | 493 | return eLink; |
337 | } | 494 | } |
338 | return eNone; | 495 | return eNone; |
339 | } | 496 | } |
340 | 497 | ||
341 | void CDrawBuffer::resize() | 498 | void CDrawBuffer::resize() |
342 | { | 499 | { |
343 | int i; | 500 | int gzoom = fc->gzoom(); |
344 | m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; | 501 | m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; |
345 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= length(); ) | 502 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; ) |
346 | { | 503 | { |
347 | CList<textsegment>::iterator next = iter; | 504 | CList<textsegment>::iterator next = iter; |
348 | iter++; | 505 | iter++; |
349 | int st = next->start; | 506 | int st = next->start; |
350 | if (st < 0) st = 0; | 507 | if (st < 0) st = 0; |
351 | 508 | ||
352 | CStyle _style = next->style; | 509 | CStyle _style = next->style; |
353 | 510 | ||
354 | int linespacing, ascent, descent, extra; | 511 | int linespacing, ascent, descent, extra; |
355 | 512 | ||
356 | ascent = fc->ascent(_style); | 513 | ascent = fc->ascent(_style); |
357 | descent = fc->descent(_style); | 514 | descent = fc->descent(_style); |
358 | linespacing = fc->lineSpacing(_style); | 515 | linespacing = fc->lineSpacing(_style); |
359 | extra = linespacing - ascent - descent; | 516 | extra = linespacing - ascent - descent; |
360 | if (_style.isPicture()) | 517 | if (_style.isPicture() && _style.canScale()) |
361 | { | 518 | { |
362 | descent = (_style.getPicture()->height()-ascent)/2; | 519 | descent = ((gzoom*_style.getPicture()->height())/100-ascent)/2; |
363 | ascent = (_style.getPicture()->height()+ascent)/2; | 520 | ascent = ((gzoom*_style.getPicture()->height())/100+ascent)/2; |
364 | } | 521 | } |
365 | /* | 522 | /* |
366 | else if (fc != NULL) | 523 | else if (fc != NULL) |
367 | { | 524 | { |
368 | ascent = fc->ascent(_style); | 525 | ascent = fc->ascent(_style); |
369 | descent = fc->descent(_style); | 526 | descent = fc->descent(_style); |
370 | linespacing = fc->lineSpacing(_style); | 527 | linespacing = fc->lineSpacing(_style); |
371 | extra = linespacing - ascent - descent; | 528 | extra = linespacing - ascent - descent; |
372 | } | 529 | } |
373 | */ | 530 | */ |
374 | if (ascent > m_ascent) m_ascent = ascent; | 531 | if (ascent > m_ascent) m_ascent = ascent; |
375 | if (descent > m_descent) m_descent = descent; | 532 | if (descent > m_descent) m_descent = descent; |
376 | if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra; | 533 | if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra; |
377 | m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing; | 534 | m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing; |
378 | } | 535 | } |
536 | int lead = fc->getlead(); | ||
537 | if (lead != 0) | ||
538 | { | ||
539 | int xt = (lead*m_lineSpacing+5)/10; | ||
540 | m_descent += xt; | ||
541 | m_lineSpacing += xt; | ||
542 | } | ||
543 | if (m_bSop) | ||
544 | { | ||
545 | int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10; | ||
546 | //qDebug("ExtraSpace:%d", xt); | ||
547 | m_ascent += xt; | ||
548 | m_lineSpacing += xt; | ||
549 | } | ||
379 | } | 550 | } |