コード例 #1
0
ファイル: ChartShape.cpp プロジェクト: foren197316/calligra
void saveOdfLabel(KoShape *label, KoXmlWriter &bodyWriter,
                  KoGenStyles &mainStyles, LabelType labelType)
{
    // Don't save hidden labels, as that's the way of removing them
    // from a chart.
    if (!label->isVisible())
        return;

    TextLabelData *labelData = qobject_cast<TextLabelData*>(label->userData());
    if (!labelData)
        return;

    if (labelType == FooterLabelType)
        bodyWriter.startElement("chart:footer");
    else if (labelType == SubTitleLabelType)
        bodyWriter.startElement("chart:subtitle");
    else // if (labelType == TitleLabelType)
        bodyWriter.startElement("chart:title");

    bodyWriter.addAttributePt("svg:x", label->position().x());
    bodyWriter.addAttributePt("svg:y", label->position().y());
    bodyWriter.addAttributePt("svg:width", label->size().width());
    bodyWriter.addAttributePt("svg:height", label->size().height());

    // TODO: Save text label color
    QTextCursor cursor(labelData->document());
    QFont labelFont = cursor.charFormat().font();

    KoGenStyle autoStyle(KoGenStyle::ChartAutoStyle, "chart", 0);
    autoStyle.addPropertyPt("style:rotation-angle", 360 - label->rotation());
    saveOdfFont(autoStyle, labelFont, QColor());
    bodyWriter.addAttribute("chart:style-name", mainStyles.insert(autoStyle, "ch"));

    bodyWriter.startElement("text:p");
    bodyWriter.addTextNode(labelData->document()->toPlainText());
    bodyWriter.endElement(); // text:p
    bodyWriter.endElement(); // chart:title/subtitle/footer
}
コード例 #2
0
// Called by Document before invoking the table-row-functors
void WordsTableHandler::tableStart(Words::Table* table)
{
    kDebug(30513);

    Q_ASSERT(table);
    Q_ASSERT(!table->name.isEmpty());

    wvWare::SharedPtr<const wvWare::Word97::TAP> tap = table->tap;
    KoXmlWriter* writer = currentWriter();

    m_currentTable = table;
    m_cellOpen = false;
    m_row = -1;
    m_currentY = 0;

#ifdef DEBUG_TABLEHANDLER
    for (unsigned int i = 0; i < (unsigned int)table->m_cellEdges.size(); i++) {
        kDebug(30513) << table->m_cellEdges[i];
    }
#endif

    if (m_currentTable->floating) {
        const KoGenStyle::PropertyType gt = KoGenStyle::GraphicType;
        KoGenStyle style(KoGenStyle::GraphicAutoStyle, "graphic");
        if (document()->writingHeader()) {
            style.setAutoStyleInStylesDotXml(true);
        }

        //style:wrap
        if (tap->textWrap) {
            if (tap->dxaAbs == -8) {
                style.addProperty("style:wrap", "left", gt);
            }
            else if (tap->dxaAbs == 0) {
                style.addProperty("style:wrap", "right", gt);
            } else {
                style.addProperty("style:wrap", "parallel", gt);
            }
            //ODF-1.2: Specifies the number of paragraphs that can wrap around
            //a frame if wrap mode is in {left, right, parallel, dynamic} and
            //anchor type is in {char, paragraph}.
            style.addProperty("style:number-wrapped-paragraphs", "no-limit", gt);
        } else {
            style.addProperty("style:wrap", "none", gt);
        }
        //fo:margin
        style.addPropertyPt("fo:margin-left", twipsToPt(tap->dxaFromText), gt);
        style.addPropertyPt("fo:margin-right", twipsToPt(tap->dxaFromTextRight), gt);
        style.addPropertyPt("fo:margin-top", twipsToPt(tap->dyaFromText), gt);
        style.addPropertyPt("fo:margin-bottom", twipsToPt(tap->dyaFromTextBottom), gt);

        int dxaAbs = 0;
        int dyaAbs = 0;

        //style:horizontal-pos - horizontal position of the anchor
        QString pos = Conversion::getHorizontalPos(tap->dxaAbs);
        style.addProperty("style:horizontal-pos", pos, gt);
        if (pos == "from-left") {
            dxaAbs = tap->dxaAbs;
        }
        //style:vertical-pos - vertical position of the anchor
        pos = Conversion::getVerticalPos(tap->dyaAbs);
        style.addProperty("style:vertical-pos", pos, gt);
        if (pos == "from-top") {
            dyaAbs = tap->dyaAbs;
        }
        //style:vertical-rel - relative vertical position of the anchor
        pos = Conversion::getVerticalRel(tap->pcVert);
	if (!pos.isEmpty()) {
            style.addProperty("style:vertical-rel", pos, gt);
        }
        //style:horizontal-rel - relative horizontal position of the anchor
        pos = Conversion::getHorizontalRel(tap->pcHorz);
        if (!pos.isEmpty()) {
            style.addProperty("style:horizontal-rel", pos, gt);
        }
        //draw:auto-grow-height
        style.addProperty("draw:auto-grow-height", "true", gt);

        const QString drawStyleName = m_mainStyles->insert(style);

        writer->startElement("draw:frame");
        writer->addAttribute("draw:style-name", drawStyleName.toUtf8());
        writer->addAttribute("text:anchor-type", "paragraph");

        int width = table->m_cellEdges[table->m_cellEdges.size() - 1] - table->m_cellEdges[0];
        writer->addAttributePt("svg:width", twipsToPt(width));

        if (style.property("style:horizontal-pos", gt) == "from-left") {
            writer->addAttributePt("svg:x", twipsToPt(dxaAbs + tap->rgdxaCenter[0]));
        }

        writer->addAttributePt("svg:y", twipsToPt(dyaAbs));
        writer->startElement("draw:text-box");
    } //absolutely positioned table

    KoGenStyle tableStyle(KoGenStyle::TableAutoStyle, "table");
    if (document()->writingHeader()) {
        tableStyle.setAutoStyleInStylesDotXml(true);
    }

    //TODO: process the border color information <table:border-color>

    if (tap->fBiDi == 1) {
        tableStyle.addProperty("style:writing-mode", "rl-tb");
    } else {
        tableStyle.addProperty("style:writing-mode", "lr-tb");
    }

    //process horizontal align information
    QString align;
    if (m_currentTable->floating) {
        align = QString("margins");
    } else {
        switch (tap->jc) {
        case hAlignLeft:
            align = QString("left");
            break;
        case hAlignCenter:
            align = QString("center");
            break;
        case hAlignRight:
            align = QString("right");
            break;
        }
    }
    tableStyle.addProperty("table:align", align);

    int width = table->m_cellEdges[table->m_cellEdges.size() - 1] - table->m_cellEdges[0];
    tableStyle.addPropertyPt("style:width", twipsToPt(width));
    tableStyle.addProperty("table:border-model", "collapsing");

    //process the margin information
    if (!m_currentTable->floating) {
        tableStyle.addPropertyPt("fo:margin-left", twipsToPt(tap->rgdxaCenter[0]));
    }

    //check if we need a master page name attribute.
    if (document()->writeMasterPageName() && !document()->writingHeader()) {
        tableStyle.addAttribute("style:master-page-name", document()->masterPageName());
        document()->set_writeMasterPageName(false);
    }

    QString tableStyleName = m_mainStyles->insert(tableStyle, QLatin1String("Table"), KoGenStyles::AllowDuplicates);

    //start table in content
    writer->startElement("table:table");
    writer->addAttribute("table:style-name", tableStyleName);

    // Write the table:table-column descriptions.
    for (int r = 0; r < table->m_cellEdges.size() - 1; r++) {
        KoGenStyle tableColumnStyle(KoGenStyle::TableColumnAutoStyle, "table-column");

        //in case a header or footer is processed, save the style into styles.xml
        if (document()->writingHeader()) {
            tableColumnStyle.setAutoStyleInStylesDotXml(true);
        }

        tableColumnStyle.addPropertyPt("style:column-width",
                                       (table->m_cellEdges[r+1] - table->m_cellEdges[r]) / 20.0);

        QString tableColumnStyleName;
        if (r >= 26) {
            tableColumnStyleName = m_mainStyles->insert(tableColumnStyle, tableStyleName + ".A" + QChar('A' + r - 26), KoGenStyles::DontAddNumberToName);
        } else {
            tableColumnStyleName = m_mainStyles->insert(tableColumnStyle, tableStyleName + '.' + QChar('A' + r), KoGenStyles::DontAddNumberToName);
        }

        writer->startElement("table:table-column");
        writer->addAttribute("table:style-name", tableColumnStyleName);
        writer->endElement();
    }
}