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 | |||
@@ -1,27 +1,26 @@ | |||
1 | #include <qmap.h> | 1 | #include <qmap.h> |
2 | #include <qfileinfo.h> | 2 | #include <qfileinfo.h> |
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 | ||
19 | static unsigned char h2i(unsigned char c) | 18 | static unsigned char h2i(unsigned char c) |
20 | { | 19 | { |
21 | unsigned char ret = 0; | 20 | unsigned char ret = 0; |
22 | if ('0' <= c && c <= '9') | 21 | if ('0' <= c && c <= '9') |
23 | { | 22 | { |
24 | ret = c - '0'; | 23 | ret = c - '0'; |
25 | } | 24 | } |
26 | else if ('a' <= c && c <= 'f') | 25 | else if ('a' <= c && c <= 'f') |
27 | { | 26 | { |
@@ -77,41 +76,49 @@ void striphtml::skipblock(const QString& _ent) | |||
77 | QString ent; | 76 | QString ent; |
78 | unsigned long pos; | 77 | unsigned long pos; |
79 | do | 78 | do |
80 | { | 79 | { |
81 | while (ch != '<' && ch != UEOF) | 80 | while (ch != '<' && ch != UEOF) |
82 | { | 81 | { |
83 | mygetch(ch, dummy, pos); | 82 | mygetch(ch, dummy, pos); |
84 | } | 83 | } |
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 | ||
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) |
106 | { | 113 | { |
107 | tchar ch; | 114 | tchar ch; |
108 | CStyle sty; | 115 | CStyle sty; |
109 | unsigned long pos; | 116 | unsigned long pos; |
110 | int i = 0; | 117 | int i = 0; |
111 | parent->getch(ch, sty, startpos); | 118 | parent->getch(ch, sty, startpos); |
112 | pos = startpos; | 119 | pos = startpos; |
113 | while (1) | 120 | while (1) |
114 | { | 121 | { |
115 | if (ch == 10 && !isPre) | 122 | if (ch == 10 && !isPre) |
116 | { | 123 | { |
117 | ch = ' '; | 124 | ch = ' '; |
@@ -220,32 +227,39 @@ QString striphtml::dehtml(const QString& _info) | |||
220 | } | 227 | } |
221 | else if ('A' <= ch1 && ch1 <= 'F') | 228 | else if ('A' <= ch1 && ch1 <= 'F') |
222 | { | 229 | { |
223 | ch += ch1 - 'A' + 10; | 230 | ch += ch1 - 'A' + 10; |
224 | } | 231 | } |
225 | } | 232 | } |
226 | } | 233 | } |
227 | info += ch; | 234 | info += ch; |
228 | } | 235 | } |
229 | return info; | 236 | return info; |
230 | } | 237 | } |
231 | 238 | ||
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 | { |
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 += '\\'; |
244 | } | 258 | } |
245 | info += ch; | 259 | info += ch; |
246 | } | 260 | } |
247 | #else | 261 | #else |
248 | QString info = QRegExp::escape(_info); | 262 | QString info = QRegExp::escape(_info); |
249 | #endif | 263 | #endif |
250 | qDebug("Adjusted searchstring:%s", (const char*)info); | 264 | qDebug("Adjusted searchstring:%s", (const char*)info); |
251 | QString sname("<[Aa][^>]*[ \t]+[Nn][Aa][Mm][Ee][ \t]*=[ \t]*\"?"); | 265 | QString sname("<[Aa][^>]*[ \t]+[Nn][Aa][Mm][Ee][ \t]*=[ \t]*\"?"); |
@@ -282,49 +296,59 @@ bool striphtml::findanchor(const QString& _info) | |||
282 | return false; | 296 | return false; |
283 | } | 297 | } |
284 | } | 298 | } |
285 | locate(pos); | 299 | locate(pos); |
286 | qDebug("Found"); | 300 | qDebug("Found"); |
287 | ret = true; | 301 | ret = true; |
288 | } | 302 | } |
289 | else | 303 | else |
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 | ||
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 | } |
303 | 317 | ||
304 | striphtml::~striphtml() | 318 | striphtml::~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 | ||
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 | { |
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)) |
323 | { | 347 | { |
324 | QTextStream t(&fl); | 348 | QTextStream t(&fl); |
325 | QString key, value; | 349 | QString key, value; |
326 | while (!t.eof()) | 350 | while (!t.eof()) |
327 | { | 351 | { |
328 | QString data = t.readLine(); | 352 | QString data = t.readLine(); |
329 | int colon = data.find(':'); | 353 | int colon = data.find(':'); |
330 | if (colon > 0) | 354 | if (colon > 0) |
@@ -399,32 +423,38 @@ QString striphtml::getname(tchar& ch, const QString& nd) | |||
399 | 423 | ||
400 | QString striphtml::getattr(tchar& ch) | 424 | QString striphtml::getattr(tchar& ch) |
401 | { | 425 | { |
402 | QString ref; | 426 | QString ref; |
403 | CStyle sty; | 427 | CStyle sty; |
404 | unsigned long pos; | 428 | unsigned long pos; |
405 | if (ch == ' ') ch = skip_ws(); | 429 | if (ch == ' ') ch = skip_ws(); |
406 | if (ch == '=') | 430 | if (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 | } |
423 | 453 | ||
424 | linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& nm) | 454 | linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& nm) |
425 | { | 455 | { |
426 | #if defined(USEQPE) || defined(_WINDOWS) | 456 | #if defined(USEQPE) || defined(_WINDOWS) |
427 | QMap<unsigned long, QString>::Iterator hrefit = id2href->find(n); | 457 | QMap<unsigned long, QString>::Iterator hrefit = id2href->find(n); |
428 | #else | 458 | #else |
429 | QMap<unsigned long, QString>::iterator hrefit = id2href->find(n); | 459 | QMap<unsigned long, QString>::iterator hrefit = id2href->find(n); |
430 | #endif | 460 | #endif |
@@ -465,53 +495,57 @@ linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& | |||
465 | if (colon >= 0) | 495 | if (colon >= 0) |
466 | { | 496 | { |
467 | file = dehtml(href.left(colon)); | 497 | file = dehtml(href.left(colon)); |
468 | name = dehtml(href.right(href.length()-colon-1)); | 498 | name = dehtml(href.right(href.length()-colon-1)); |
469 | } | 499 | } |
470 | else | 500 | else |
471 | { | 501 | { |
472 | file = dehtml(href); | 502 | file = dehtml(href); |
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()) |
510 | { | 544 | { |
511 | w = f1.absFilePath(); | 545 | w = f1.absFilePath(); |
512 | nm = name; | 546 | nm = name; |
513 | } | 547 | } |
514 | else | 548 | else |
515 | { | 549 | { |
516 | w = file; | 550 | w = file; |
517 | } | 551 | } |
@@ -551,75 +585,102 @@ void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
551 | text_q = text_q.right(text_q.length()-1); | 585 | text_q = text_q.right(text_q.length()-1); |
552 | } | 586 | } |
553 | else | 587 | else |
554 | { | 588 | { |
555 | parent->getch(ch, sty, pos); | 589 | parent->getch(ch, sty, pos); |
556 | if (ch == '<') | 590 | if (ch == '<') |
557 | { | 591 | { |
558 | m_inblock = true; | 592 | m_inblock = true; |
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 | ||
571 | void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos) | 629 | void 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) |
576 | { | 634 | { |
577 | count++; | 635 | count++; |
578 | } | 636 | } |
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) |
596 | { | 653 | { |
597 | QString ent = getname(ch, " =>").lower(); | 654 | QString ent = getname(ch, " =>").lower(); |
598 | QString attr = getattr(ch).lower(); | 655 | QString attr = getattr(ch).lower(); |
599 | //qDebug("(Paragraph)Entity:%s Attr:%s", (const char*)ent, (const char*)attr); | 656 | //qDebug("(Paragraph)Entity:%s Attr:%s", (const char*)ent, (const char*)attr); |
600 | if (ent == "align") | 657 | if (ent == "align") |
601 | { | 658 | { |
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); |
618 | unsigned char r,g,b; | 679 | unsigned char r,g,b; |
619 | parse_color(attr, r, g, b); | 680 | parse_color(attr, r, g, b); |
620 | currentstyle.setPaper(r, g, b); | 681 | currentstyle.setPaper(r, g, b); |
621 | } | 682 | } |
622 | if (ent == "color") | 683 | if (ent == "color") |
623 | { | 684 | { |
624 | qDebug("Got foreground colour:%s", (const char*)attr); | 685 | qDebug("Got foreground colour:%s", (const char*)attr); |
625 | unsigned char r,g,b; | 686 | unsigned char r,g,b; |
@@ -641,91 +702,90 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
641 | { | 702 | { |
642 | tchar w = q[1].unicode(); | 703 | tchar w = q[1].unicode(); |
643 | tchar h = q[2].unicode(); | 704 | tchar h = q[2].unicode(); |
644 | unsigned char r = q[3].unicode(); | 705 | unsigned char r = q[3].unicode(); |
645 | unsigned char g = q[4].unicode(); | 706 | unsigned char g = q[4].unicode(); |
646 | unsigned char b = q[5].unicode(); | 707 | unsigned char b = q[5].unicode(); |
647 | ch = '#'; | 708 | ch = '#'; |
648 | //qDebug("html:hrule<%u, %u>", w, h); | 709 | //qDebug("html:hrule<%u, %u>", w, h); |
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('\''); |
693 | ref = attr.mid(st+1, nd-st-1); | 753 | ref = attr.mid(st+1, nd-st-1); |
694 | ishref = true; | 754 | ishref = true; |
695 | qDebug("Onclick:%s", (const char*)ref); | 755 | qDebug("Onclick:%s", (const char*)ref); |
696 | } | 756 | } |
697 | if (ent == "href") | 757 | if (ent == "href") |
698 | { | 758 | { |
699 | ishref = true; | 759 | ishref = true; |
700 | ref = attr; | 760 | ref = attr; |
701 | } | 761 | } |
702 | if (ent == "filepos") | 762 | if (ent == "filepos") |
703 | { | 763 | { |
704 | filepos = attr.toUInt(&fileposfound); | 764 | filepos = attr.toUInt(&fileposfound); |
705 | if (ref.isEmpty()) | 765 | if (ref.isEmpty()) |
706 | { | 766 | { |
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 | { |
724 | currentstyle.setBold(); | 784 | currentstyle.setBold(); |
725 | currentstyle.setCentreJustify(); | 785 | currentstyle.setCentreJustify(); |
726 | } | 786 | } |
727 | (*id2href)[currentid] = ref; | 787 | (*id2href)[currentid] = ref; |
728 | currentid++; | 788 | currentid++; |
729 | 789 | ||
730 | 790 | ||
731 | if (fileposfound) | 791 | if (fileposfound) |
@@ -735,32 +795,33 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
735 | } | 795 | } |
736 | if (!name.isEmpty()) | 796 | if (!name.isEmpty()) |
737 | { | 797 | { |
738 | (*href2filepos)[name] = pos; | 798 | (*href2filepos)[name] = pos; |
739 | } | 799 | } |
740 | } | 800 | } |
741 | else if (ent == "p") | 801 | else if (ent == "p") |
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); |
811 | currentstyle.setExtraSpace(16); | ||
751 | //indent = 0; | 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 | { |
760 | currentstyle.setVOffset(1); | 821 | currentstyle.setVOffset(1); |
761 | } | 822 | } |
762 | else if (ent == "/sup" || ent == "/sub") | 823 | else if (ent == "/sup" || ent == "/sub") |
763 | { | 824 | { |
764 | currentstyle.setVOffset(0); | 825 | currentstyle.setVOffset(0); |
765 | } | 826 | } |
766 | else if (ent == "span") | 827 | else if (ent == "span") |
@@ -787,93 +848,98 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
787 | } | 848 | } |
788 | stylestack.push_front(currentstyle); | 849 | stylestack.push_front(currentstyle); |
789 | } | 850 | } |
790 | else if (ent == "/span") | 851 | else if (ent == "/span") |
791 | { | 852 | { |
792 | if (ch != '>') ch = skip_ws_end(); | 853 | if (ch != '>') ch = skip_ws_end(); |
793 | currentstyle.setBackground(255, 255, 255); | 854 | currentstyle.setBackground(255, 255, 255); |
794 | currentstyle.setColour(0, 0, 0); | 855 | currentstyle.setColour(0, 0, 0); |
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 | { |
811 | currentstyle.setBold(); | 873 | currentstyle.setBold(); |
812 | } | 874 | } |
813 | else if (ent == "u") | 875 | else if (ent == "u") |
814 | { | 876 | { |
815 | currentstyle.setUnderline(); | 877 | currentstyle.setUnderline(); |
816 | } | 878 | } |
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); |
841 | ch = 10; | 906 | ch = 10; |
842 | continue; | 907 | continue; |
843 | */ | 908 | */ |
844 | ch = 6; | 909 | ch = 6; |
845 | // currentstyle.setTop(); | 910 | // currentstyle.setTop(); |
846 | continue; | 911 | continue; |
847 | } | 912 | } |
848 | else if (ent == "center") | 913 | else if (ent == "center") |
849 | { | 914 | { |
850 | //forcecentre = true; | 915 | //forcecentre = true; |
851 | qDebug("setting centre"); | 916 | qDebug("setting centre"); |
852 | currentstyle.setCentreJustify(); | 917 | currentstyle.setCentreJustify(); |
853 | ch = 10; | 918 | ch = 10; |
854 | continue; | 919 | continue; |
855 | } | 920 | } |
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); |
872 | } | 938 | } |
873 | q += ' '; | 939 | q += ' '; |
874 | currentstyle.setLeftMargin(6*indent); | 940 | currentstyle.setLeftMargin(6*indent); |
875 | qDebug("Setting indent:%d", indent); | 941 | qDebug("Setting indent:%d", indent); |
876 | continue; | 942 | continue; |
877 | } | 943 | } |
878 | else if (ent == "ul") | 944 | else if (ent == "ul") |
879 | { | 945 | { |
@@ -905,70 +971,74 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
905 | else if (ent == "small") | 971 | else if (ent == "small") |
906 | { | 972 | { |
907 | currentstyle.setFontSize(-2); | 973 | currentstyle.setFontSize(-2); |
908 | } | 974 | } |
909 | else if (ent == "/small") | 975 | else if (ent == "/small") |
910 | { | 976 | { |
911 | currentstyle.setFontSize(0); | 977 | currentstyle.setFontSize(0); |
912 | } | 978 | } |
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 | } |
967 | else if (ent == "/pre") | 1037 | else if (ent == "/pre") |
968 | { | 1038 | { |
969 | currentstyle.unsetMono(); | 1039 | currentstyle.unsetMono(); |
970 | isPre = false; | 1040 | isPre = false; |
971 | } | 1041 | } |
972 | else if (ent == "/tt") | 1042 | else if (ent == "/tt") |
973 | { | 1043 | { |
974 | currentstyle.unsetMono(); | 1044 | currentstyle.unsetMono(); |
@@ -1034,116 +1104,158 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
1034 | else if (ent == "/td") | 1104 | else if (ent == "/td") |
1035 | { | 1105 | { |
1036 | currentstyle.unset(); | 1106 | currentstyle.unset(); |
1037 | if (ch != '>') ch = skip_ws_end(); | 1107 | if (ch != '>') ch = skip_ws_end(); |
1038 | if (!stylestack.isEmpty()) | 1108 | if (!stylestack.isEmpty()) |
1039 | { | 1109 | { |
1040 | stylestack.pop(); | 1110 | stylestack.pop(); |
1041 | } | 1111 | } |
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(); |
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()); |
1107 | q += 3; | 1209 | q += 3; |
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 | ||
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()); |
1142 | currentstyle.setPicture(true, img); | 1254 | currentstyle.setPicture(true, img); |
1143 | } | 1255 | } |
1144 | } | 1256 | } |
1145 | } | 1257 | } |
1146 | if (ent == "recindex") | 1258 | if (ent == "recindex") |
1147 | { | 1259 | { |
1148 | bool ok; | 1260 | bool ok; |
1149 | unsigned int picindex = attr.toUInt(&ok); | 1261 | unsigned int picindex = attr.toUInt(&ok); |
@@ -1159,51 +1271,62 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
1159 | } | 1271 | } |
1160 | } | 1272 | } |
1161 | } | 1273 | } |
1162 | if (ch != '>') ch = skip_ws_end(); | 1274 | if (ch != '>') ch = skip_ws_end(); |
1163 | ch = '#'; | 1275 | ch = '#'; |
1164 | break; | 1276 | break; |
1165 | } | 1277 | } |
1166 | else if (ent.left(2) == "dc") | 1278 | else if (ent.left(2) == "dc") |
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(); |
1183 | ch = 10; | 1303 | ch = 10; |
1184 | continue; | 1304 | continue; |
1185 | } | 1305 | } |
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(); |
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 == '&') |
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); |
1203 | while (ch != ';' && ch != UEOF) | 1326 | while (ch != ';' && ch != UEOF) |
1204 | { | 1327 | { |
1205 | id = 10*id+ch-'0'; | 1328 | id = 10*id+ch-'0'; |
1206 | mygetch(ch, dummy, npos); | 1329 | mygetch(ch, dummy, npos); |
1207 | } | 1330 | } |
1208 | ch = id; | 1331 | ch = id; |
1209 | } | 1332 | } |
@@ -1221,28 +1344,71 @@ void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) | |||
1221 | #if defined(USEQPE) || defined(_WINDOWS) | 1344 | #if defined(USEQPE) || defined(_WINDOWS) |
1222 | QMap<QString, tchar>::Iterator it = entmap->find(en); | 1345 | QMap<QString, tchar>::Iterator it = entmap->find(en); |
1223 | #else | 1346 | #else |
1224 | QMap<QString, tchar>::iterator it = entmap->find(en); | 1347 | QMap<QString, tchar>::iterator it = entmap->find(en); |
1225 | #endif | 1348 | #endif |
1226 | if (it != entmap->end()) | 1349 | if (it != entmap->end()) |
1227 | { | 1350 | { |
1228 | ch = *it; | 1351 | ch = *it; |
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 | ||
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 | } |