bool KHTMLReader::parse_table(DOM::Element e) { if (_writer->isInTable()) { // We are already inside of a table. Tables in tables are not supported // yet. So, just add that table-content as text. for (DOM::Node rows = e.firstChild().firstChild();!rows.isNull();rows = rows.nextSibling()) if (!rows.isNull() && rows.nodeName().string().toLower() == "tr") for (DOM::Node cols = rows.firstChild();!cols.isNull();cols = cols.nextSibling()) if (!cols.isNull()) parseNode(cols); return false; } DOM::Element table_body = e.firstChild(); if (table_body.isNull()) { // If the table_body is empty, we don't continue cause else // KHTML will throw a DOM::DOMException if we try to access // the null element. return true; } int tableno = _writer->createTable(); int nrow = 0; int ncol = 0; bool has_borders = false; QColor bgcolor = parsecolor("#FFFFFF"); if (!table_body.getAttribute("bgcolor").string().isEmpty()) bgcolor = parsecolor(table_body.getAttribute("bgcolor").string()); if ((e.getAttribute("border").string().toInt() > 0)) has_borders = true; // fixme rewrite this proper //(maybe using computed sizes from khtml if thats once exported) for (DOM::Node rowsnode = table_body.firstChild();!rowsnode.isNull();rowsnode = rowsnode.nextSibling()) { DOM::Element rows = rowsnode; if (!rows.isNull() && rows.tagName().string().toLower() == "tr") { QColor obgcolor = bgcolor; if (!rows.getAttribute("bgcolor").string().isEmpty()) bgcolor = parsecolor(rows.getAttribute("bgcolor").string()); ncol = 0; for (DOM::Node colsnode = rows.firstChild();!colsnode.isNull();colsnode = colsnode.nextSibling()) { DOM::Element cols = colsnode; const QString nodename = cols.isNull() ? QString() : cols.nodeName().string().toLower(); if (nodename == "td" || nodename == "th") { QColor bbgcolor = bgcolor; if (!cols.getAttribute("bgcolor").string().isEmpty()) bgcolor = parsecolor(cols.getAttribute("bgcolor").string()); pushNewState(); QRect colrect = cols.getRect(); state()->frameset = _writer->createTableCell(tableno, nrow, ncol, 1, colrect); state()->frameset.firstChild().toElement().setAttribute("bkRed", bgcolor.red()); state()->frameset.firstChild().toElement().setAttribute("bkGreen", bgcolor.green()); state()->frameset.firstChild().toElement().setAttribute("bkBlue", bgcolor.blue()); if (has_borders) { state()->frameset.firstChild().toElement().setAttribute("lWidth", 1); state()->frameset.firstChild().toElement().setAttribute("rWidth", 1); state()->frameset.firstChild().toElement().setAttribute("bWidth", 1); state()->frameset.firstChild().toElement().setAttribute("tWidth", 1); } // fixme don't guess. get it right. state()->paragraph = _writer->addParagraph(state()->frameset); parseNode(cols); _writer->cleanUpParagraph(state()->paragraph); popState(); ncol++; bgcolor = bbgcolor; } } nrow++; bgcolor = obgcolor; } } _writer->finishTable(tableno/*,0,0,r.right()-r.left(),r.bottom()-r.top()*/); // FIXME find something better. startNewParagraph(false, false); _writer->createInline(state()->paragraph, _writer->fetchTableCell(tableno, 0, 0)); startNewParagraph(false, false); return false; // we do our own recursion }