Diffstat (limited to 'noncore/apps/opie-reader/CDrawBuffer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CDrawBuffer.cpp | 277 |
1 files changed, 224 insertions, 53 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 | |||
@@ -5,2 +5,4 @@ | |||
5 | #include <qpixmap.h> | 5 | #include <qpixmap.h> |
6 | #include <qimage.h> | ||
7 | #include "useqpe.h" | ||
6 | #include "opie.h" | 8 | #include "opie.h" |
@@ -44,3 +46,3 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | |||
44 | int i; | 46 | int i; |
45 | // qDebug("Trying 2"); | 47 | // //qDebug("Trying 2"); |
46 | len = rhs.len; | 48 | len = rhs.len; |
@@ -62,3 +64,3 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | |||
62 | len = i; | 64 | len = i; |
63 | // qDebug("Tried 2"); | 65 | // //qDebug("Tried 2"); |
64 | return *this; | 66 | return *this; |
@@ -82,2 +84,4 @@ void CDrawBuffer::empty() | |||
82 | { | 84 | { |
85 | m_bSop = false; | ||
86 | m_bEop = false; | ||
83 | len = 0; | 87 | len = 0; |
@@ -113,7 +117,45 @@ void CDrawBuffer::truncate(int n) | |||
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; |
@@ -122,3 +164,3 @@ int CDrawBuffer::width(int numchars) | |||
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) |
@@ -130,4 +172,11 @@ int CDrawBuffer::width(int numchars) | |||
130 | { | 172 | { |
173 | if (currentstyle.canScale()) | ||
174 | { | ||
175 | currentx += (gzoom*currentstyle.getPicture()->width())/100; | ||
176 | } | ||
177 | else | ||
178 | { | ||
131 | currentx += currentstyle.getPicture()->width(); | 179 | currentx += currentstyle.getPicture()->width(); |
132 | } | 180 | } |
181 | } | ||
133 | else | 182 | else |
@@ -141,3 +190,3 @@ int CDrawBuffer::width(int numchars) | |||
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()); |
@@ -145,2 +194,34 @@ int CDrawBuffer::width(int numchars) | |||
145 | QFontMetrics fm(f); | 194 | QFontMetrics fm(f); |
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 | { | ||
146 | currentx += fm.width(str); | 227 | currentx += fm.width(str); |
@@ -148,5 +229,6 @@ int CDrawBuffer::width(int numchars) | |||
148 | } | 229 | } |
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; |
@@ -156,3 +238,3 @@ 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 | } |
@@ -161,8 +243,8 @@ 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()) |
@@ -171,3 +253,3 @@ int CDrawBuffer::offset(int scwidth) | |||
171 | { | 253 | { |
172 | currentx = scwidth - BORDER - rightMargin() - width(); | 254 | currentx = scwidth - _border - rightMargin() - width(); |
173 | } | 255 | } |
@@ -184,3 +266,3 @@ int CDrawBuffer::offset(int scwidth) | |||
184 | case m_AlignLeft: | 266 | case m_AlignLeft: |
185 | currentx = BORDER + leftMargin(); | 267 | currentx = _border + leftMargin(); |
186 | break; | 268 | break; |
@@ -190,26 +272,45 @@ int CDrawBuffer::offset(int scwidth) | |||
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] != ' ') |
203 | } | 290 | { |
291 | nonspace = i; | ||
204 | break; | 292 | break; |
205 | case CStyle::m_AlignCentre: | 293 | } |
294 | } | ||
295 | #ifdef _WINDOWS | ||
296 | for (i = nonspace; i < len; i++) | ||
297 | #else | ||
298 | for (int i = nonspace; i < len; i++) | ||
299 | #endif | ||
300 | { | ||
301 | if ((*this)[i] == ' ') | ||
206 | { | 302 | { |
207 | currentx = (scwidth - width())/2 - BORDER; | 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; |
@@ -218,5 +319,5 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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()); |
@@ -225,3 +326,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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)); |
@@ -230,2 +331,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
230 | #endif | 331 | #endif |
332 | int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2; | ||
231 | if (_bMono) | 333 | if (_bMono) |
@@ -234,3 +336,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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 | } |
@@ -239,3 +341,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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 | } |
@@ -243,3 +345,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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 | } |
@@ -251,6 +353,19 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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 | } |
@@ -264,3 +379,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
264 | { | 379 | { |
265 | _p->drawLine( currentx, _y, currentx + w, _y); | 380 | _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset); |
266 | } | 381 | } |
@@ -269,3 +384,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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 | } |
@@ -273,5 +388,9 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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; |
@@ -282,6 +401,45 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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 | } |
@@ -290,5 +448,4 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
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; |
@@ -299,3 +456,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
299 | } | 456 | } |
300 | while (textend != segs.end() && textstart->start < length()-1); | 457 | while (textend != segs.end() && textstart->start < len); |
301 | } | 458 | } |
@@ -316,3 +473,3 @@ linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) | |||
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; |
@@ -321,3 +478,3 @@ linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) | |||
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 | */ |
@@ -342,5 +499,5 @@ 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 | { |
@@ -359,6 +516,6 @@ void CDrawBuffer::resize() | |||
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 | } |
@@ -378,2 +535,16 @@ void CDrawBuffer::resize() | |||
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 | } |