summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorTünde Tóth <tundeth@gmail.com>2020-03-06 10:29:03 +0100
committerLászló Németh <nemeth@numbertext.org>2020-04-09 11:12:22 +0200
commit40d83914d43f60a196dfabddea0b52e2046b333a (patch)
tree86165bf504f42aba1195249c48f0a109722e23b3 /xmloff
parent31de39108ce19c002ab4ef6ab369dd5bfa668634 (diff)
tdf#127792 implement UNO chart attribute MajorOrigin
based on the specification in OFFICE-3936 for ODF 1.4: https://issues.oasis-open.org/browse/OFFICE-3936 Note: import of the embedded chart of the DOCX unit test document uses also ODF format in the background, testing also the extension of the native file format. Follow-up of commit 830e539547c463b932ce643517f880789185032d (tdf#127393 OOXML chart import: fix X axis position setting "CrossBetween"). See also commits with "ShiftedCategoryPosition" in their descriptions. Change-Id: I9cd278ac0172c0fab7c51d585a65c34a0ad60b82 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90081 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/chart/PropertyMap.hxx1
-rw-r--r--xmloff/source/chart/SchXMLAxisContext.cxx43
-rw-r--r--xmloff/source/chart/SchXMLExport.cxx29
-rw-r--r--xmloff/source/core/xmltoken.cxx1
-rw-r--r--xmloff/source/token/tokens.txt1
5 files changed, 49 insertions, 26 deletions
diff --git a/xmloff/source/chart/PropertyMap.hxx b/xmloff/source/chart/PropertyMap.hxx
index aa132990bc3b..0b8d52c93bce 100644
--- a/xmloff/source/chart/PropertyMap.hxx
+++ b/xmloff/source/chart/PropertyMap.hxx
@@ -184,6 +184,7 @@ const XMLPropertyMapEntry aXMLChartPropMap[] =
MAP_SPECIAL( "NumberFormat", STYLE, XML_DATA_STYLE_NAME, XML_TYPE_NUMBER, XML_SCH_CONTEXT_SPECIAL_NUMBER_FORMAT ),
MAP_ENTRY( "LinkNumberFormatToSource", CHART, XML_LINK_DATA_STYLE_TO_SOURCE, XML_TYPE_BOOL ),
MAP_ENTRY( "Visible", CHART, XML_VISIBLE, XML_TYPE_BOOL ),
+ MAP_ENTRY_ODF_EXT( "MajorOrigin", LO_EXT, XML_MAJOR_ORIGIN, XML_TYPE_DOUBLE ),
MAP_FULL( "CrossoverPosition", CHART, XML_AXIS_POSITION, XML_SCH_TYPE_AXIS_POSITION|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0, SvtSaveOptions::ODFVER_012 ),
MAP_FULL( "CrossoverValue", CHART, XML_AXIS_POSITION, XML_SCH_TYPE_AXIS_POSITION_VALUE|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0, SvtSaveOptions::ODFVER_012 ),
diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx
index 962fec96e6df..577d87b1ac49 100644
--- a/xmloff/source/chart/SchXMLAxisContext.cxx
+++ b/xmloff/source/chart/SchXMLAxisContext.cxx
@@ -465,25 +465,6 @@ void SchXMLAxisContext::CreateAxis()
if( m_bAxisTypeImported )
m_xAxisProps->setPropertyValue("AxisType", uno::makeAny(m_nAxisType) );
- if( m_aCurrentAxis.eDimension == SCH_XML_AXIS_X )
- {
- bool bIs3DChart = false;
- if( (xDiaProp->getPropertyValue("Dim3D") >>= bIs3DChart) && bIs3DChart )
- {
- OUString sChartType = m_xDiagram->getDiagramType();
- if( sChartType == "com.sun.star.chart.BarDiagram" || sChartType == "com.sun.star.chart.StockDiagram" )
- {
- Reference< chart2::XAxis > xAxis(lcl_getAxis(GetImport().GetModel(), m_aCurrentAxis.eDimension, m_aCurrentAxis.nAxisIndex));
- if( xAxis.is() )
- {
- chart2::ScaleData aScaleData(xAxis->getScaleData());
- aScaleData.ShiftedCategoryPosition = true;
- xAxis->setScaleData(aScaleData);
- }
- }
- }
- }
-
if( !m_aAutoStyleName.isEmpty())
{
const SvXMLStylesContext* pStylesCtxt = m_rImportHelper.GetAutoStylesContext();
@@ -579,6 +560,30 @@ void SchXMLAxisContext::CreateAxis()
}
}
}
+
+ if (m_aCurrentAxis.eDimension == SCH_XML_AXIS_X)
+ {
+ Reference<chart2::XAxis> xAxis(lcl_getAxis(GetImport().GetModel(), m_aCurrentAxis.eDimension, m_aCurrentAxis.nAxisIndex));
+ if (xAxis.is())
+ {
+ chart2::ScaleData aScaleData(xAxis->getScaleData());
+ bool bIs3DChart = false;
+ double fMajorOrigin = -1;
+ OUString sChartType = m_xDiagram->getDiagramType();
+ if ((xDiaProp->getPropertyValue("Dim3D") >>= bIs3DChart) && bIs3DChart
+ && (sChartType == "com.sun.star.chart.BarDiagram" || sChartType == "com.sun.star.chart.StockDiagram"))
+ {
+ aScaleData.ShiftedCategoryPosition = true;
+ xAxis->setScaleData(aScaleData);
+ }
+ else if ((m_xAxisProps->getPropertyValue("MajorOrigin") >>= fMajorOrigin)
+ && (rtl::math::approxEqual(fMajorOrigin, 0.0) || rtl::math::approxEqual(fMajorOrigin, 0.5)))
+ {
+ aScaleData.ShiftedCategoryPosition = rtl::math::approxEqual(fMajorOrigin, 0.5);
+ xAxis->setScaleData(aScaleData);
+ }
+ }
+ }
}
}
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx
index 07226e89cda2..5566c0b2dfd3 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -201,7 +201,7 @@ public:
void exportAxis( enum XMLTokenEnum eDimension, enum XMLTokenEnum eAxisName,
const Reference< beans::XPropertySet >& rAxisProps, const Reference< chart2::XAxis >& rChart2Axis,
const OUString& rCategoriesRanges,
- bool bHasTitle, bool bHasMajorGrid, bool bHasMinorGrid, bool bExportContent );
+ bool bHasTitle, bool bHasMajorGrid, bool bHasMinorGrid, bool bExportContent, OUString sChartType );
void exportGrid( const Reference< beans::XPropertySet >& rGridProperties, bool bMajor, bool bExportContent );
void exportDateScale( const Reference< beans::XPropertySet >& rAxisProps );
void exportAxisTitle( const Reference< beans::XPropertySet >& rTitleProps, bool bExportContent );
@@ -2290,7 +2290,7 @@ void SchXMLExportHelper_Impl::exportAxis(
const Reference< chart2::XAxis >& rChart2Axis,
const OUString& rCategoriesRange,
bool bHasTitle, bool bHasMajorGrid, bool bHasMinorGrid,
- bool bExportContent )
+ bool bExportContent, OUString sChartType )
{
std::vector< XMLPropertyState > aPropertyStates;
std::unique_ptr<SvXMLElementExport> pAxis;
@@ -2298,6 +2298,20 @@ void SchXMLExportHelper_Impl::exportAxis(
// get property states for autostyles
if( rAxisProps.is() && mxExpPropMapper.is() )
{
+ const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion(SvtSaveOptions().GetODFDefaultVersion());
+ if (nCurrentODFVersion > SvtSaveOptions::ODFVER_012 && eDimension == XML_X)
+ {
+ chart2::ScaleData aScaleData(rChart2Axis->getScaleData());
+ bool bShiftedCatPos = aScaleData.ShiftedCategoryPosition;
+ if (sChartType == "com.sun.star.chart.BarDiagram" || sChartType == "com.sun.star.chart.StockDiagram")
+ {
+ if (!bShiftedCatPos)
+ rAxisProps->setPropertyValue("MajorOrigin", uno::makeAny(0.0));
+ }
+ else if (bShiftedCatPos)
+ rAxisProps->setPropertyValue("MajorOrigin", uno::makeAny(0.5));
+ }
+
lcl_exportNumberFormat( "NumberFormat", rAxisProps, mrExport );
aPropertyStates = mxExpPropMapper->Filter( rAxisProps );
@@ -2419,6 +2433,7 @@ void SchXMLExportHelper_Impl::exportAxes(
OUString aCategoriesRange;
Reference< chart::XAxisSupplier > xAxisSupp( xDiagram, uno::UNO_QUERY );
+ OUString sChartType = xDiagram->getDiagramType();
// x axis
@@ -2440,7 +2455,7 @@ void SchXMLExportHelper_Impl::exportAxes(
}
}
}
- exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasXAxisTitle, bHasXAxisMajorGrid, bHasXAxisMinorGrid, bExportContent );
+ exportAxis( XML_X, XML_PRIMARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasXAxisTitle, bHasXAxisMajorGrid, bHasXAxisMinorGrid, bExportContent, sChartType );
aCategoriesRange.clear();
}
@@ -2450,7 +2465,7 @@ void SchXMLExportHelper_Impl::exportAxes(
if( xNewAxis.is() )
{
Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getSecondaryAxis(0) : nullptr, uno::UNO_QUERY );
- exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryXAxisTitle, false, false, bExportContent );
+ exportAxis( XML_X, XML_SECONDARY_X, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryXAxisTitle, false, false, bExportContent, sChartType );
}
// y axis
@@ -2459,7 +2474,7 @@ void SchXMLExportHelper_Impl::exportAxes(
if( xNewAxis.is() )
{
Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(1) : nullptr, uno::UNO_QUERY );
- exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasYAxisTitle, bHasYAxisMajorGrid, bHasYAxisMinorGrid, bExportContent );
+ exportAxis( XML_Y, XML_PRIMARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasYAxisTitle, bHasYAxisMajorGrid, bHasYAxisMinorGrid, bExportContent, sChartType );
}
// secondary y axis
@@ -2468,7 +2483,7 @@ void SchXMLExportHelper_Impl::exportAxes(
if( xNewAxis.is() )
{
Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getSecondaryAxis(1) : nullptr, uno::UNO_QUERY );
- exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryYAxisTitle, false, false, bExportContent );
+ exportAxis( XML_Y, XML_SECONDARY_Y, xAxisProps, xNewAxis, aCategoriesRange, bHasSecondaryYAxisTitle, false, false, bExportContent, sChartType );
}
// z axis
@@ -2477,7 +2492,7 @@ void SchXMLExportHelper_Impl::exportAxes(
if( xNewAxis.is() )
{
Reference< beans::XPropertySet > xAxisProps( xAxisSupp.is() ? xAxisSupp->getAxis(2) : nullptr, uno::UNO_QUERY );
- exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xNewAxis, aCategoriesRange, bHasZAxisTitle, bHasZAxisMajorGrid, bHasZAxisMinorGrid, bExportContent );
+ exportAxis( XML_Z, XML_PRIMARY_Z, xAxisProps, xNewAxis, aCategoriesRange, bHasZAxisTitle, bHasZAxisMajorGrid, bHasZAxisMinorGrid, bExportContent, sChartType );
}
}
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index a9cf682e7d5d..253818ccf2df 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -1185,6 +1185,7 @@ namespace xmloff::token {
TOKEN( "maction", XML_MACTION ),
TOKEN( "main-entry-style-name", XML_MAIN_ENTRY_STYLE_NAME ),
TOKEN( "major", XML_MAJOR ),
+ TOKEN( "major-origin", XML_MAJOR_ORIGIN ),
TOKEN( "maligngroup", XML_MALIGNGROUP ),
TOKEN( "malignmark", XML_MALIGNMARK ),
TOKEN( "manual", XML_MANUAL ),
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index cd94bd5228d6..fd3806a7f0f2 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -1098,6 +1098,7 @@ macro-name
maction
main-entry-style-name
major
+major-origin
maligngroup
malignmark
manual