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.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp
index bfb3027..227f0f6 100644
--- a/noncore/apps/opie-reader/CDrawBuffer.cpp
+++ b/noncore/apps/opie-reader/CDrawBuffer.cpp
@@ -343,48 +343,49 @@ int CDrawBuffer::rightMargin()
343{ 343{
344 return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style)+3)/6; 344 return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style)+3)/6;
345} 345}
346 346
347int CDrawBuffer::offset(int scwidth, unsigned short _lborder, unsigned short _rborder, int availht) 347int CDrawBuffer::offset(int scwidth, unsigned short _lborder, unsigned short _rborder, int availht)
348{ 348{
349 int currentx = _lborder; 349 int currentx = _lborder;
350 switch(segs.begin()->style.getJustify()) 350 switch(segs.begin()->style.getJustify())
351 { 351 {
352 case m_AlignRight: 352 case m_AlignRight:
353 { 353 {
354 currentx = scwidth - _rborder - rightMargin() - width(availht); 354 currentx = scwidth - _rborder - rightMargin() - width(availht);
355 } 355 }
356 break; 356 break;
357 case m_AlignCentre: 357 case m_AlignCentre:
358 { 358 {
359 currentx = ( 359 currentx = (
360 scwidth - _lborder -_rborder + 360 scwidth - _lborder -_rborder +
361 leftMargin() - rightMargin() 361 leftMargin() - rightMargin()
362 - width(availht))/2 + _lborder; 362 - width(availht))/2 + _lborder;
363 } 363 }
364 break; 364 break;
365 case m_AlignJustify: 365 case m_AlignJustify:
366 case m_AlignLeft: 366 case m_AlignLeft:
367 case m_AlignNone:
367 currentx = _lborder + leftMargin(); 368 currentx = _lborder + leftMargin();
368 break; 369 break;
369 } 370 }
370 return currentx; 371 return currentx;
371} 372}
372 373
373void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned short _lborder, unsigned short _rborder, const QColor& _bg, int availht) 374void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned short _lborder, unsigned short _rborder, const QColor& _bg, int availht)
374{ 375{
375 CList<textsegment>::iterator textstart = segs.begin(); 376 CList<textsegment>::iterator textstart = segs.begin();
376 QColor paperColour = QColor(qRgb(textstart->style.pRed(), 377 QColor paperColour = QColor(qRgb(textstart->style.pRed(),
377 textstart->style.pGreen(), 378 textstart->style.pGreen(),
378 textstart->style.pBlue())); 379 textstart->style.pBlue()));
379 380
380 Highlight(_p, !(paperColour == _bg), _lborder, _y, scwidth-(_lborder+_rborder), paperColour); 381 Highlight(_p, !(paperColour == _bg), _lborder, _y, scwidth-(_lborder+_rborder), paperColour);
381 // Highlight(_p, true, _lborder, _y, scwidth-(_lborder+_rborder), paperColour); 382 // Highlight(_p, true, _lborder, _y, scwidth-(_lborder+_rborder), paperColour);
382 int gzoom = fc->gzoom(); 383 int gzoom = fc->gzoom();
383 int currentx = offset(scwidth, _lborder, _rborder, availht); 384 int currentx = offset(scwidth, _lborder, _rborder, availht);
384 if (!m_hastext) 385 if (!m_hastext)
385 { 386 {
386 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++) 387 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++)
387 { 388 {
388 CStyle currentstyle = iter->style; 389 CStyle currentstyle = iter->style;
389 if (currentstyle.isPicture()) 390 if (currentstyle.isPicture())
390 { 391 {
@@ -463,49 +464,49 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
463 int end = (textend != segs.end()) ? textend->start : len; 464 int end = (textend != segs.end()) ? textend->start : len;
464 CStyle currentstyle = textstart->style; 465 CStyle currentstyle = textstart->style;
465 /* 466 /*
466 bool drawBackground = ( 467 bool drawBackground = (
467 currentstyle.bRed() != 255 468 currentstyle.bRed() != 255
468 || 469 ||
469 currentstyle.bGreen() != 255 470 currentstyle.bGreen() != 255
470 || 471 ||
471 currentstyle.bBlue() != 255 472 currentstyle.bBlue() != 255
472 ); 473 );
473 */ 474 */
474 QColor bgColour = QColor(qRgb(currentstyle.bRed(), 475 QColor bgColour = QColor(qRgb(currentstyle.bRed(),
475 currentstyle.bGreen(), 476 currentstyle.bGreen(),
476 currentstyle.bBlue())); 477 currentstyle.bBlue()));
477 drawBackground = !(bgColour == _bg); 478 drawBackground = !(bgColour == _bg);
478 479
479// if (drawBackground) qDebug("Drawing background"); 480// if (drawBackground) qDebug("Drawing background");
480 481
481 QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); 482 QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
482 //f.setUnderline(currentstyle.isUnderline()); 483 //f.setUnderline(currentstyle.isUnderline());
483 //if (currentstyle.isUnderline()) qDebug("UNDERLINE"); 484 //if (currentstyle.isUnderline()) qDebug("UNDERLINE");
484 _p->setFont(f); 485 _p->setFont(f);
485 QString str = text.mid(textstart->start, end-textstart->start); 486 QString str = text.mid(textstart->start, end-textstart->start);
486#if defined(OPIE) || !defined(USEQPE) 487#if defined(OPIE) || !defined(USEQPE)
487 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100)); 488 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10/*0*/));
488#else 489#else
489 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10)); 490 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10));
490#endif 491#endif
491 int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2; 492 int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2;
492 493
493 if (_bMono) 494 if (_bMono)
494 { 495 {
495 496
496 Highlight(_p, drawBackground, currentx, _y, str.length()*_charWidth, bgColour); 497 Highlight(_p, drawBackground, currentx, _y, str.length()*_charWidth, bgColour);
497 if (currentstyle.isUnderline()) 498 if (currentstyle.isUnderline())
498 { 499 {
499 _p->drawLine( currentx, _y+voffset, currentx + str.length()*_charWidth, _y+voffset); 500 _p->drawLine( currentx, _y+voffset, currentx + str.length()*_charWidth, _y+voffset);
500 } 501 }
501 if (currentstyle.isStrikethru()) 502 if (currentstyle.isStrikethru())
502 { 503 {
503 int ascent = fc->ascent(currentstyle)/3; 504 int ascent = fc->ascent(currentstyle)/3;
504 _p->drawLine( currentx, _y-ascent+voffset, currentx + str.length()*_charWidth, _y-ascent+voffset); 505 _p->drawLine( currentx, _y-ascent+voffset, currentx + str.length()*_charWidth, _y-ascent+voffset);
505 } 506 }
506 for (int i = 0; i < str.length(); i++) 507 for (int i = 0; i < str.length(); i++)
507 { 508 {
508 _p->drawText( currentx + i*_charWidth, _y+voffset, QString(str[i])); 509 _p->drawText( currentx + i*_charWidth, _y+voffset, QString(str[i]));
509 } 510 }
510 currentx += str.length()*_charWidth; 511 currentx += str.length()*_charWidth;
511 } 512 }
@@ -637,163 +638,179 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
637 { 638 {
638 Highlight(_p, drawBackground, currentx, _y, scwidth - (currentx + _lborder + _rborder), bgColour); 639 Highlight(_p, drawBackground, currentx, _y, scwidth - (currentx + _lborder + _rborder), bgColour);
639 } 640 }
640 */ 641 */
641} 642}
642 643
643void CDrawBuffer::Highlight(QPainter* _p, bool drawBackground, int _x, int _y, int w, QColor bgColour) 644void CDrawBuffer::Highlight(QPainter* _p, bool drawBackground, int _x, int _y, int w, QColor bgColour)
644{ 645{
645 if (drawBackground) 646 if (drawBackground)
646 { 647 {
647 _p->fillRect(_x, _y-m_ascent, w, m_lineSpacing, bgColour); 648 _p->fillRect(_x, _y-m_ascent, w, m_lineSpacing, bgColour);
648 } 649 }
649} 650}
650 651
651CStyle CDrawBuffer::laststyle() 652CStyle CDrawBuffer::laststyle()
652{ 653{
653 return segs.last().style; 654 return segs.last().style;
654} 655}
655 656
656CStyle CDrawBuffer::firststyle() 657CStyle CDrawBuffer::firststyle()
657{ 658{
658 return segs.first().style; 659 return segs.first().style;
659} 660}
660 661
661linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt, size_t& offset, size_t& pictgt, QImage*& img) 662linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt, size_t& offset, size_t& pictgt, QImage*& img, size_t& tabletgt)
662{ 663{
663 linkType ret = eNone; 664 linkType ret = eNone;
664 int end = 0; 665 int end = 0;
665 CStyle currentstyle; 666 CStyle currentstyle;
666 CList<textsegment>::iterator textstart = segs.begin(); 667 CList<textsegment>::iterator textstart = segs.begin();
667 CList<textsegment>::iterator textend = textstart; 668 CList<textsegment>::iterator textend = textstart;
668 do 669 do
669 { 670 {
670 textend++; 671 textend++;
671 end = (textend != segs.end()) ? textend->start : len; 672 end = (textend != segs.end()) ? textend->start : len;
672 currentstyle = textstart->style; 673 currentstyle = textstart->style;
673/* 674/*
674 if (currentstyle.isPicture()) qDebug("Passed thru picture"); 675 if (currentstyle.isPicture()) qDebug("Passed thru picture");
675 if (currentstyle.getLink()) qDebug("Passed thru link"); 676 if (currentstyle.getLink()) qDebug("Passed thru link");
676 //qDebug("islink:%d - %d", numchars, end); 677 //qDebug("islink:%d - %d", numchars, end);
677*/ 678*/
678 textstart = textend; 679 textstart = textend;
679 } 680 }
680 while (textend != segs.end() && end <= numchars); 681 while (textend != segs.end() && end <= numchars);
681 img = currentstyle.getPicture(); 682 img = currentstyle.getPicture();
682 if (currentstyle.getPictureLink()) 683 if (currentstyle.getPictureLink())
683 { 684 {
684 pictgt = currentstyle.getPictureLinkData(); 685 pictgt = currentstyle.getPictureLinkData();
685 ret |= ePicture; 686 ret |= ePicture;
686 } 687 }
687 if (currentstyle.getLink()) 688 if (currentstyle.getLink())
688 { 689 {
689 tgt = currentstyle.getData(); 690 tgt = currentstyle.getData();
690 offset = currentstyle.getOffset(); 691 offset = currentstyle.getOffset();
691 ret |= eLink; 692 ret |= eLink;
692 } 693 }
694 if (currentstyle.isTable())
695 {
696 tabletgt = currentstyle.getTable();
697 ret |= eTable;
698 }
693 return ret; 699 return ret;
694} 700}
695 701
696void CDrawBuffer::resize(int availht) 702void CDrawBuffer::resize(int availht)
697{ 703{
698 int gzoom = fc->gzoom(); 704 int gzoom = fc->gzoom();
699 m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; 705 m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
700 /* 706 /*
701 int t_ascent = 0; 707 int t_ascent = 0;
702 int t_descent = 0; 708 int t_descent = 0;
703 int t_lineExtraSpacing = 0; 709 int t_lineExtraSpacing = 0;
704 */ 710 */
705 int t_lineSpacing = 0; 711 int t_lineSpacing = 0;
706 m_hastext = false; 712 m_hastext = false;
707 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; ) 713 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; )
708 { 714 {
709 CStyle _style = iter->style; 715 CStyle _style = iter->style;
710 if (!_style.isPicture()) 716 if (!_style.isPicture())
711 { 717 {
712 m_hastext = true; 718 m_hastext = true;
713 break; 719 break;
714 } 720 }
715 iter++; 721 iter++;
716 } 722 }
717 if (m_hastext) 723 if (m_hastext)
718 { 724 {
719 725 int p_linespacing = 0;
720 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; ) 726 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; )
721 { 727 {
722 CList<textsegment>::iterator next = iter; 728 CList<textsegment>::iterator next = iter;
723 iter++; 729 iter++;
724 int st = next->start; 730 int st = next->start;
725 if (st < 0) st = 0; 731 if (st < 0) st = 0;
726 732
727 CStyle _style = next->style; 733 CStyle _style = next->style;
728 734
729 int linespacing, ascent, descent, extra; 735 int linespacing, ascent, descent, extra;
730 736
731 ascent = fc->ascent(_style); 737 ascent = fc->ascent(_style);
732 descent = fc->descent(_style); 738 descent = fc->descent(_style);
733 linespacing = fc->lineSpacing(_style); 739 linespacing = fc->lineSpacing(_style);
734 extra = linespacing - ascent - descent; 740 extra = linespacing - ascent - descent;
735 /* 741 /*
736 if (ascent > t_ascent) t_ascent = ascent; 742 if (ascent > t_ascent) t_ascent = ascent;
737 if (descent > t_descent) t_descent = descent; 743 if (descent > t_descent) t_descent = descent;
738 if (extra > t_lineExtraSpacing) t_lineExtraSpacing = extra; 744 if (extra > t_lineExtraSpacing) t_lineExtraSpacing = extra;
739 t_lineSpacing = t_ascent+t_descent+t_lineExtraSpacing; 745 t_lineSpacing = t_ascent+t_descent+t_lineExtraSpacing;
740 */ 746 */
741 if (linespacing > t_lineSpacing) t_lineSpacing = linespacing; 747 if (linespacing > t_lineSpacing) t_lineSpacing = linespacing;
742 if (_style.isPicture()) 748 if (_style.isPicture())
743 { 749 {
744 int ht = (gzoom*_style.getPicture()->height())/100; 750 int ht = (gzoom*_style.getPicture()->height())/100;
745 int wt = (gzoom*_style.getPicture()->width())/100; 751 int wt = (gzoom*_style.getPicture()->width())/100;
746 752
747 bool willscale = false; 753 bool willscale = false;
748 if (ht > availht) 754 if (ht > availht)
749 { 755 {
750 wt = (wt*availht)/ht; 756 wt = (wt*availht)/ht;
751 ht = availht; 757 ht = availht;
752 willscale = true; 758 willscale = true;
753 } 759 }
754 if (willscale || _style.canScale()) 760 if (willscale || _style.canScale())
755 { 761 {
756 descent = ((gzoom*_style.getPicture()->height())/100-ascent)/2; 762 descent = ((gzoom*_style.getPicture()->height())/100-ascent)/2;
757 ascent = ((gzoom*_style.getPicture()->height())/100+ascent)/2; 763 ascent = ((gzoom*_style.getPicture()->height())/100+ascent)/2;
758 } 764 }
765 else
766 {
767 descent = (_style.getPicture()->height()-ascent)/2;
768 ascent = (_style.getPicture()->height()+ascent)/2;
769 }
770 int lineSpacing = ascent+descent;
771 if (lineSpacing > p_linespacing)
772 {
773 p_linespacing = lineSpacing;
774 }
775 extra = 0;
759 } 776 }
760 777
761 /* 778 /*
762 else if (fc != NULL) 779 else if (fc != NULL)
763 { 780 {
764 ascent = fc->ascent(_style); 781 ascent = fc->ascent(_style);
765 descent = fc->descent(_style); 782 descent = fc->descent(_style);
766 linespacing = fc->lineSpacing(_style); 783 linespacing = fc->lineSpacing(_style);
767 extra = linespacing - ascent - descent; 784 extra = linespacing - ascent - descent;
768 } 785 }
769 */ 786 */
770 if (ascent > m_ascent) m_ascent = ascent; 787 if (ascent > m_ascent) m_ascent = ascent;
771 if (descent > m_descent) m_descent = descent; 788 if (descent > m_descent) m_descent = descent;
772 if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra; 789 if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra;
773 m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing; 790 m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing;
774 } 791 }
775 m_showPartial = (m_lineSpacing > t_lineSpacing); 792 m_showPartial = (p_linespacing > t_lineSpacing);
776 int lead = fc->getlead(); 793 int lead = fc->getlead();
777 if (lead != 0) 794 if (lead != 0)
778 { 795 {
779 int xt = (lead*t_lineSpacing+5)/10; 796 int xt = (lead*t_lineSpacing+5)/10;
780 m_lineExtraSpacing += xt; 797 m_lineExtraSpacing += xt;
781 m_lineSpacing += xt; 798 m_lineSpacing += xt;
782 } 799 }
783 if (m_bSop) 800 if (m_bSop)
784 { 801 {
785 int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10; 802 int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10;
786 //qDebug("ExtraSpace:%d", xt); 803 //qDebug("ExtraSpace:%d", xt);
787 m_ascent += xt; 804 m_ascent += xt;
788 m_lineSpacing += xt; 805 m_lineSpacing += xt;
789 } 806 }
790 } 807 }
791 else 808 else
792 { 809 {
793 m_showPartial = true; 810 m_showPartial = true;
794 int maxheight = 0; 811 int maxheight = 0;
795 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++) 812 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++)
796 { 813 {
797 CStyle _style = iter->style; 814 CStyle _style = iter->style;
798 if (_style.isPicture()) 815 if (_style.isPicture())
799 { 816 {