author | pohly <pohly> | 2005-05-05 14:39:33 (UTC) |
---|---|---|
committer | pohly <pohly> | 2005-05-05 14:39:33 (UTC) |
commit | 39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91 (patch) (side-by-side diff) | |
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) (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 @@ -10,3 +10,2 @@ #include "hrule.h" -#include "util.h" @@ -92,3 +91,3 @@ void striphtml::skipblock(const QString& _ent) -void striphtml::locate(unsigned int n) +void striphtml::reset() { @@ -96,7 +95,15 @@ void striphtml::locate(unsigned int n) text_q = ""; + q = ""; + tablenesteddepth = 0; forcecentre = false; ignorespace = false; + indent = 0; while (!stylestack.isEmpty()) stylestack.pop(); currentstyle.unset(); +} + +void striphtml::locate(unsigned int n) +{ qDebug("striphtml:locating:%u", n); + reset(); parent->locate(n); @@ -235,2 +242,9 @@ bool striphtml::findanchor(const QString& _info) // QProgressBar dlg(0); + if (parent->findanchor(_info)) + { + reset(); + return true; + } + qDebug("Using html find"); + parent->locate(parent->startSection()); #if defined(USEQPE) || defined(_WINDOWS) @@ -297,3 +311,3 @@ bool striphtml::findanchor(const QString& _info) -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) +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) { @@ -313,3 +327,13 @@ void striphtml::initentmap() entmap = new QMap<QString, tchar>; - QString fname(QTReaderUtil::getPluginPath("data")); +#ifdef USEQPE +#ifdef OPIE + QString fname(getenv("OPIEDIR")); +#else + QString fname(getenv("QTDIR")); +#endif + fname += "/plugins/reader/data"; +#else + QString fname(getenv("READERDIR")); + fname += "/data"; +#endif QFileInfo fi; @@ -414,2 +438,8 @@ QString striphtml::getattr(tchar& ch) } + else if (ch == '\'') + { + mygetch(ch, sty, pos); + ref = getname(ch, "\'"); + ch = skip_ws(); + } else @@ -480,2 +510,7 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& { + if (parent->findanchor(name)) + { + reset(); + return eLink; + } fpit = href2filepos->find(name); @@ -490,3 +525,2 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& qDebug("Do a search for:%s", (const char*)name); - parent->locate(0); findanchor(name); @@ -500,3 +534,3 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& { - w = "/"+file; + w = file; nm = name; @@ -566,3 +600,27 @@ void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) { +#ifdef REMOVE_LF_BEFORE_ENDTAG + parent->getch(ch, sty, pos); + if (ch == '<') + { + parent->getch(ch, sty, pos); + if (ch == '/') + { + ch = '<'; + text_q += '/'; + } + else + { + text_q += '<'; + text_q += ch; + ch = ' '; + } + } + else + { + text_q += ch; + ch = ' '; + } +#else ch = ' '; +#endif } @@ -586,3 +644,2 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p { - qDebug("Using stack style"); currentstyle = stylestack.first(); @@ -609,2 +666,6 @@ void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long p } + if (attr == "justify") + { + currentstyle.setFullJustify(); + } } @@ -656,2 +717,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) sty = currentstyle; + lastch = ch; return; @@ -663,3 +725,2 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) mygetch(ch, dummy, pos); - // if (ch == 10 && !isPre) ch = ' '; while (ch == '<' && ch != UEOF) @@ -667,3 +728,2 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) ch = skip_ws(); - QString ent = getname(ch, " >").lower(); @@ -683,3 +743,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) QString attr = getattr(ch); - qDebug("<A>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); + //qDebug("<A>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); if (ent == "name") @@ -714,3 +774,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) } - qDebug("<a %s=%s>", (const char*)ent, (const char*)ref); + //qDebug("<a %s=%s>", (const char*)ent, (const char*)ref); } @@ -750,2 +810,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) stylestack.push_front(currentstyle); + currentstyle.setExtraSpace(16); //indent = 0; @@ -802,2 +863,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) isPre = true; + currentstyle.setNoJustify(); currentstyle.setMono(); @@ -824,2 +886,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) ch = 10; + currentstyle.setExtraSpace(0); currentstyle.setLeftMargin(30); @@ -832,2 +895,4 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) ch = 10; + currentstyle.setExtraSpace(0); + lastch = 0; continue; @@ -863,2 +928,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) if (ch != '>') ch = skip_ws_end(); + lastch = 0; ch = 10; @@ -920,2 +986,8 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) } + else if (ent[0] == '/' && ent[1] == 'h' && ent.length() == 3 && QString("123456789").find(ent[2]) != -1) + { + parse_paragraph(currentstyle, ch, pos); + currentstyle.setExtraSpace(3); + continue; + } else if (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1) @@ -930,3 +1002,2 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) // currentstyle.setExtraSpace(10); - continue; } @@ -939,3 +1010,2 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) // currentstyle.setExtraSpace(10); - continue; } @@ -948,3 +1018,2 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) // currentstyle.setExtraSpace(10); - continue; } @@ -956,4 +1025,5 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) // currentstyle.setExtraSpace(10); - continue; } + ch = 10; + continue; } @@ -1049,8 +1119,5 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) if (ch != '>') ch = skip_ws_end(); - ch = 10; - continue; + //ch = 10; + //continue; } - - - else if (ent == "table" || ent == "/table") @@ -1059,2 +1126,14 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) ignorespace = (ent == "table"); + if (ent == "table") + { + if (tablenesteddepth++ == 0) currentstyle.setTable(pos); + } + else + { + if (--tablenesteddepth <= 0) + { + tablenesteddepth = 0; + currentstyle.setTable(0xffffffff); + } + } if (ch == ' ') ch = skip_ws(); @@ -1068,2 +1147,6 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) + currentstyle.setLeftMargin(6*tablenesteddepth); + + + lastch = 0; // Anything but 10 ch = 10; @@ -1071,3 +1154,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) q += QChar(parent->getwidth()); - q += 2; + q += 3; q += '\0'; @@ -1079,14 +1162,4 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) { + //bool isPageBreak = false; if (ch == ' ') ch = skip_ws(); - // if (stylestack.isEmpty()) - // { - currentstyle.unset(); - // } - /* - else - { - qDebug("Using stack style"); - currentstyle = stylestack.first(); - } - */ unsigned char red = 0, green = 0, blue = 0; @@ -1100,2 +1173,11 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) } + /* + if (ent == "size") + { + if (attr == "0") + { + isPageBreak = true; + } + } + */ qDebug("<hr>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); @@ -1103,2 +1185,22 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) if (ch != '>') ch = skip_ws_end(); + /* + if (isPageBreak) + { + ch = UEOF; + } + else + { + */ + // if (stylestack.isEmpty()) + // { + currentstyle.unset(); + // } + /* + else + { + qDebug("Using stack style"); + currentstyle = stylestack.first(); + } + */ + lastch = 0; //Anything but 10 or ' ' ch = 10; @@ -1110,2 +1212,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) q += blue; + continue; @@ -1125,2 +1228,3 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) { + /* if (m_bchm) @@ -1133,2 +1237,10 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) } + */ + + + QImage* img = parent->getPicture(attr); + if (img != NULL) + { + currentstyle.setPicture(true, img); + } else @@ -1174,2 +1286,10 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) } + else if (ent == "title") + { + skipblock("/title"); + } + else if (ent == "head") + { + skipblock("/head"); + } /* @@ -1193,2 +1313,5 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) if (ch != '>') ch = skip_ws_end(); + if (ent[0] == '/') + mygetch(ch, dummy, pos); + else mygetch(ch, dummy, npos); @@ -1236,5 +1359,9 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) // sty = (dummy == ucFontBase) ? currentstyle : dummy; + if (lastch == 10 && ch == 10 && sty.getExtraSpace() > currentstyle.getExtraSpace()) + { + currentstyle.setExtraSpace(sty.getExtraSpace()); + } sty = currentstyle; } - while (!isPre && (lastch == ' ' || lastch == 10 || ignorespace) && ch == ' '); + while (!isPre && (((lastch == ' ' || lastch == 10 || ignorespace) && ch == ' ') || ((ch == 10) && (lastch == 10)))); // lastch = ch; @@ -1244,2 +1371,41 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) +QString striphtml::getTableAsHtml(unsigned long loc) +{ + qDebug("striphtml::getTableAsHtml"); + QString ret; + tchar ch(0); + CStyle sty; + unsigned long pos; + locate(loc); + int endpos(0); + QString endmarker("</table>"); + QString startmarker("<table"); + int startpos(0); + int depth(0); + while (ch != UEOF) + { + parent->getch(ch, sty, pos); + QChar qc(ch); + ret += qc; + if (qc.lower() == endmarker[endpos]) + { + if ((++endpos >= endmarker.length()) && (--depth <= 0)) break; + } + else + { + endpos = 0; + } + if (qc.lower() == startmarker[startpos]) + { + if (++startpos >= startmarker.length()) ++depth; + } + else + { + startpos = 0; + } + } + return ret; +} + + extern "C" |