Diffstat (limited to 'noncore/apps/opie-reader/striphtml.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/striphtml.cpp | 232 |
1 files changed, 199 insertions, 33 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 | |||
@@ -8,7 +8,6 @@ | |||
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> |
@@ -90,15 +89,23 @@ void striphtml::skipblock(const QString& _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 | ||
@@ -233,6 +240,13 @@ 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++) |
@@ -295,7 +309,7 @@ bool striphtml::findanchor(const QString& _info) | |||
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>; |
@@ -311,7 +325,17 @@ striphtml::~striphtml() | |||
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()) |
@@ -412,6 +436,12 @@ QString striphtml::getattr(tchar& ch) | |||
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, " >"); |
@@ -478,6 +508,11 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& | |||
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 | { |
@@ -488,7 +523,6 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& | |||
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 | } |
@@ -498,7 +532,7 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& | |||
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 | } |
@@ -564,7 +598,31 @@ void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | ||
@@ -584,7 +642,6 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p | |||
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) |
@@ -607,6 +664,10 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p | |||
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 | { |
@@ -654,6 +715,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 |
@@ -661,11 +723,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); |
@@ -681,7 +741,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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; |
@@ -712,7 +772,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -748,6 +808,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
748 | { | 808 | { |
749 | parse_paragraph(currentstyle, ch, pos); | 809 | parse_paragraph(currentstyle, ch, pos); |
750 | stylestack.push_front(currentstyle); | 810 | stylestack.push_front(currentstyle); |
811 | currentstyle.setExtraSpace(16); | ||
751 | //indent = 0; | 812 | //indent = 0; |
752 | continue; | 813 | continue; |
753 | } | 814 | } |
@@ -800,6 +861,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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") |
@@ -822,6 +884,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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; |
@@ -830,6 +893,8 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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") |
@@ -861,6 +926,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -918,6 +984,12 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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; |
@@ -928,7 +1000,6 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -937,7 +1008,6 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -946,7 +1016,6 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -954,8 +1023,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& 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 | ||
@@ -1047,16 +1117,25 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -1066,10 +1145,14 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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'; |
@@ -1077,18 +1160,8 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -1098,9 +1171,38 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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(); |
1186 | /* | ||
1187 | if (isPageBreak) | ||
1188 | { | ||
1189 | ch = UEOF; | ||
1190 | } | ||
1191 | else | ||
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 ' ' | ||
1104 | ch = 10; | 1206 | ch = 10; |
1105 | q += '-'; | 1207 | q += '-'; |
1106 | q += QChar(parent->getwidth()); | 1208 | q += QChar(parent->getwidth()); |
@@ -1108,6 +1210,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
1108 | q += red; | 1210 | q += red; |
1109 | q += green; | 1211 | q += green; |
1110 | q += blue; | 1212 | q += blue; |
1213 | |||
1111 | continue; | 1214 | continue; |
1112 | } | 1215 | } |
1113 | 1216 | ||
@@ -1123,6 +1226,7 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); |
@@ -1131,6 +1235,14 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); |
@@ -1172,6 +1284,14 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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 | { |
@@ -1191,6 +1311,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
1191 | } | 1311 | } |
1192 | 1312 | ||
1193 | if (ch != '>') ch = skip_ws_end(); | 1313 | if (ch != '>') ch = skip_ws_end(); |
1314 | if (ent[0] == '/') | ||
1315 | mygetch(ch, dummy, pos); | ||
1316 | else | ||
1194 | mygetch(ch, dummy, npos); | 1317 | mygetch(ch, dummy, npos); |
1195 | } | 1318 | } |
1196 | if (ch == '&') | 1319 | if (ch == '&') |
@@ -1234,14 +1357,57 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
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); } |