summaryrefslogtreecommitdiff
path: root/xmloff/source/chart/SchXMLPlotAreaContext.cxx
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2020-08-22 23:03:02 +0200
committerRegina Henschel <rb.henschel@t-online.de>2020-09-05 17:49:15 +0200
commit87d1ebeb11a00301745ee3c3c03fffb7033ab59d (patch)
treefb346833aab57cf5ef9544afd03aaddb6de8c0ec /xmloff/source/chart/SchXMLPlotAreaContext.cxx
parent23cf849bd699427889a99301d50ad52edec9d06d (diff)
tdf#135366 ODF import of line and fill of data labels
LibreOffice has line and fill properties of data labels in a chart in properties of kind "LabelBorderWidth" or "LabelFillColor" at a data point or, as defaults for the points, at a series. But ODF has such information in a <style:style> element, which is refered by a <chart:data-label> element. That one can be child of a <chart:data-point> and child of a <chart:series> element. Microsoft Office correctly uses the <chart:data-point> element and its style for the line and fill properties of data labels. Up to now LO cannot import such information and does not write the ODF elements. Instead LibreOffice reads and writes attributes in 'loext' namespace. Using the "LabelFoo" properties was implemented by Kohei Yoshida, July 2014. Although there is no published service, these properties can be used in macros. Because they are now available since six years, the decision was to keep this internal model and convert on import and export. This patch implements the import of the ODF fill and line properties from the <chart:data-label> element and converts them to the internal used properties. LibreOffice has currently only implemented a few of the possible line and fill properties. When more are implemented, their <ODF,LabelFoo> pairs need to be added to the array aApiToLabelFooPairs, further adaptions are not needed. The <chart:data-label> contains in addition the absolute position of a data label. LibreOffice has internally only a position offset relative to the regular position of the label. The conversion of the position is not included in the patch. Change-Id: I5fd868945585971dac3dd945804a4a2951b8c12d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101194 Tested-by: Jenkins Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'xmloff/source/chart/SchXMLPlotAreaContext.cxx')
-rw-r--r--xmloff/source/chart/SchXMLPlotAreaContext.cxx62
1 files changed, 55 insertions, 7 deletions
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
index 02eb8a2f0f42..8782ef7818ff 100644
--- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx
+++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
@@ -616,9 +616,12 @@ SvXMLImportContextRef SchXMLDataLabelParaContext::CreateChildContext(
return xContext;
}
-SchXMLDataLabelContext::SchXMLDataLabelContext( SvXMLImport& rImport, const OUString& rLocalName, ::std::vector<OUString>& rLabels):
- SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName),
- mrLabels(rLabels)
+SchXMLDataLabelContext::SchXMLDataLabelContext(SvXMLImport& rImport, const OUString& rLocalName,
+ ::std::vector<OUString>& rLabels,
+ DataRowPointStyle& rDataLabelStyle)
+ : SvXMLImportContext(rImport, XML_NAMESPACE_CHART, rLocalName)
+ , mrLabels(rLabels)
+ , mrDataLabelStyle(rDataLabelStyle)
{
}
@@ -634,6 +637,42 @@ SvXMLImportContextRef SchXMLDataLabelContext::CreateChildContext(
return xContext;
}
+void SchXMLDataLabelContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+{
+ const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
+ const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
+ for (sal_Int16 i = 0; i < nAttrCount; i++)
+ {
+ const OUString& rAttrName = xAttrList->getNameByIndex(i);
+ OUString aLocalName;
+ sal_uInt16 nPrefix = rMap.GetKeyByAttrName(rAttrName, &aLocalName);
+ const OUString sValue(xAttrList->getValueByIndex(i));
+
+ if (nPrefix == XML_NAMESPACE_SVG)
+ {
+ if (IsXMLToken(aLocalName, XML_X))
+ {
+ sal_Int32 nResultValue;
+ GetImport().GetMM100UnitConverter().convertMeasureToCore(nResultValue, sValue);
+ mrDataLabelStyle.mo_nLabelAbsolutePosX = nResultValue;
+ }
+ else if (IsXMLToken(aLocalName, XML_Y))
+ {
+ sal_Int32 nResultValue;
+ GetImport().GetMM100UnitConverter().convertMeasureToCore(nResultValue, sValue);
+ mrDataLabelStyle.mo_nLabelAbsolutePosY = nResultValue;
+ }
+ }
+ else if (nPrefix == XML_NAMESPACE_CHART)
+ {
+ if (IsXMLToken(aLocalName, XML_STYLE_NAME))
+ {
+ mrDataLabelStyle.msStyleName = sValue;
+ }
+ }
+ }
+}
+
SchXMLDataPointContext::SchXMLDataPointContext( SchXMLImportHelper& rImportHelper,
SvXMLImport& rImport, const OUString& rLocalName,
@@ -645,7 +684,8 @@ SchXMLDataPointContext::SchXMLDataPointContext( SchXMLImportHelper& rImportHelp
mrImportHelper( rImportHelper ),
mrStyleVector( rStyleVector ),
mrIndex( rIndex ),
- mDataPoint(DataRowPointStyle::DATA_POINT, xSeries, rIndex, 1, OUString{})
+ mDataPoint(DataRowPointStyle::DATA_POINT, xSeries, rIndex, 1, OUString{}),
+ mDataLabel(DataRowPointStyle::DATA_LABEL_POINT, xSeries, rIndex, 1, OUString{})
{
mDataPoint.mbSymbolSizeForSeriesIsMissingInFile = bSymbolSizeForSeriesIsMissingInFile;
}
@@ -662,7 +702,8 @@ SvXMLImportContextRef SchXMLDataPointContext::CreateChildContext(
{
case XML_TOK_SERIES_DATA_LABEL:
mbHasLabelParagraph = true;
- pContext = new SchXMLDataLabelContext( GetImport(), rLocalName, mDataPoint.mCustomLabels);
+ pContext = new SchXMLDataLabelContext(GetImport(), rLocalName, mDataPoint.mCustomLabels,
+ mDataLabel);
break;
}
return pContext;
@@ -692,11 +733,13 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
{
sAutoStyleName = xAttrList->getValueByIndex( i );
mDataPoint.msStyleName = sAutoStyleName;
+ mDataLabel.msStyleNameOfParent = sAutoStyleName;
}
else if( IsXMLToken( aLocalName, XML_REPEATED ) )
{
nRepeat = xAttrList->getValueByIndex( i ).toInt32();
mDataPoint.m_nPointRepeat = nRepeat;
+ mDataLabel.m_nPointRepeat = nRepeat;
}
}
else if( nPrefix == XML_NAMESPACE_LO_EXT)
@@ -741,9 +784,14 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
void SchXMLDataPointContext::EndElement()
{
- if( !mDataPoint.msStyleName.isEmpty() || mDataPoint.mCustomLabels.size() > 0)
+ if(!mDataPoint.msStyleName.isEmpty() || mDataPoint.mCustomLabels.size() > 0)
+ {
+ mrStyleVector.push_back(mDataPoint);
+ }
+ if (!mDataLabel.msStyleName.isEmpty() || mDataLabel.mo_nLabelAbsolutePosX.has_value()
+ || mDataLabel.mo_nLabelAbsolutePosY.has_value())
{
- mrStyleVector.push_back( mDataPoint );
+ mrStyleVector.push_back(mDataLabel);
}
}