예제 #1
0
void exportText(QString& ret,
                const QString& text,
                const KTextEditor::Attribute::Ptr& attrib)
{
    if ( !attrib || !attrib->hasAnyProperty()) {
        ret.append(text);
        return;
    }

    if ( attrib->fontBold() ) {
        ret.append("<b>");
    }
    if ( attrib->fontItalic() ) {
        ret.append("<i>");
    }

    bool writeForeground = attrib->hasProperty(QTextCharFormat::ForegroundBrush);
    bool writeBackground = attrib->hasProperty(QTextCharFormat::BackgroundBrush);

    if ( writeForeground || writeBackground ) {
        ret.append(QString("<span style='%1%2'>")
            .arg(writeForeground ? QString(QLatin1String("color:") 
                                            + attrib->foreground().color().name() 
                                            + QLatin1Char(';')) 
                                    : QString())
            .arg(writeBackground ? QString(QLatin1String("background:") 
                                            + attrib->background().color().name() 
                                            + QLatin1Char(';')) 
                                    : QString()));
    }
    ret.append(text);

    if ( writeBackground || writeForeground ) {
        ret.append("</span>");
    }
    if ( attrib->fontItalic() ) {
        ret.append("</i>");
    }
    if ( attrib->fontBold() ) {
        ret.append("</b>");
    }
}
예제 #2
0
void HTMLExporter::exportText(const QString &text, const KTextEditor::Attribute::Ptr &attrib)
{
    if (!attrib || !attrib->hasAnyProperty() || attrib == m_defaultAttribute) {
        m_output << text.toHtmlEscaped();
        return;
    }

    if (attrib->fontBold()) {
        m_output << "<b>";
    }
    if (attrib->fontItalic()) {
        m_output << "<i>";
    }

    bool writeForeground = attrib->hasProperty(QTextCharFormat::ForegroundBrush)
                           && (!m_defaultAttribute || attrib->foreground().color() != m_defaultAttribute->foreground().color());
    bool writeBackground = attrib->hasProperty(QTextCharFormat::BackgroundBrush)
                           && (!m_defaultAttribute || attrib->background().color() != m_defaultAttribute->background().color());

    if (writeForeground || writeBackground) {
        m_output << QStringLiteral("<span style='%1%2'>")
                 .arg(writeForeground ? QString(QLatin1String("color:") + attrib->foreground().color().name() + QLatin1Char(';')) : QString())
                 .arg(writeBackground ? QString(QLatin1String("background:") + attrib->background().color().name() + QLatin1Char(';')) : QString());
    }

    m_output << text.toHtmlEscaped();

    if (writeBackground || writeForeground) {
        m_output << "</span>";
    }
    if (attrib->fontItalic()) {
        m_output << "</i>";
    }
    if (attrib->fontBold()) {
        m_output << "</b>";
    }
}