Beispiel #1
0
bool KHTMLReader::parse_ul(DOM::Element e)
{
    _list_depth++;
    bool popstateneeded = false;
    for (DOM::Node items = e.firstChild();!items.isNull();items = items.nextSibling()) {
        if (items.nodeName().string().toLower() == "li") {
            if (popstateneeded) {
                popState();
                //popstateneeded = false;
            }
            pushNewState();
            startNewLayout();
            popstateneeded = true;
            _writer->layoutAttribute(state()->paragraph, "COUNTER", "numberingtype", "1");
            _writer->layoutAttribute(state()->paragraph, "COUNTER", "righttext", ".");
            if (e.tagName().string().toLower() == "ol") {
                _writer->layoutAttribute(state()->paragraph, "COUNTER", "type", "1");
                _writer->layoutAttribute(state()->paragraph, "COUNTER", "numberingtype", "1");
                _writer->layoutAttribute(state()->paragraph, "COUNTER", "righttext", ".");
            } else {
                _writer->layoutAttribute(state()->paragraph, "COUNTER", "type", "10");
                _writer->layoutAttribute(state()->paragraph, "COUNTER", "numberingtype", "");
                _writer->layoutAttribute(state()->paragraph, "COUNTER", "righttext", "");
            }
            _writer->layoutAttribute(state()->paragraph, "COUNTER", "depth", QString("%1").arg(_list_depth - 1));
        }
        parseNode(items);
    }
    if (popstateneeded)
        popState();
    _list_depth--;
    return false;
}
Beispiel #2
0
void KHTMLReader::parse_head(DOM::Element e)
{
    for (DOM::Element items = e.firstChild();!items.isNull();items = items.nextSibling()) {
        if (items.tagName().string().lower() == "title") {
            DOM::Text t = items.firstChild();
            if (!t.isNull()) {
                _writer->createDocInfo("HTML import filter", t.data().string());
            }
        }
    }
}
Beispiel #3
0
bool KHTMLReader::parse_CommonAttributes(DOM::Element e)
{
    kDebug(30503) << "entering KHTMLReader::parse_CommonAttributes";
    kDebug(30503) << "tagName is" << e.tagName().string();
    QString s = e.getAttribute("align").string();
    if (!s.isEmpty()) {
        _writer->formatAttribute(state()->paragraph, "FLOW", "align", s);
    }
    QRegExp rx("h[0-9]+");
    if (0 == rx.search(e.getAttribute("class").string()))
        // example: <p class="h1" style="text-align:left; ">
    {
        _writer->layoutAttribute(state()->paragraph, "NAME", "value", e.getAttribute("class").string());
    }
    return true;
}
Beispiel #4
0
bool KHTMLReader::parseTag(DOM::Element e)
{
    _PP(a);
    _PP(p);
    _PP(br);
    _PP(table);
    _PP(pre);
    _PP(ul);
    _PP(ol);
    _PP(font);
    _PP(hr);

    // FIXME we can get rid of these, make things tons more simple
    // when khtml finally implements getComputedStyle
    _PF(b, WEIGHT, value, 75);
    _PF(strong, WEIGHT, value, 75);
    _PF(u, UNDERLINE, value, 1);
    _PF(i, ITALIC, value, 1);

    _PL(center, FLOW, align, center);
    _PL(right, FLOW, align, right);
    _PL(left, FLOW, align, left);

    _PL(h1, NAME, value, h1);
    _PL(h2, NAME, value, h2);
    _PL(h3, NAME, value, h3);
    _PL(h4, NAME, value, h4);
    _PL(h5, NAME, value, h5);
    _PL(h6, NAME, value, h6);

    // Don't handle the content of comment- or script-nodes.
    if (e.nodeType() == DOM::Node::COMMENT_NODE || e.tagName().lower() == "script") {
        return false;
    }

    return true;
}
Beispiel #5
0
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
}