Kaydet (Commit) 84392651 authored tarafından Bartosz Kosiorek's avatar Bartosz Kosiorek Kaydeden (comit) Mike Kaganski

tdf#114173 Preserve size of chart legend during xlsx export

During export chart into .xlsx file,
the information about size of legend was not saved.
Example of proper size:
                    <c:w val="0.41459448854442293"/>
                    <c:h val="0.23161616722845749"/>
another issue was hardcoded "layoutTarget" which
was always "inner":
                    <c:layoutTarget val="inner"/>
also properties regarding default text style was not preserved:

            <c:txPr>
                <a:bodyPr/>
                <a:lstStyle/>
                <a:p>
                    <a:pPr>
                        <a:defRPr sz="900" b="0" i="0" u="none" strike="noStrike" kern="1200" baseline="0">
                            <a:solidFill>
                                <a:schemeClr val="tx1">
                                    <a:lumMod val="65000"/>
                                    <a:lumOff val="35000"/>
                                </a:schemeClr>
                            </a:solidFill>
                        </a:defRPr>
                    </a:pPr>
                    <a:endParaRPr lang="pl-PL"/>
                </a:p>
            </c:txPr>

With this patch all these issues was resolved, and in case
of layoutTarget "outer", the field is not availble at all,
according to specification.

Change-Id: I2c9b7a112bdd911542b5273e660222d7fefa2d88
Reviewed-on: https://gerrit.libreoffice.org/47358Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 847d20b3
...@@ -1407,6 +1407,7 @@ void Chart2ExportTest::testTitleManualLayoutXLSX() ...@@ -1407,6 +1407,7 @@ void Chart2ExportTest::testTitleManualLayoutXLSX()
load("/chart2/qa/extras/data/xlsx/", "title_manual_layout.xlsx"); load("/chart2/qa/extras/data/xlsx/", "title_manual_layout.xlsx");
xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
CPPUNIT_ASSERT(pXmlDoc); CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:layoutTarget", 0);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:xMode", "val", "edge"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:xMode", "val", "edge");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:yMode", "val", "edge"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:yMode", "val", "edge");
...@@ -1428,6 +1429,7 @@ void Chart2ExportTest::testPlotAreaManualLayoutXLSX() ...@@ -1428,6 +1429,7 @@ void Chart2ExportTest::testPlotAreaManualLayoutXLSX()
xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
CPPUNIT_ASSERT(pXmlDoc); CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:layoutTarget", "val", "inner");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:xMode", "val", "edge"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:xMode", "val", "edge");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:yMode", "val", "edge"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:yMode", "val", "edge");
...@@ -1456,6 +1458,7 @@ void Chart2ExportTest::testLegendManualLayoutXLSX() ...@@ -1456,6 +1458,7 @@ void Chart2ExportTest::testLegendManualLayoutXLSX()
xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
CPPUNIT_ASSERT(pXmlDoc); CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:layoutTarget", 0);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:xMode", "val", "edge"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:xMode", "val", "edge");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:yMode", "val", "edge"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:yMode", "val", "edge");
...@@ -1467,6 +1470,18 @@ void Chart2ExportTest::testLegendManualLayoutXLSX() ...@@ -1467,6 +1470,18 @@ void Chart2ExportTest::testLegendManualLayoutXLSX()
double nY = aYVal.toDouble(); double nY = aYVal.toDouble();
CPPUNIT_ASSERT(nY > 0 && nY < 1); CPPUNIT_ASSERT(nY > 0 && nY < 1);
CPPUNIT_ASSERT(nX != nY); CPPUNIT_ASSERT(nX != nY);
OUString aWVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:w", "val");
double nW = aWVal.toDouble();
CPPUNIT_ASSERT(nW > 0 && nW < 1);
OUString aHVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:h", "val");
double nH = aHVal.toDouble();
CPPUNIT_ASSERT(nH > 0 && nH < 1);
CPPUNIT_ASSERT(nH != nW);
// Make sure that default text font size is preserved after export
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:txPr/a:p/a:pPr/a:defRPr", "sz", "900");
} }
void Chart2ExportTest::testAxisCharacterPropertiesXLSX() void Chart2ExportTest::testAxisCharacterPropertiesXLSX()
......
...@@ -134,7 +134,8 @@ private: ...@@ -134,7 +134,8 @@ private:
css::chart::XChartDocument >& rChartDoc ); css::chart::XChartDocument >& rChartDoc );
void exportTitle( const css::uno::Reference< void exportTitle( const css::uno::Reference<
css::drawing::XShape >& xShape ); css::drawing::XShape >& xShape );
void exportPlotArea( ); void exportPlotArea( const css::uno::Reference<
css::chart::XChartDocument >& rChartDoc );
void exportPlotAreaShapeProps( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); void exportPlotAreaShapeProps( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
void exportFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); void exportFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
void exportGradientFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); void exportGradientFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
...@@ -188,7 +189,7 @@ private: ...@@ -188,7 +189,7 @@ private:
void exportErrorBar(const css::uno::Reference< css::beans::XPropertySet >& xErrorBarProps, void exportErrorBar(const css::uno::Reference< css::beans::XPropertySet >& xErrorBarProps,
bool bYError); bool bYError);
void exportManualLayout(const css::chart2::RelativePosition& rPos, const css::chart2::RelativeSize& rSize); void exportManualLayout(const css::chart2::RelativePosition& rPos, const css::chart2::RelativeSize& rSize, const bool bIsExcludingDiagramPositioning);
void exportAxes( ); void exportAxes( );
void exportAxis(const AxisIdPair& rAxisIdPair); void exportAxis(const AxisIdPair& rAxisIdPair);
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include <com/sun/star/chart/DataLabelPlacement.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp>
#include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp>
#include <com/sun/star/chart/MissingValueTreatment.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp>
#include <com/sun/star/chart/XDiagramPositioning.hpp>
#include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/chart2/RelativeSize.hpp> #include <com/sun/star/chart2/RelativeSize.hpp>
...@@ -748,7 +749,7 @@ void ChartExport::exportChart( const Reference< css::chart::XChartDocument >& xC ...@@ -748,7 +749,7 @@ void ChartExport::exportChart( const Reference< css::chart::XChartDocument >& xC
} }
// plot area // plot area
exportPlotArea( ); exportPlotArea( xChartDoc );
// legend // legend
if( bHasLegend ) if( bHasLegend )
exportLegend( xChartDoc ); exportLegend( xChartDoc );
...@@ -851,7 +852,6 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x ...@@ -851,7 +852,6 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x
uno::Any aRelativePos = xProp->getPropertyValue("RelativePosition"); uno::Any aRelativePos = xProp->getPropertyValue("RelativePosition");
if (aRelativePos.hasValue()) if (aRelativePos.hasValue())
{ {
chart2::RelativePosition aPos = aRelativePos.get<chart2::RelativePosition>();
pFS->startElement(FSNS(XML_c, XML_layout), FSEND); pFS->startElement(FSNS(XML_c, XML_layout), FSEND);
pFS->startElement(FSNS(XML_c, XML_manualLayout), FSEND); pFS->startElement(FSNS(XML_c, XML_manualLayout), FSEND);
...@@ -861,9 +861,14 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x ...@@ -861,9 +861,14 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x
pFS->singleElement(FSNS(XML_c, XML_yMode), pFS->singleElement(FSNS(XML_c, XML_yMode),
XML_val, "edge", XML_val, "edge",
FSEND); FSEND);
chart2::RelativePosition aPos = aRelativePos.get<chart2::RelativePosition>();
uno::Any aRelativeSize = xProp->getPropertyValue("RelativeSize");
chart2::RelativeSize aSize = aRelativeSize.get<chart2::RelativeSize>();
double x = aPos.Primary; const double x = aPos.Primary;
double y = aPos.Secondary; const double y = aPos.Secondary;
const double w = aSize.Primary;
const double h = aSize.Secondary;
pFS->singleElement(FSNS(XML_c, XML_x), pFS->singleElement(FSNS(XML_c, XML_x),
XML_val, IS(x), XML_val, IS(x),
...@@ -871,6 +876,14 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x ...@@ -871,6 +876,14 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x
pFS->singleElement(FSNS(XML_c, XML_y), pFS->singleElement(FSNS(XML_c, XML_y),
XML_val, IS(y), XML_val, IS(y),
FSEND); FSEND);
pFS->singleElement(FSNS(XML_c, XML_w),
XML_val, IS(w),
FSEND);
pFS->singleElement(FSNS(XML_c, XML_h),
XML_val, IS(h),
FSEND);
SAL_WARN_IF(aPos.Anchor != css::drawing::Alignment_TOP_LEFT, "oox", "unsupported anchor position"); SAL_WARN_IF(aPos.Anchor != css::drawing::Alignment_TOP_LEFT, "oox", "unsupported anchor position");
pFS->endElement(FSNS(XML_c, XML_manualLayout)); pFS->endElement(FSNS(XML_c, XML_manualLayout));
...@@ -886,6 +899,9 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x ...@@ -886,6 +899,9 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x
// shape properties // shape properties
exportShapeProps( xProp ); exportShapeProps( xProp );
// draw-chart:txPr text properties
exportTextProps( xProp );
} }
// legendEntry // legendEntry
...@@ -1010,7 +1026,7 @@ void ChartExport::exportTitle( const Reference< XShape >& xShape ) ...@@ -1010,7 +1026,7 @@ void ChartExport::exportTitle( const Reference< XShape >& xShape )
pFS->endElement( FSNS( XML_c, XML_title ) ); pFS->endElement( FSNS( XML_c, XML_title ) );
} }
void ChartExport::exportPlotArea( ) void ChartExport::exportPlotArea( const Reference< css::chart::XChartDocument >& xChartDoc )
{ {
Reference< chart2::XCoordinateSystemContainer > xBCooSysCnt( mxNewDiagram, uno::UNO_QUERY ); Reference< chart2::XCoordinateSystemContainer > xBCooSysCnt( mxNewDiagram, uno::UNO_QUERY );
if( ! xBCooSysCnt.is()) if( ! xBCooSysCnt.is())
...@@ -1031,7 +1047,8 @@ void ChartExport::exportPlotArea( ) ...@@ -1031,7 +1047,8 @@ void ChartExport::exportPlotArea( )
chart2::RelativePosition aPos = aAny.get<chart2::RelativePosition>(); chart2::RelativePosition aPos = aAny.get<chart2::RelativePosition>();
aAny = xWall->getPropertyValue("RelativeSize"); aAny = xWall->getPropertyValue("RelativeSize");
chart2::RelativeSize aSize = aAny.get<chart2::RelativeSize>(); chart2::RelativeSize aSize = aAny.get<chart2::RelativeSize>();
exportManualLayout(aPos, aSize); uno::Reference< css::chart::XDiagramPositioning > xDiagramPositioning( xChartDoc->getDiagram(), uno::UNO_QUERY );
exportManualLayout(aPos, aSize, xDiagramPositioning->isExcludingDiagramPositioning() );
} }
} }
...@@ -1143,14 +1160,21 @@ void ChartExport::exportPlotArea( ) ...@@ -1143,14 +1160,21 @@ void ChartExport::exportPlotArea( )
} }
void ChartExport::exportManualLayout(const css::chart2::RelativePosition& rPos, const css::chart2::RelativeSize& rSize) void ChartExport::exportManualLayout(const css::chart2::RelativePosition& rPos,
const css::chart2::RelativeSize& rSize,
const bool bIsExcludingDiagramPositioning)
{ {
FSHelperPtr pFS = GetFS(); FSHelperPtr pFS = GetFS();
pFS->startElement(FSNS(XML_c, XML_layout), FSEND); pFS->startElement(FSNS(XML_c, XML_layout), FSEND);
pFS->startElement(FSNS(XML_c, XML_manualLayout), FSEND); pFS->startElement(FSNS(XML_c, XML_manualLayout), FSEND);
pFS->singleElement(FSNS(XML_c, XML_layoutTarget),
XML_val, "inner", // By default layoutTarget is set to "outer" and we shouldn't save it in that case
FSEND); if ( bIsExcludingDiagramPositioning )
{
pFS->singleElement(FSNS(XML_c, XML_layoutTarget),
XML_val, "inner",
FSEND);
}
pFS->singleElement(FSNS(XML_c, XML_xMode), pFS->singleElement(FSNS(XML_c, XML_xMode),
XML_val, "edge", XML_val, "edge",
FSEND); FSEND);
...@@ -1160,8 +1184,8 @@ void ChartExport::exportManualLayout(const css::chart2::RelativePosition& rPos, ...@@ -1160,8 +1184,8 @@ void ChartExport::exportManualLayout(const css::chart2::RelativePosition& rPos,
double x = rPos.Primary; double x = rPos.Primary;
double y = rPos.Secondary; double y = rPos.Secondary;
double w = rSize.Primary; const double w = rSize.Primary;
double h = rSize.Secondary; const double h = rSize.Secondary;
switch (rPos.Anchor) switch (rPos.Anchor)
{ {
case drawing::Alignment_LEFT: case drawing::Alignment_LEFT:
...@@ -2278,20 +2302,18 @@ void ChartExport::exportTextProps(const Reference<XPropertySet>& xPropSet) ...@@ -2278,20 +2302,18 @@ void ChartExport::exportTextProps(const Reference<XPropertySet>& xPropSet)
{ {
FSHelperPtr pFS = GetFS(); FSHelperPtr pFS = GetFS();
pFS->startElement(FSNS(XML_c, XML_txPr), FSEND); pFS->startElement(FSNS(XML_c, XML_txPr), FSEND);
pFS->singleElement( FSNS( XML_a, XML_bodyPr ), FSEND );
pFS->startElement(FSNS(XML_a, XML_bodyPr), FSEND); pFS->singleElement( FSNS( XML_a, XML_lstStyle ), FSEND );
pFS->endElement(FSNS(XML_a, XML_bodyPr));
pFS->startElement(FSNS(XML_a, XML_p), FSEND); pFS->startElement(FSNS(XML_a, XML_p), FSEND);
pFS->startElement(FSNS(XML_a, XML_pPr), FSEND); pFS->startElement(FSNS(XML_a, XML_pPr), FSEND);
bool bDummy = false; bool bOverrideCharHeight = false;
sal_Int32 nDummy; sal_Int32 nCharHeight;
WriteRunProperties(xPropSet, false, XML_defRPr, true, bDummy, nDummy); WriteRunProperties(xPropSet, false, XML_defRPr, true, bOverrideCharHeight, nCharHeight);
pFS->endElement(FSNS(XML_a, XML_pPr)); pFS->endElement(FSNS(XML_a, XML_pPr));
pFS->endElement(FSNS(XML_a, XML_p)); pFS->endElement(FSNS(XML_a, XML_p));
pFS->endElement(FSNS(XML_c, XML_txPr)); pFS->endElement(FSNS(XML_c, XML_txPr));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment