summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CDrawBuffer.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/CDrawBuffer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/CDrawBuffer.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp
index ec36fb2..b137ac3 100644
--- a/noncore/apps/opie-reader/CDrawBuffer.cpp
+++ b/noncore/apps/opie-reader/CDrawBuffer.cpp
@@ -19,67 +19,67 @@ void CDrawBuffer::setright(CDrawBuffer& rhs, int f)
19 segs.erase(0); 19 segs.erase(0);
20 } 20 }
21 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); ) 21 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); )
22 { 22 {
23 CList<textsegment>::iterator next = iter; 23 CList<textsegment>::iterator next = iter;
24 iter++; 24 iter++;
25 if (iter == rhs.segs.end() || iter->start > f) 25 if (iter == rhs.segs.end() || iter->start > f)
26 { 26 {
27 int st = next->start-f; 27 int st = next->start-f;
28 if (st < 0) st = 0; 28 if (st < 0) st = 0;
29 29
30 CStyle _style = next->style; 30 CStyle _style = next->style;
31 31
32 segs.push_back(textsegment(st,next->style)); 32 segs.push_back(textsegment(st,next->style));
33 } 33 }
34 } 34 }
35 for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i]; 35 for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i];
36 (*this)[i-f] = '\0'; 36 (*this)[i-f] = '\0';
37 len = i; 37 len = i;
38} 38}
39 39
40CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) 40CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
41{ 41{
42 int i; 42 int i;
43// //qDebug("Trying 2"); 43// //odebug << "Trying 2" << oendl;
44 len = rhs.len; 44 len = rhs.len;
45 m_maxstyle = rhs.m_maxstyle; 45 m_maxstyle = rhs.m_maxstyle;
46 m_ascent = rhs.m_ascent; 46 m_ascent = rhs.m_ascent;
47 m_descent = rhs.m_descent; 47 m_descent = rhs.m_descent;
48 m_lineSpacing = rhs.m_lineSpacing; 48 m_lineSpacing = rhs.m_lineSpacing;
49 m_lineExtraSpacing = rhs.m_lineExtraSpacing; 49 m_lineExtraSpacing = rhs.m_lineExtraSpacing;
50 while (!segs.isEmpty()) 50 while (!segs.isEmpty())
51 { 51 {
52 segs.erase(0); 52 segs.erase(0);
53 } 53 }
54 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++) 54 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++)
55 { 55 {
56 segs.push_back(*iter); 56 segs.push_back(*iter);
57 } 57 }
58 for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i]; 58 for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i];
59 (*this)[i] = '\0'; 59 (*this)[i] = '\0';
60 len = i; 60 len = i;
61// //qDebug("Tried 2"); 61// //odebug << "Tried 2" << oendl;
62 return *this; 62 return *this;
63} 63}
64 64
65CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) 65CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp)
66{ 66{
67 int i; 67 int i;
68 while (!segs.isEmpty()) 68 while (!segs.isEmpty())
69 { 69 {
70 segs.erase(0); 70 segs.erase(0);
71 } 71 }
72 segs.push_back(textsegment(0, CStyle())); 72 segs.push_back(textsegment(0, CStyle()));
73 for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; 73 for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i];
74 (*this)[i] = '\0'; 74 (*this)[i] = '\0';
75 len = i; 75 len = i;
76 return *this; 76 return *this;
77} 77}
78 78
79void CDrawBuffer::empty() 79void CDrawBuffer::empty()
80{ 80{
81 m_bSop = false; 81 m_bSop = false;
82 m_bEop = false; 82 m_bEop = false;
83 len = 0; 83 len = 0;
84 (*this)[0] = 0; 84 (*this)[0] = 0;
85 while (!segs.isEmpty()) 85 while (!segs.isEmpty())
@@ -187,49 +187,49 @@ int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _
187 QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); 187 QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
188 // f.setUnderline(currentstyle.isUnderline()); 188 // f.setUnderline(currentstyle.isUnderline());
189 QString str = text.mid(textstart->start, end-textstart->start); 189 QString str = text.mid(textstart->start, end-textstart->start);
190 QFontMetrics fm(f); 190 QFontMetrics fm(f);
191 if (just) 191 if (just)
192 { 192 {
193 int lastspace = -1; 193 int lastspace = -1;
194 int nsp = 0; 194 int nsp = 0;
195 int cx = currentx; 195 int cx = currentx;
196 while ((nsp = str.find(" ", lastspace+1)) >= 0) 196 while ((nsp = str.find(" ", lastspace+1)) >= 0)
197 { 197 {
198 if (nsp > nonspace) 198 if (nsp > nonspace)
199 { 199 {
200 spacenumber++; 200 spacenumber++;
201 int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar; 201 int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar;
202 QString nstr = str.mid(lastspace+1, nsp-lastspace); 202 QString nstr = str.mid(lastspace+1, nsp-lastspace);
203 int lw = fm.width(nstr); 203 int lw = fm.width(nstr);
204 cx += lw+nexttoadd; 204 cx += lw+nexttoadd;
205 spacesofar += nexttoadd; 205 spacesofar += nexttoadd;
206 lastspace = nsp; 206 lastspace = nsp;
207 } 207 }
208 else 208 else
209 { 209 {
210 QString nstr = str.mid(lastspace+1, nsp-lastspace); 210 QString nstr = str.mid(lastspace+1, nsp-lastspace);
211 // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); 211 // odebug << "str:" << str << ": last:" << lastspace << " new:" << nsp << " nstr:" << nstr << ":" << oendl;
212 int lw = fm.width(nstr); 212 int lw = fm.width(nstr);
213 cx += lw; 213 cx += lw;
214 lastspace = nsp; 214 lastspace = nsp;
215 } 215 }
216 } 216 }
217 QString nstr = str.right(str.length()-1-lastspace); 217 QString nstr = str.right(str.length()-1-lastspace);
218 cx += fm.width(nstr); 218 cx += fm.width(nstr);
219 currentx = cx; 219 currentx = cx;
220 } 220 }
221 else 221 else
222 { 222 {
223 currentx += fm.width(str); 223 currentx += fm.width(str);
224 } 224 }
225 } 225 }
226 } 226 }
227 textstart = textend; 227 textstart = textend;
228 } 228 }
229 while (textend != segs.end() && end != numchars && textstart->start < len); 229 while (textend != segs.end() && end != numchars && textstart->start < len);
230 return currentx; 230 return currentx;
231} 231}
232 232
233int CDrawBuffer::leftMargin() 233int CDrawBuffer::leftMargin()
234{ 234{
235 return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style)+3)/6; 235 return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style)+3)/6;
@@ -296,49 +296,49 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
296 { 296 {
297 if ((*this)[i] == ' ') 297 if ((*this)[i] == ' ')
298 { 298 {
299 spaces++; 299 spaces++;
300 } 300 }
301 } 301 }
302 if (spaces == 0) 302 if (spaces == 0)
303 { 303 {
304 just = false; 304 just = false;
305 } 305 }
306 else 306 else
307 { 307 {
308 extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width()); 308 extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width());
309 if (extraspace == 0) just = false; 309 if (extraspace == 0) just = false;
310 } 310 }
311 } 311 }
312 CList<textsegment>::iterator textend = textstart; 312 CList<textsegment>::iterator textend = textstart;
313 do 313 do
314 { 314 {
315 textend++; 315 textend++;
316 int end = (textend != segs.end()) ? textend->start : len; 316 int end = (textend != segs.end()) ? textend->start : len;
317 CStyle currentstyle = textstart->style; 317 CStyle currentstyle = textstart->style;
318 QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); 318 QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
319 //f.setUnderline(currentstyle.isUnderline()); 319 //f.setUnderline(currentstyle.isUnderline());
320 //if (currentstyle.isUnderline()) qDebug("UNDERLINE"); 320 //if (currentstyle.isUnderline()) odebug << "UNDERLINE" << oendl;
321 _p->setFont(f); 321 _p->setFont(f);
322 QString str = text.mid(textstart->start, end-textstart->start); 322 QString str = text.mid(textstart->start, end-textstart->start);
323#if defined(OPIE) || !defined(USEQPE) 323#if defined(OPIE) || !defined(USEQPE)
324 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100)); 324 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100));
325#else 325#else
326 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10)); 326 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10));
327#endif 327#endif
328 int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2; 328 int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2;
329 if (_bMono) 329 if (_bMono)
330 { 330 {
331 if (currentstyle.isUnderline()) 331 if (currentstyle.isUnderline())
332 { 332 {
333 _p->drawLine( currentx, _y+voffset, currentx + str.length()*_charWidth, _y+voffset); 333 _p->drawLine( currentx, _y+voffset, currentx + str.length()*_charWidth, _y+voffset);
334 } 334 }
335 if (currentstyle.isStrikethru()) 335 if (currentstyle.isStrikethru())
336 { 336 {
337 int ascent = fc->ascent(currentstyle)/3; 337 int ascent = fc->ascent(currentstyle)/3;
338 _p->drawLine( currentx, _y-ascent+voffset, currentx + str.length()*_charWidth, _y-ascent+voffset); 338 _p->drawLine( currentx, _y-ascent+voffset, currentx + str.length()*_charWidth, _y-ascent+voffset);
339 } 339 }
340 for (int i = 0; i < str.length(); i++) 340 for (int i = 0; i < str.length(); i++)
341 { 341 {
342 _p->drawText( currentx + i*_charWidth, _y+voffset, QString(str[i])); 342 _p->drawText( currentx + i*_charWidth, _y+voffset, QString(str[i]));
343 } 343 }
344 currentx += str.length()*_charWidth; 344 currentx += str.length()*_charWidth;
@@ -387,59 +387,59 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
387#ifdef _WINDOWS 387#ifdef _WINDOWS
388 _p->drawText( currentx, _y+voffset, QString(str.at(i))); 388 _p->drawText( currentx, _y+voffset, QString(str.at(i)));
389#else 389#else
390 _p->drawText( currentx, _y+voffset, QString(str[i])); 390 _p->drawText( currentx, _y+voffset, QString(str[i]));
391#endif 391#endif
392 currentx += cw; 392 currentx += cw;
393 } 393 }
394 } 394 }
395 else 395 else
396 { 396 {
397 QFontMetrics fm(f); 397 QFontMetrics fm(f);
398 int w; 398 int w;
399 if (just) 399 if (just)
400 { 400 {
401 int lastspace = -1; 401 int lastspace = -1;
402 int nsp = 0; 402 int nsp = 0;
403 int cx = currentx; 403 int cx = currentx;
404 while ((nsp = str.find(" ", lastspace+1)) >= 0) 404 while ((nsp = str.find(" ", lastspace+1)) >= 0)
405 { 405 {
406 if (nsp+textstart->start >= nonspace) 406 if (nsp+textstart->start >= nonspace)
407 { 407 {
408 spacenumber++; 408 spacenumber++;
409 int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar; 409 int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar;
410 QString nstr = str.mid(lastspace+1, nsp-lastspace); 410 QString nstr = str.mid(lastspace+1, nsp-lastspace);
411 // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); 411 // odebug << "str:" << str << ": last:" << lastspace << " new:" << nsp << " nstr:" << nstr << ":" << oendl;
412 int lw = fm.width(nstr); 412 int lw = fm.width(nstr);
413 _p->drawText( cx, _y+voffset, nstr); 413 _p->drawText( cx, _y+voffset, nstr);
414 cx += lw+nexttoadd; 414 cx += lw+nexttoadd;
415 spacesofar += nexttoadd; 415 spacesofar += nexttoadd;
416 lastspace = nsp; 416 lastspace = nsp;
417 } 417 }
418 else 418 else
419 { 419 {
420 QString nstr = str.mid(lastspace+1, nsp-lastspace); 420 QString nstr = str.mid(lastspace+1, nsp-lastspace);
421 // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); 421 // odebug << "str:" << str << ": last:" << lastspace << " new:" << nsp << " nstr:" << nstr << ":" << oendl;
422 int lw = fm.width(nstr); 422 int lw = fm.width(nstr);
423 _p->drawText( cx, _y+voffset, nstr); 423 _p->drawText( cx, _y+voffset, nstr);
424 cx += lw; 424 cx += lw;
425 lastspace = nsp; 425 lastspace = nsp;
426 } 426 }
427 } 427 }
428 QString nstr = str.right(str.length()-1-lastspace); 428 QString nstr = str.right(str.length()-1-lastspace);
429 _p->drawText( cx, _y+voffset, nstr); 429 _p->drawText( cx, _y+voffset, nstr);
430 cx += fm.width(nstr); 430 cx += fm.width(nstr);
431 w = cx - currentx; 431 w = cx - currentx;
432 } 432 }
433 else 433 else
434 { 434 {
435 _p->drawText( currentx, _y+voffset, str); 435 _p->drawText( currentx, _y+voffset, str);
436 w = fm.width(str); 436 w = fm.width(str);
437 } 437 }
438 if (currentstyle.isUnderline()) 438 if (currentstyle.isUnderline())
439 { 439 {
440 _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset); 440 _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset);
441 } 441 }
442 if (currentstyle.isStrikethru()) 442 if (currentstyle.isStrikethru())
443 { 443 {
444 int ascent = fc->ascent(currentstyle)/3; 444 int ascent = fc->ascent(currentstyle)/3;
445 _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset); 445 _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset);
@@ -449,56 +449,56 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
449 } 449 }
450 } 450 }
451 textstart = textend; 451 textstart = textend;
452 } 452 }
453 while (textend != segs.end() && textstart->start < len); 453 while (textend != segs.end() && textstart->start < len);
454} 454}
455 455
456CStyle CDrawBuffer::laststyle() 456CStyle CDrawBuffer::laststyle()
457{ 457{
458 return segs.last().style; 458 return segs.last().style;
459} 459}
460 460
461linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) 461linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt)
462{ 462{
463 int end = 0; 463 int end = 0;
464 CStyle currentstyle; 464 CStyle currentstyle;
465 CList<textsegment>::iterator textstart = segs.begin(); 465 CList<textsegment>::iterator textstart = segs.begin();
466 CList<textsegment>::iterator textend = textstart; 466 CList<textsegment>::iterator textend = textstart;
467 do 467 do
468 { 468 {
469 textend++; 469 textend++;
470 end = (textend != segs.end()) ? textend->start : len; 470 end = (textend != segs.end()) ? textend->start : len;
471 currentstyle = textstart->style; 471 currentstyle = textstart->style;
472/* 472/*
473 if (currentstyle.isPicture()) qDebug("Passed thru picture"); 473 if (currentstyle.isPicture()) odebug << "Passed thru picture" << oendl;
474 if (currentstyle.getLink()) qDebug("Passed thru link"); 474 if (currentstyle.getLink()) odebug << "Passed thru link" << oendl;
475 //qDebug("islink:%d - %d", numchars, end); 475 //odebug << "islink:" << numchars << " - " << end << "" << oendl;
476*/ 476*/
477 textstart = textend; 477 textstart = textend;
478 } 478 }
479 while (textend != segs.end() && end <= numchars); 479 while (textend != segs.end() && end <= numchars);
480// if (currentstyle.isPicture()) qDebug("Clicked on picture"); 480// if (currentstyle.isPicture()) odebug << "Clicked on picture" << oendl;
481 if (currentstyle.getPictureLink()) 481 if (currentstyle.getPictureLink())
482 { 482 {
483 tgt = currentstyle.getPictureLinkData(); 483 tgt = currentstyle.getPictureLinkData();
484 return ePicture; 484 return ePicture;
485 } 485 }
486 if (currentstyle.getLink()) 486 if (currentstyle.getLink())
487 { 487 {
488 tgt = currentstyle.getData(); 488 tgt = currentstyle.getData();
489 return eLink; 489 return eLink;
490 } 490 }
491 return eNone; 491 return eNone;
492} 492}
493 493
494void CDrawBuffer::resize() 494void CDrawBuffer::resize()
495{ 495{
496 int gzoom = fc->gzoom(); 496 int gzoom = fc->gzoom();
497 m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; 497 m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
498 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; ) 498 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; )
499 { 499 {
500 CList<textsegment>::iterator next = iter; 500 CList<textsegment>::iterator next = iter;
501 iter++; 501 iter++;
502 int st = next->start; 502 int st = next->start;
503 if (st < 0) st = 0; 503 if (st < 0) st = 0;
504 504
@@ -518,29 +518,29 @@ void CDrawBuffer::resize()
518/* 518/*
519 else if (fc != NULL) 519 else if (fc != NULL)
520 { 520 {
521 ascent = fc->ascent(_style); 521 ascent = fc->ascent(_style);
522 descent = fc->descent(_style); 522 descent = fc->descent(_style);
523 linespacing = fc->lineSpacing(_style); 523 linespacing = fc->lineSpacing(_style);
524 extra = linespacing - ascent - descent; 524 extra = linespacing - ascent - descent;
525 } 525 }
526*/ 526*/
527 if (ascent > m_ascent) m_ascent = ascent; 527 if (ascent > m_ascent) m_ascent = ascent;
528 if (descent > m_descent) m_descent = descent; 528 if (descent > m_descent) m_descent = descent;
529 if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra; 529 if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra;
530 m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing; 530 m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing;
531 } 531 }
532 int lead = fc->getlead(); 532 int lead = fc->getlead();
533 if (lead != 0) 533 if (lead != 0)
534 { 534 {
535 int xt = (lead*m_lineSpacing+5)/10; 535 int xt = (lead*m_lineSpacing+5)/10;
536 m_descent += xt; 536 m_descent += xt;
537 m_lineSpacing += xt; 537 m_lineSpacing += xt;
538 } 538 }
539 if (m_bSop) 539 if (m_bSop)
540 { 540 {
541 int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10; 541 int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10;
542 //qDebug("ExtraSpace:%d", xt); 542 //odebug << "ExtraSpace:" << xt << "" << oendl;
543 m_ascent += xt; 543 m_ascent += xt;
544 m_lineSpacing += xt; 544 m_lineSpacing += xt;
545 } 545 }
546} 546}