summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/striphtml.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/striphtml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/striphtml.cpp252
1 files changed, 209 insertions, 43 deletions
diff --git a/noncore/apps/opie-reader/striphtml.cpp b/noncore/apps/opie-reader/striphtml.cpp
index e86402b..c434dbb 100644
--- a/noncore/apps/opie-reader/striphtml.cpp
+++ b/noncore/apps/opie-reader/striphtml.cpp
@@ -3,17 +3,16 @@
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qdir.h> 4#include <qdir.h>
5#ifdef USEQPE 5#ifdef USEQPE
6#include <qpe/global.h> 6#include <qpe/global.h>
7#endif 7#endif
8#include "CDrawBuffer.h" 8#include "CDrawBuffer.h"
9#include "striphtml.h" 9#include "striphtml.h"
10#include "hrule.h" 10#include "hrule.h"
11#include "util.h"
12 11
13#include <qregexp.h> 12#include <qregexp.h>
14#include <qimage.h> 13#include <qimage.h>
15#include <qpixmap.h> 14#include <qpixmap.h>
16//#include <qprogressdialog.h> 15//#include <qprogressdialog.h>
17//#include <qapplication.h> 16//#include <qapplication.h>
18 17
19static unsigned char h2i(unsigned char c) 18static unsigned char h2i(unsigned char c)
@@ -85,25 +84,33 @@ void striphtml::skipblock(const QString& _ent)
85 84
86 ch = skip_ws(); 85 ch = skip_ws();
87 86
88 ent = getname(ch, " >").lower(); 87 ent = getname(ch, " >").lower();
89 qDebug("Skipblock:%s", (const char*)ent); 88 qDebug("Skipblock:%s", (const char*)ent);
90 } while (ent != _ent && ch != UEOF); 89 } while (ent != _ent && ch != UEOF);
91} 90}
92 91
93void striphtml::locate(unsigned int n) 92void striphtml::reset()
94{ 93{
95 m_inblock = false; 94 m_inblock = false;
96 text_q = ""; 95 text_q = "";
96 q = "";
97 tablenesteddepth = 0;
97 forcecentre = false; 98 forcecentre = false;
98 ignorespace = false; 99 ignorespace = false;
100 indent = 0;
99 while (!stylestack.isEmpty()) stylestack.pop(); 101 while (!stylestack.isEmpty()) stylestack.pop();
100 currentstyle.unset(); 102 currentstyle.unset();
103}
104
105void striphtml::locate(unsigned int n)
106{
101 qDebug("striphtml:locating:%u", n); 107 qDebug("striphtml:locating:%u", n);
108 reset();
102 parent->locate(n); 109 parent->locate(n);
103} 110}
104 111
105int striphtml::getpara(CBuffer& buff, unsigned long& startpos) 112int striphtml::getpara(CBuffer& buff, unsigned long& startpos)
106{ 113{
107 tchar ch; 114 tchar ch;
108 CStyle sty; 115 CStyle sty;
109 unsigned long pos; 116 unsigned long pos;
@@ -228,16 +235,23 @@ QString striphtml::dehtml(const QString& _info)
228 } 235 }
229 return info; 236 return info;
230} 237}
231 238
232bool striphtml::findanchor(const QString& _info) 239bool striphtml::findanchor(const QString& _info)
233{ 240{
234 // QProgressDialog dlg("Finding link...", QString::null, 0, NULL, "progress", true); 241 // QProgressDialog dlg("Finding link...", QString::null, 0, NULL, "progress", true);
235 // QProgressBar dlg(0); 242 // QProgressBar dlg(0);
243 if (parent->findanchor(_info))
244 {
245 reset();
246 return true;
247 }
248 qDebug("Using html find");
249 parent->locate(parent->startSection());
236#if defined(USEQPE) || defined(_WINDOWS) 250#if defined(USEQPE) || defined(_WINDOWS)
237 QString info; 251 QString info;
238 for (int i = 0; i < _info.length(); i++) 252 for (int i = 0; i < _info.length(); i++)
239 { 253 {
240 tchar ch = _info[i]; 254 tchar ch = _info[i];
241 if (QString(".^$[]*+?").find(ch) != -1) 255 if (QString(".^$[]*+?").find(ch) != -1)
242 { 256 {
243 info += '\\'; 257 info += '\\';
@@ -290,33 +304,43 @@ bool striphtml::findanchor(const QString& _info)
290 { 304 {
291 locate(startpos); 305 locate(startpos);
292 qDebug("Not found"); 306 qDebug("Not found");
293 ret = false; 307 ret = false;
294 } 308 }
295 return ret; 309 return ret;
296} 310}
297 311
298striphtml::striphtml(const QString& _s) : entmap(NULL), isPre(false), currentid(0), lastch(0), currentfile(_s), indent(0), forcecentre(false), m_inblock(false), m_bchm(false), ignorespace(false) 312striphtml::striphtml(const QString& _s) : entmap(NULL), isPre(false), currentid(0), lastch(0), currentfile(_s), indent(0), forcecentre(false), m_inblock(false), m_bchm(false), ignorespace(false), tablenesteddepth(0)
299{ 313{
300 href2filepos = new QMap<QString, unsigned long>; 314 href2filepos = new QMap<QString, unsigned long>;
301 id2href = new QMap<unsigned long, QString>; 315 id2href = new QMap<unsigned long, QString>;
302} 316}
303 317
304striphtml::~striphtml() 318striphtml::~striphtml()
305{ 319{
306 if (entmap != NULL) delete entmap; 320 if (entmap != NULL) delete entmap;
307 delete href2filepos; 321 delete href2filepos;
308 delete id2href; 322 delete id2href;
309} 323}
310 324
311void striphtml::initentmap() 325void striphtml::initentmap()
312{ 326{
313 entmap = new QMap<QString, tchar>; 327 entmap = new QMap<QString, tchar>;
314 QString fname(QTReaderUtil::getPluginPath("data")); 328#ifdef USEQPE
329#ifdef OPIE
330 QString fname(getenv("OPIEDIR"));
331#else
332 QString fname(getenv("QTDIR"));
333#endif
334 fname += "/plugins/reader/data";
335#else
336 QString fname(getenv("READERDIR"));
337 fname += "/data";
338#endif
315 QFileInfo fi; 339 QFileInfo fi;
316 fi.setFile(fname, "HTMLentities"); 340 fi.setFile(fname, "HTMLentities");
317 if (fi.exists()) 341 if (fi.exists())
318 { 342 {
319 fname = fi.absFilePath(); 343 fname = fi.absFilePath();
320 344
321 QFile fl(fname); 345 QFile fl(fname);
322 if (fl.open(IO_ReadOnly)) 346 if (fl.open(IO_ReadOnly))
@@ -407,16 +431,22 @@ QString striphtml::getattr(tchar& ch)
407 { 431 {
408 ch = skip_ws(); 432 ch = skip_ws();
409 if (ch == '"') 433 if (ch == '"')
410 { 434 {
411 mygetch(ch, sty, pos); 435 mygetch(ch, sty, pos);
412 ref = getname(ch, "\""); 436 ref = getname(ch, "\"");
413 ch = skip_ws(); 437 ch = skip_ws();
414 } 438 }
439 else if (ch == '\'')
440 {
441 mygetch(ch, sty, pos);
442 ref = getname(ch, "\'");
443 ch = skip_ws();
444 }
415 else 445 else
416 { 446 {
417 ref = getname(ch, " >"); 447 ref = getname(ch, " >");
418 if (ch == ' ') ch = skip_ws(); 448 if (ch == ' ') ch = skip_ws();
419 } 449 }
420 } 450 }
421 return ref; 451 return ref;
422} 452}
@@ -473,37 +503,41 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString&
473 } 503 }
474 504
475 qDebug("File:%s", (const char*)file); 505 qDebug("File:%s", (const char*)file);
476 qDebug("Name:%s", (const char*)name); 506 qDebug("Name:%s", (const char*)name);
477 507
478 508
479 if (file.isEmpty()) 509 if (file.isEmpty())
480 { 510 {
511 if (parent->findanchor(name))
512 {
513 reset();
514 return eLink;
515 }
481 fpit = href2filepos->find(name); 516 fpit = href2filepos->find(name);
482 if (fpit != href2filepos->end()) 517 if (fpit != href2filepos->end())
483 { 518 {
484 locate(*fpit); 519 locate(*fpit);
485 return eLink; 520 return eLink;
486 } 521 }
487 else 522 else
488 { 523 {
489 // nm = QString("<a[^>]*name[ \t]*=[ \t]*\"") + name + "\""; 524 // nm = QString("<a[^>]*name[ \t]*=[ \t]*\"") + name + "\"";
490 qDebug("Do a search for:%s", (const char*)name); 525 qDebug("Do a search for:%s", (const char*)name);
491 parent->locate(0);
492 findanchor(name); 526 findanchor(name);
493 return eLink; 527 return eLink;
494 } 528 }
495 } 529 }
496 else 530 else
497 // if (href.find('#') == -1) 531 // if (href.find('#') == -1)
498 { 532 {
499 if (m_bchm) 533 if (m_bchm)
500 { 534 {
501 w = "/"+file; 535 w = file;
502 nm = name; 536 nm = name;
503 return eFile; 537 return eFile;
504 } 538 }
505 else 539 else
506 { 540 {
507 QFileInfo f(currentfile); 541 QFileInfo f(currentfile);
508 QFileInfo f1(f.dir(true), file); 542 QFileInfo f1(f.dir(true), file);
509 if (f1.exists()) 543 if (f1.exists())
@@ -559,17 +593,41 @@ void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos)
559 } 593 }
560 if (ch == '>') 594 if (ch == '>')
561 { 595 {
562 m_inblock = false; 596 m_inblock = false;
563 } 597 }
564 } 598 }
565 if (ch == 10 && !isPre) 599 if (ch == 10 && !isPre)
566 { 600 {
601#ifdef REMOVE_LF_BEFORE_ENDTAG
602 parent->getch(ch, sty, pos);
603 if (ch == '<')
604 {
605 parent->getch(ch, sty, pos);
606 if (ch == '/')
607 {
608 ch = '<';
609 text_q += '/';
610 }
611 else
612 {
613 text_q += '<';
614 text_q += ch;
615 ch = ' ';
616 }
617 }
618 else
619 {
620 text_q += ch;
621 ch = ' ';
622 }
623#else
567 ch = ' '; 624 ch = ' ';
625#endif
568 } 626 }
569} 627}
570 628
571void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos) 629void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos)
572{ 630{
573/* 631/*
574 int count = 0; 632 int count = 0;
575 for (CList<CStyle>::iterator iter = stylestack.begin(); iter != stylestack.end(); ++iter) 633 for (CList<CStyle>::iterator iter = stylestack.begin(); iter != stylestack.end(); ++iter)
@@ -579,17 +637,16 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p
579 qDebug("Currently have %u styles", count); 637 qDebug("Currently have %u styles", count);
580*/ 638*/
581 if (stylestack.isEmpty()) 639 if (stylestack.isEmpty())
582 { 640 {
583 currentstyle.unset(); 641 currentstyle.unset();
584 } 642 }
585 else 643 else
586 { 644 {
587 qDebug("Using stack style");
588 currentstyle = stylestack.first(); 645 currentstyle = stylestack.first();
589 } 646 }
590 if (forcecentre) 647 if (forcecentre)
591 { 648 {
592 currentstyle.setCentreJustify(); 649 currentstyle.setCentreJustify();
593 } 650 }
594 if (ch == ' ') ch = skip_ws(); 651 if (ch == ' ') ch = skip_ws();
595 while (ch != '>' && ch != UEOF) 652 while (ch != '>' && ch != UEOF)
@@ -602,16 +659,20 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p
602 if (attr == "center") 659 if (attr == "center")
603 { 660 {
604 currentstyle.setCentreJustify(); 661 currentstyle.setCentreJustify();
605 } 662 }
606 if (attr == "right") 663 if (attr == "right")
607 { 664 {
608 currentstyle.setRightJustify(); 665 currentstyle.setRightJustify();
609 } 666 }
667 if (attr == "justify")
668 {
669 currentstyle.setFullJustify();
670 }
610 } 671 }
611 if (ent == "id") 672 if (ent == "id")
612 { 673 {
613 (*href2filepos)[attr] = pos; 674 (*href2filepos)[attr] = pos;
614 } 675 }
615 if (ent == "bgcolor") 676 if (ent == "bgcolor")
616 { 677 {
617 qDebug("Got paper colour:%s", (const char*)attr); 678 qDebug("Got paper colour:%s", (const char*)attr);
@@ -649,44 +710,43 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
649 currentstyle.setPicture(false, hRule(w,h,r,g,b)); 710 currentstyle.setPicture(false, hRule(w,h,r,g,b));
650 q = q.right(q.length()-6); 711 q = q.right(q.length()-6);
651 } 712 }
652 else 713 else
653 { 714 {
654 q = q.right(q.length()-1); 715 q = q.right(q.length()-1);
655 } 716 }
656 sty = currentstyle; 717 sty = currentstyle;
718 lastch = ch;
657 return; 719 return;
658 } 720 }
659 do 721 do
660 { 722 {
661 unsigned long npos; 723 unsigned long npos;
662 CStyle dummy; 724 CStyle dummy;
663 mygetch(ch, dummy, pos); 725 mygetch(ch, dummy, pos);
664 // if (ch == 10 && !isPre) ch = ' ';
665 while (ch == '<' && ch != UEOF) 726 while (ch == '<' && ch != UEOF)
666 { 727 {
667 ch = skip_ws(); 728 ch = skip_ws();
668
669 QString ent = getname(ch, " >").lower(); 729 QString ent = getname(ch, " >").lower();
670 730
671 // qDebug("Entity:%s", (const char*)ent); 731 // qDebug("Entity:%s", (const char*)ent);
672 732
673 if (ent == "a"/* || ent == "reference"*/) 733 if (ent == "a"/* || ent == "reference"*/)
674 { 734 {
675 if (ch == ' ') ch = skip_ws(); 735 if (ch == ' ') ch = skip_ws();
676 bool fileposfound = false; 736 bool fileposfound = false;
677 bool ishref = false; 737 bool ishref = false;
678 unsigned int filepos = 0; 738 unsigned int filepos = 0;
679 QString ref, name; 739 QString ref, name;
680 while (ch != '>' && ch != UEOF) 740 while (ch != '>' && ch != UEOF)
681 { 741 {
682 QString ent = getname(ch, " =>").lower(); 742 QString ent = getname(ch, " =>").lower();
683 QString attr = getattr(ch); 743 QString attr = getattr(ch);
684 qDebug("<A>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 744 //qDebug("<A>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
685 if (ent == "name") 745 if (ent == "name")
686 { 746 {
687 name = attr; 747 name = attr;
688 } 748 }
689 if (ent == "onclick") 749 if (ent == "onclick")
690 { 750 {
691 int st = attr.find('\''); 751 int st = attr.find('\'');
692 int nd = attr.findRev('\''); 752 int nd = attr.findRev('\'');
@@ -707,17 +767,17 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
707 ishref = true; 767 ishref = true;
708 ref = attr; 768 ref = attr;
709 } 769 }
710 } 770 }
711 if (ent == "title") 771 if (ent == "title")
712 { 772 {
713 text_q = attr + "</a><p>"; 773 text_q = attr + "</a><p>";
714 } 774 }
715 qDebug("<a %s=%s>", (const char*)ent, (const char*)ref); 775 //qDebug("<a %s=%s>", (const char*)ent, (const char*)ref);
716 } 776 }
717 if (ishref) 777 if (ishref)
718 { 778 {
719 currentstyle.setColour(0,0,255); 779 currentstyle.setColour(0,0,255);
720 currentstyle.setLink(true); 780 currentstyle.setLink(true);
721 currentstyle.setData(currentid); 781 currentstyle.setData(currentid);
722 if (!text_q.isEmpty()) 782 if (!text_q.isEmpty())
723 { 783 {
@@ -742,18 +802,19 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
742 { 802 {
743 parse_paragraph(currentstyle, ch, pos); 803 parse_paragraph(currentstyle, ch, pos);
744 currentstyle.setExtraSpace(3); 804 currentstyle.setExtraSpace(3);
745 continue; 805 continue;
746 } 806 }
747 else if (ent == "div") 807 else if (ent == "div")
748 { 808 {
749 parse_paragraph(currentstyle, ch, pos); 809 parse_paragraph(currentstyle, ch, pos);
750 stylestack.push_front(currentstyle); 810 stylestack.push_front(currentstyle);
751 //indent = 0; 811 currentstyle.setExtraSpace(16);
812 //indent = 0;
752 continue; 813 continue;
753 } 814 }
754 else if (ent == "sup") 815 else if (ent == "sup")
755 { 816 {
756 currentstyle.setVOffset(-1); 817 currentstyle.setVOffset(-1);
757 } 818 }
758 else if (ent == "sup") 819 else if (ent == "sup")
759 { 820 {
@@ -795,16 +856,17 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
795 if (!stylestack.isEmpty()) 856 if (!stylestack.isEmpty())
796 { 857 {
797 stylestack.pop(); 858 stylestack.pop();
798 } 859 }
799 } 860 }
800 else if (ent == "pre") 861 else if (ent == "pre")
801 { 862 {
802 isPre = true; 863 isPre = true;
864 currentstyle.setNoJustify();
803 currentstyle.setMono(); 865 currentstyle.setMono();
804 } 866 }
805 else if (ent == "tt") 867 else if (ent == "tt")
806 { 868 {
807 currentstyle.setMono(); 869 currentstyle.setMono();
808 } 870 }
809 else if (ent == "b" || ent == "strong") 871 else if (ent == "b" || ent == "strong")
810 { 872 {
@@ -817,24 +879,27 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
817 else if (ent == "/u") 879 else if (ent == "/u")
818 { 880 {
819 currentstyle.unsetUnderline(); 881 currentstyle.unsetUnderline();
820 } 882 }
821 else if (ent == "blockquote") 883 else if (ent == "blockquote")
822 { 884 {
823 if (ch != '>') ch = skip_ws_end(); 885 if (ch != '>') ch = skip_ws_end();
824 ch = 10; 886 ch = 10;
887 currentstyle.setExtraSpace(0);
825 currentstyle.setLeftMargin(30); 888 currentstyle.setLeftMargin(30);
826 currentstyle.setRightMargin(30); 889 currentstyle.setRightMargin(30);
827 continue; 890 continue;
828 } 891 }
829 else if (ent == "br" || ent == "br/") 892 else if (ent == "br" || ent == "br/")
830 { 893 {
831 if (ch != '>') ch = skip_ws_end(); 894 if (ch != '>') ch = skip_ws_end();
832 ch = 10; 895 ch = 10;
896 currentstyle.setExtraSpace(0);
897 lastch = 0;
833 continue; 898 continue;
834 } 899 }
835 else if (ent == "mbp:pagebreak") 900 else if (ent == "mbp:pagebreak")
836 { 901 {
837 /* 902 /*
838 if (ch != '>') ch = skip_ws_end(pos); 903 if (ch != '>') ch = skip_ws_end(pos);
839 q += 10; 904 q += 10;
840 q += QChar(UEOF); 905 q += QChar(UEOF);
@@ -856,16 +921,17 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
856 else if (ent == "/center") 921 else if (ent == "/center")
857 { 922 {
858 qDebug("unsetting centre"); 923 qDebug("unsetting centre");
859 forcecentre = false; 924 forcecentre = false;
860 } 925 }
861 else if (ent == "li") 926 else if (ent == "li")
862 { 927 {
863 if (ch != '>') ch = skip_ws_end(); 928 if (ch != '>') ch = skip_ws_end();
929 lastch = 0;
864 ch = 10; 930 ch = 10;
865 if (m_listtype[indent % m_cmaxdepth] == 1) 931 if (m_listtype[indent % m_cmaxdepth] == 1)
866 { 932 {
867 q.setNum(m_ctr[indent % m_cmaxdepth]++); 933 q.setNum(m_ctr[indent % m_cmaxdepth]++);
868 } 934 }
869 else 935 else
870 { 936 {
871 q += QChar(8226); 937 q += QChar(8226);
@@ -913,54 +979,58 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
913 else if (ent == "big") 979 else if (ent == "big")
914 { 980 {
915 currentstyle.setFontSize(2); 981 currentstyle.setFontSize(2);
916 } 982 }
917 else if (ent == "/big") 983 else if (ent == "/big")
918 { 984 {
919 currentstyle.setFontSize(0); 985 currentstyle.setFontSize(0);
920 } 986 }
987 else if (ent[0] == '/' && ent[1] == 'h' && ent.length() == 3 && QString("123456789").find(ent[2]) != -1)
988 {
989 parse_paragraph(currentstyle, ch, pos);
990 currentstyle.setExtraSpace(3);
991 continue;
992 }
921 else if (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1) 993 else if (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1)
922 { 994 {
923 indent = 0; 995 indent = 0;
924 if (ent[1] == '1') 996 if (ent[1] == '1')
925 { 997 {
926 parse_paragraph(currentstyle, ch, pos); 998 parse_paragraph(currentstyle, ch, pos);
927 currentstyle.setFontSize(3); 999 currentstyle.setFontSize(3);
928 currentstyle.setExtraSpace(8); 1000 currentstyle.setExtraSpace(8);
929 currentstyle.setBold(); 1001 currentstyle.setBold();
930 // currentstyle.setExtraSpace(10); 1002 // currentstyle.setExtraSpace(10);
931 continue;
932 } 1003 }
933 else if (ent[1] == '2') 1004 else if (ent[1] == '2')
934 { 1005 {
935 parse_paragraph(currentstyle, ch, pos); 1006 parse_paragraph(currentstyle, ch, pos);
936 currentstyle.setFontSize(2); 1007 currentstyle.setFontSize(2);
937 currentstyle.setExtraSpace(6); 1008 currentstyle.setExtraSpace(6);
938 currentstyle.setBold(); 1009 currentstyle.setBold();
939 // currentstyle.setExtraSpace(10); 1010 // currentstyle.setExtraSpace(10);
940 continue;
941 } 1011 }
942 else if (ent[1] == '3') 1012 else if (ent[1] == '3')
943 { 1013 {
944 parse_paragraph(currentstyle, ch, pos); 1014 parse_paragraph(currentstyle, ch, pos);
945 currentstyle.setFontSize(1); 1015 currentstyle.setFontSize(1);
946 currentstyle.setExtraSpace(4); 1016 currentstyle.setExtraSpace(4);
947 currentstyle.setBold(); 1017 currentstyle.setBold();
948 // currentstyle.setExtraSpace(10); 1018 // currentstyle.setExtraSpace(10);
949 continue;
950 } 1019 }
951 else 1020 else
952 { 1021 {
953 parse_paragraph(currentstyle, ch, pos); 1022 parse_paragraph(currentstyle, ch, pos);
954 currentstyle.setExtraSpace(4); 1023 currentstyle.setExtraSpace(4);
955 currentstyle.setBold(); 1024 currentstyle.setBold();
956 // currentstyle.setExtraSpace(10); 1025 // currentstyle.setExtraSpace(10);
957 continue;
958 } 1026 }
1027 ch = 10;
1028 continue;
959 } 1029 }
960 1030
961 1031
962 else if (ent == "/a") 1032 else if (ent == "/a")
963 { 1033 {
964 currentstyle.setColour(0,0,0); 1034 currentstyle.setColour(0,0,0);
965 currentstyle.setLink(false); 1035 currentstyle.setLink(false);
966 } 1036 }
@@ -1042,100 +1112,142 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
1042 // ch = 10; 1112 // ch = 10;
1043 continue; 1113 continue;
1044 } 1114 }
1045 */ 1115 */
1046 else if (ent[0] == '/' && ent.length() == 3 && ent[1] == 'h' && QString("123456789").find(ent[2]) != -1) 1116 else if (ent[0] == '/' && ent.length() == 3 && ent[1] == 'h' && QString("123456789").find(ent[2]) != -1)
1047 { 1117 {
1048 currentstyle.unset(); 1118 currentstyle.unset();
1049 if (ch != '>') ch = skip_ws_end(); 1119 if (ch != '>') ch = skip_ws_end();
1050 ch = 10; 1120 //ch = 10;
1051 continue; 1121 //continue;
1052 } 1122 }
1053
1054
1055
1056 else if (ent == "table" || ent == "/table") 1123 else if (ent == "table" || ent == "/table")
1057 { 1124 {
1058 currentstyle.unset(); 1125 currentstyle.unset();
1059 ignorespace = (ent == "table"); 1126 ignorespace = (ent == "table");
1127 if (ent == "table")
1128 {
1129 if (tablenesteddepth++ == 0) currentstyle.setTable(pos);
1130 }
1131 else
1132 {
1133 if (--tablenesteddepth <= 0)
1134 {
1135 tablenesteddepth = 0;
1136 currentstyle.setTable(0xffffffff);
1137 }
1138 }
1060 if (ch == ' ') ch = skip_ws(); 1139 if (ch == ' ') ch = skip_ws();
1061 while (ch != '>' && ch != UEOF) 1140 while (ch != '>' && ch != UEOF)
1062 { 1141 {
1063 QString ent = getname(ch, " =>").lower(); 1142 QString ent = getname(ch, " =>").lower();
1064 QString attr = getattr(ch); 1143 QString attr = getattr(ch);
1065 qDebug("<table>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 1144 qDebug("<table>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
1066 } 1145 }
1067 if (ch != '>') ch = skip_ws_end(); 1146 if (ch != '>') ch = skip_ws_end();
1068 1147
1148 currentstyle.setLeftMargin(6*tablenesteddepth);
1149
1150
1151 lastch = 0; // Anything but 10
1069 ch = 10; 1152 ch = 10;
1070 q += '-'; 1153 q += '-';
1071 q += QChar(parent->getwidth()); 1154 q += QChar(parent->getwidth());
1072 q += 2; 1155 q += 3;
1073 q += '\0'; 1156 q += '\0';
1074 q += '\0'; 1157 q += '\0';
1075 q += '\0'; 1158 q += '\0';
1076 continue; 1159 continue;
1077 } 1160 }
1078 else if (ent == "hr") 1161 else if (ent == "hr")
1079 { 1162 {
1163 //bool isPageBreak = false;
1080 if (ch == ' ') ch = skip_ws(); 1164 if (ch == ' ') ch = skip_ws();
1081 // if (stylestack.isEmpty())
1082 // {
1083 currentstyle.unset();
1084 // }
1085 /*
1086 else
1087 {
1088 qDebug("Using stack style");
1089 currentstyle = stylestack.first();
1090 }
1091 */
1092 unsigned char red = 0, green = 0, blue = 0; 1165 unsigned char red = 0, green = 0, blue = 0;
1093 while (ch != '>' && ch != UEOF) 1166 while (ch != '>' && ch != UEOF)
1094 { 1167 {
1095 QString ent = getname(ch, " =>").lower(); 1168 QString ent = getname(ch, " =>").lower();
1096 QString attr = getattr(ch); 1169 QString attr = getattr(ch);
1097 if (ent == "color") 1170 if (ent == "color")
1098 { 1171 {
1099 parse_color(attr, red, green, blue); 1172 parse_color(attr, red, green, blue);
1100 } 1173 }
1174 /*
1175 if (ent == "size")
1176 {
1177 if (attr == "0")
1178 {
1179 isPageBreak = true;
1180 }
1181 }
1182 */
1101 qDebug("<hr>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 1183 qDebug("<hr>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
1102 } 1184 }
1103 if (ch != '>') ch = skip_ws_end(); 1185 if (ch != '>') ch = skip_ws_end();
1104 ch = 10; 1186 /*
1105 q += '-'; 1187 if (isPageBreak)
1106 q += QChar(parent->getwidth()); 1188 {
1107 q += 3; 1189 ch = UEOF;
1108 q += red; 1190 }
1109 q += green; 1191 else
1110 q += blue; 1192 {
1193 */
1194 // if (stylestack.isEmpty())
1195 // {
1196 currentstyle.unset();
1197 // }
1198 /*
1199 else
1200 {
1201 qDebug("Using stack style");
1202 currentstyle = stylestack.first();
1203 }
1204 */
1205 lastch = 0; //Anything but 10 or ' '
1206 ch = 10;
1207 q += '-';
1208 q += QChar(parent->getwidth());
1209 q += 3;
1210 q += red;
1211 q += green;
1212 q += blue;
1213
1111 continue; 1214 continue;
1112 } 1215 }
1113 1216
1114 1217
1115 1218
1116 else if (ent == "img") 1219 else if (ent == "img")
1117 { 1220 {
1118 if (ch == ' ') ch = skip_ws(); 1221 if (ch == ' ') ch = skip_ws();
1119 while (ch != '>' && ch != UEOF) 1222 while (ch != '>' && ch != UEOF)
1120 { 1223 {
1121 QString ent = getname(ch, " =>").lower(); 1224 QString ent = getname(ch, " =>").lower();
1122 QString attr = getattr(ch); 1225 QString attr = getattr(ch);
1123 qDebug("<img>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 1226 qDebug("<img>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
1124 if (ent == "src") 1227 if (ent == "src")
1125 { 1228 {
1229 /*
1126 if (m_bchm) 1230 if (m_bchm)
1127 { 1231 {
1128 QImage* img = parent->getPicture(attr); 1232 QImage* img = parent->getPicture(attr);
1129 if (img != NULL) 1233 if (img != NULL)
1130 { 1234 {
1131 currentstyle.setPicture(true, img); 1235 currentstyle.setPicture(true, img);
1132 } 1236 }
1133 } 1237 }
1238 */
1239
1240
1241 QImage* img = parent->getPicture(attr);
1242 if (img != NULL)
1243 {
1244 currentstyle.setPicture(true, img);
1245 }
1134 else 1246 else
1135 { 1247 {
1136 QFileInfo f(currentfile); 1248 QFileInfo f(currentfile);
1137 QFileInfo f1(f.dir(true), attr); 1249 QFileInfo f1(f.dir(true), attr);
1138 QPixmap pm; 1250 QPixmap pm;
1139 if (pm.load(f1.absFilePath())) 1251 if (pm.load(f1.absFilePath()))
1140 { 1252 {
1141 QImage* img = new QImage(pm.convertToImage()); 1253 QImage* img = new QImage(pm.convertToImage());
@@ -1167,16 +1279,24 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
1167 { 1279 {
1168 QString nd("/"); 1280 QString nd("/");
1169 skipblock(nd+ent); 1281 skipblock(nd+ent);
1170 } 1282 }
1171 else if (ent == "metadata") 1283 else if (ent == "metadata")
1172 { 1284 {
1173 // skipblock("/metadata"); 1285 // skipblock("/metadata");
1174 } 1286 }
1287 else if (ent == "title")
1288 {
1289 skipblock("/title");
1290 }
1291 else if (ent == "head")
1292 {
1293 skipblock("/head");
1294 }
1175 /* 1295 /*
1176 else if (ent == "metadata") 1296 else if (ent == "metadata")
1177 { 1297 {
1178 currentstyle.setFontSize(-2); 1298 currentstyle.setFontSize(-2);
1179 } 1299 }
1180 else if (ent == "/metadata") 1300 else if (ent == "/metadata")
1181 { 1301 {
1182 currentstyle.unset(); 1302 currentstyle.unset();
@@ -1186,17 +1306,20 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
1186 */ 1306 */
1187 else 1307 else
1188 { 1308 {
1189 if (ent[0] != '/') 1309 if (ent[0] != '/')
1190 qDebug("Not handling:%s", (const char*)ent); 1310 qDebug("Not handling:%s", (const char*)ent);
1191 } 1311 }
1192 1312
1193 if (ch != '>') ch = skip_ws_end(); 1313 if (ch != '>') ch = skip_ws_end();
1194 mygetch(ch, dummy, npos); 1314 if (ent[0] == '/')
1315 mygetch(ch, dummy, pos);
1316 else
1317 mygetch(ch, dummy, npos);
1195 } 1318 }
1196 if (ch == '&') 1319 if (ch == '&')
1197 { 1320 {
1198 mygetch(ch, dummy, npos); 1321 mygetch(ch, dummy, npos);
1199 if (ch == '#') 1322 if (ch == '#')
1200 { 1323 {
1201 int id = 0; 1324 int id = 0;
1202 mygetch(ch, dummy, npos); 1325 mygetch(ch, dummy, npos);
@@ -1229,20 +1352,63 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
1229 } 1352 }
1230 else 1353 else
1231 { 1354 {
1232 ch = '.'; 1355 ch = '.';
1233 } 1356 }
1234 } 1357 }
1235 } 1358 }
1236 // sty = (dummy == ucFontBase) ? currentstyle : dummy; 1359 // sty = (dummy == ucFontBase) ? currentstyle : dummy;
1360 if (lastch == 10 && ch == 10 && sty.getExtraSpace() > currentstyle.getExtraSpace())
1361 {
1362 currentstyle.setExtraSpace(sty.getExtraSpace());
1363 }
1237 sty = currentstyle; 1364 sty = currentstyle;
1238 } 1365 }
1239 while (!isPre && (lastch == ' ' || lastch == 10 || ignorespace) && ch == ' '); 1366 while (!isPre && (((lastch == ' ' || lastch == 10 || ignorespace) && ch == ' ') || ((ch == 10) && (lastch == 10))));
1240 // lastch = ch; 1367 // lastch = ch;
1241 lastch = ch; 1368 lastch = ch;
1242 return; 1369 return;
1243} 1370}
1244 1371
1372QString striphtml::getTableAsHtml(unsigned long loc)
1373{
1374 qDebug("striphtml::getTableAsHtml");
1375 QString ret;
1376 tchar ch(0);
1377 CStyle sty;
1378 unsigned long pos;
1379 locate(loc);
1380 int endpos(0);
1381 QString endmarker("</table>");
1382 QString startmarker("<table");
1383 int startpos(0);
1384 int depth(0);
1385 while (ch != UEOF)
1386 {
1387 parent->getch(ch, sty, pos);
1388 QChar qc(ch);
1389 ret += qc;
1390 if (qc.lower() == endmarker[endpos])
1391 {
1392 if ((++endpos >= endmarker.length()) && (--depth <= 0)) break;
1393 }
1394 else
1395 {
1396 endpos = 0;
1397 }
1398 if (qc.lower() == startmarker[startpos])
1399 {
1400 if (++startpos >= startmarker.length()) ++depth;
1401 }
1402 else
1403 {
1404 startpos = 0;
1405 }
1406 }
1407 return ret;
1408}
1409
1410
1245extern "C" 1411extern "C"
1246{ 1412{
1247 CFilter* newfilter(const QString& s) { return new striphtml(s); } 1413 CFilter* newfilter(const QString& s) { return new striphtml(s); }
1248} 1414}