author | pohly <pohly> | 2005-05-05 14:39:33 (UTC) |
---|---|---|
committer | pohly <pohly> | 2005-05-05 14:39:33 (UTC) |
commit | 39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91 (patch) (unidiff) | |
tree | 96e66fdc18dca4d4ab8611133e072f57dea224b9 /noncore/apps/opie-reader/striphtml.cpp | |
parent | 279fc4fd1986074acbadd3a8e86fcf3968a8dd5c (diff) | |
download | opie-39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91.zip opie-39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91.tar.gz opie-39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91.tar.bz2 |
new opie-reader sources with support for ArriereGo, Reb input and flite output plugins
Diffstat (limited to 'noncore/apps/opie-reader/striphtml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/striphtml.cpp | 252 |
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 | |||
@@ -7,9 +7,8 @@ | |||
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> |
@@ -89,17 +88,25 @@ void striphtml::skipblock(const QString& _ent) | |||
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 | ||
93 | void striphtml::locate(unsigned int n) | 92 | void 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 | |||
105 | void 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 | ||
105 | int striphtml::getpara(CBuffer& buff, unsigned long& startpos) | 112 | int striphtml::getpara(CBuffer& buff, unsigned long& startpos) |
@@ -232,8 +239,15 @@ QString striphtml::dehtml(const QString& _info) | |||
232 | bool striphtml::findanchor(const QString& _info) | 239 | bool 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 | { |
@@ -294,9 +308,9 @@ bool striphtml::findanchor(const QString& _info) | |||
294 | } | 308 | } |
295 | return ret; | 309 | return ret; |
296 | } | 310 | } |
297 | 311 | ||
298 | striphtml::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) | 312 | striphtml::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 | } |
@@ -310,9 +324,19 @@ striphtml::~striphtml() | |||
310 | 324 | ||
311 | void striphtml::initentmap() | 325 | void 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 | { |
@@ -411,8 +435,14 @@ QString striphtml::getattr(tchar& ch) | |||
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(); |
@@ -477,8 +507,13 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& | |||
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); |
@@ -487,9 +522,8 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& | |||
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 | } |
@@ -497,9 +531,9 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& | |||
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 |
@@ -563,9 +597,33 @@ void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | ||
571 | void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos) | 629 | void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos) |
@@ -583,9 +641,8 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p | |||
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 | { |
@@ -606,8 +663,12 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p | |||
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; |
@@ -653,20 +714,19 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | ||
@@ -680,9 +740,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | } |
@@ -711,9 +771,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); |
@@ -746,10 +806,11 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -799,8 +860,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -821,16 +883,19 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -860,8 +925,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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]++); |
@@ -917,8 +983,14 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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') |
@@ -927,36 +999,34 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& 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") |
@@ -1046,18 +1116,27 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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(); |
@@ -1065,31 +1144,25 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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(); |
@@ -1097,18 +1170,48 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | ||
@@ -1122,16 +1225,25 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); |
@@ -1171,8 +1283,16 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); |
@@ -1190,9 +1310,12 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); |
@@ -1233,16 +1356,59 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | ||
1372 | QString 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 | |||
1245 | extern "C" | 1411 | extern "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 | } |