Beispiel #1
0
bool KHTMLReader::parse_font(DOM::Element e)
{
    // fixme don't hardcode 12 font size ...
    QString face = e.getAttribute("face").string();
    QColor color = parsecolor("#000000");
    if (!e.getAttribute("color").string().isEmpty())
        color = parsecolor(e.getAttribute("color").string());
    QString size = e.getAttribute("size").string();
    int isize = -1;
    if (size.startsWith('+'))
        isize = 12 + size.right(size.length() - 1).toInt();
    else if (size.startsWith('-'))
        isize = 12 - size.right(size.length() - 1).toInt();
    else
        isize = 12 + size.toInt();

    _writer->formatAttribute(state()->paragraph, "FONT", "name", face);
    if ((isize >= 0) && (isize != 12))
        _writer->formatAttribute(state()->paragraph, "SIZE", "value", QString("%1").arg(isize));

    _writer->formatAttribute(state()->paragraph, "COLOR", "red", QString("%1").arg(color.red()));
    _writer->formatAttribute(state()->paragraph, "COLOR", "green", QString("%1").arg(color.green()));
    _writer->formatAttribute(state()->paragraph, "COLOR", "blue", QString("%1").arg(color.blue()));
    return true;
}
Beispiel #2
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 #3
0
bool KHTMLReader::parse_a(DOM::Element e)
{
    QString url = e.getAttribute("href").string();
    if (!url.isEmpty()) {
        QString linkName;
        DOM::Text t = e.firstChild();
        if (t.isNull()) {
            /* Link without text -> just drop it*/
            return false; /* stop parsing recursively */
        }
        linkName = t.data().string().simplified();
        t.setData(DOM::DOMString("#")); // replace with '#'
        _writer->createLink(state()->paragraph, linkName, url);
    }
    return true; /* stop parsing recursively */
}
Beispiel #4
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
}