diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-07-30 08:52:44 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-08-02 21:22:43 +0200 |
commit | c8d8bf4282cbd04abacfa69ba2cc0fa4300e35e1 (patch) | |
tree | 270fcf114ac38a4d1b374b6837fa4cc6c9c5d649 /xmloff/source | |
parent | 2d96d69322ac18f53668b75397c8587f94cd043b (diff) |
sc: theme color support for sparklines + ODF & OOXML import/export
This changes Sparkline colors to use complex colors instead and
adds Sparkline theme color import and export support for ODF and
OOXML.
Change-Id: I58edd525d50f95199bd4fe7825afb51aaa7fc091
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155113
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmloff/source')
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 14 | ||||
-rw-r--r-- | xmloff/source/draw/XMLShapePropertySetContext.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/style/StylePropertiesContext.cxx | 3 | ||||
-rw-r--r-- | xmloff/source/text/XMLComplexColorContext.cxx | 69 | ||||
-rw-r--r-- | xmloff/source/text/XMLComplexColorExport.cxx | 35 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextPropertySetContext.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextShapeStyleContext.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 14 |
8 files changed, 104 insertions, 37 deletions
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 2ecc3ea5ce7b..6564a2b866d7 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -1813,10 +1813,18 @@ namespace xmloff::token { TOKEN( "source-range-address", XML_SOURCE_RANGE_ADDRESS ), TOKEN( "source-service", XML_SOURCE_SERVICE ), TOKEN( "space-before", XML_SPACE_BEFORE ), - TOKEN( "sparkline-groups", XML_SPARKLINE_GROUPS ), - TOKEN( "sparkline-group", XML_SPARKLINE_GROUP ), - TOKEN( "sparklines", XML_SPARKLINES ), TOKEN( "sparkline", XML_SPARKLINE ), + TOKEN( "sparklines", XML_SPARKLINES ), + TOKEN( "sparkline-axis-complex-color", XML_SPARKLINE_AXIS_COMPLEX_COLOR), + TOKEN( "sparkline-first-complex-color", XML_SPARKLINE_FIRST_COMPLEX_COLOR), + TOKEN( "sparkline-group", XML_SPARKLINE_GROUP ), + TOKEN( "sparkline-groups", XML_SPARKLINE_GROUPS ), + TOKEN( "sparkline-high-complex-color", XML_SPARKLINE_HIGH_COMPLEX_COLOR), + TOKEN( "sparkline-last-complex-color", XML_SPARKLINE_LAST_COMPLEX_COLOR), + TOKEN( "sparkline-low-complex-color", XML_SPARKLINE_LOW_COMPLEX_COLOR), + TOKEN( "sparkline-markers-complex-color", XML_SPARKLINE_MARKERS_COMPLEX_COLOR), + TOKEN( "sparkline-negative-complex-color", XML_SPARKLINE_NEGATIVE_COMPLEX_COLOR), + TOKEN( "sparkline-series-complex-color", XML_SPARKLINE_SERIES_COMPLEX_COLOR), TOKEN( "span", XML_SPAN ), TOKEN( "specular", XML_SPECULAR ), TOKEN( "specular-color", XML_SPECULAR_COLOR ), diff --git a/xmloff/source/draw/XMLShapePropertySetContext.cxx b/xmloff/source/draw/XMLShapePropertySetContext.cxx index 42cff9db52d8..40287e6516e0 100644 --- a/xmloff/source/draw/XMLShapePropertySetContext.cxx +++ b/xmloff/source/draw/XMLShapePropertySetContext.cxx @@ -84,7 +84,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLShapePropertySetCon return new XMLTextColumnsContext(GetImport(), nElement, xAttrList, rProp, rProperties); case CTF_COMPLEX_COLOR: - return new XMLComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); + return new XMLPropertyComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); } return SvXMLPropertySetContext::createFastChildContext( nElement, diff --git a/xmloff/source/style/StylePropertiesContext.cxx b/xmloff/source/style/StylePropertiesContext.cxx index 1bda191485e6..910b7873d54f 100644 --- a/xmloff/source/style/StylePropertiesContext.cxx +++ b/xmloff/source/style/StylePropertiesContext.cxx @@ -35,7 +35,8 @@ StylePropertiesContext::createFastChildContext( { if (nElement == XML_ELEMENT(LO_EXT, XML_CHAR_COMPLEX_COLOR)) { - return new XMLComplexColorContext(GetImport(), nElement, xAttrList, rProperty, rProperties); + return new XMLPropertyComplexColorContext(GetImport(), nElement, xAttrList, rProperty, + rProperties); } return SvXMLPropertySetContext::createFastChildContext(nElement, xAttrList, rProperties, rProperty); diff --git a/xmloff/source/text/XMLComplexColorContext.cxx b/xmloff/source/text/XMLComplexColorContext.cxx index 39b8687cbc51..7b4e299f95e6 100644 --- a/xmloff/source/text/XMLComplexColorContext.cxx +++ b/xmloff/source/text/XMLComplexColorContext.cxx @@ -19,6 +19,7 @@ #include <xmloff/xmlement.hxx> #include <xmloff/xmlprhdl.hxx> #include <xmloff/XMLComplexColorContext.hxx> +#include <docmodel/uno/UnoComplexColor.hxx> using namespace css; using namespace xmloff::token; @@ -38,12 +39,13 @@ SvXMLEnumMapEntry<sal_Int16> const pXML_ThemeColor_Enum[] = { { XML_NONE, -1 }, { XML_FOLLOWED_HYPERLINK, 11 }, { XML_TOKEN_INVALID, 0 } }; -XMLComplexColorContext::XMLComplexColorContext( - SvXMLImport& rImport, sal_Int32 nElement, - const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, const XMLPropertyState& rProp, - std::vector<XMLPropertyState>& rProps) - : XMLElementPropertyContext(rImport, nElement, rProp, rProps) - , mnRootElement(nElement) +XMLComplexColorImport::XMLComplexColorImport(model::ComplexColor& rComplexColor) + : mrComplexColor(rComplexColor) +{ +} + +void XMLComplexColorImport::fillAttributes( + const uno::Reference<xml::sax::XFastAttributeList>& xAttrList) { for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList)) { @@ -54,7 +56,7 @@ XMLComplexColorContext::XMLComplexColorContext( sal_Int16 nValue = -1; if (SvXMLUnitConverter::convertEnum(nValue, aIter.toView(), pXML_ThemeColor_Enum)) { - maComplexColor.setSchemeColor(model::convertToThemeColorType(nValue)); + mrComplexColor.setSchemeColor(model::convertToThemeColorType(nValue)); } break; } @@ -62,7 +64,7 @@ XMLComplexColorContext::XMLComplexColorContext( { const OUString aValue = aIter.toString(); if (aValue == u"theme") - maComplexColor.setType(model::ColorType::Scheme); + mrComplexColor.setType(model::ColorType::Scheme); // TODO - handle other color types break; } @@ -73,8 +75,7 @@ XMLComplexColorContext::XMLComplexColorContext( } } -css::uno::Reference<css::xml::sax::XFastContextHandler> -XMLComplexColorContext::createFastChildContext( +bool XMLComplexColorImport::handleTransformContext( sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) { if (nElement == XML_ELEMENT(LO_EXT, XML_TRANSFORMATION)) @@ -110,24 +111,62 @@ XMLComplexColorContext::createFastChildContext( break; } } - maComplexColor.addTransformation({ eTransformationType, nTransformationValue }); - return this; + mrComplexColor.addTransformation({ eTransformationType, nTransformationValue }); + return true; } XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); + return false; +} + +XMLPropertyComplexColorContext::XMLPropertyComplexColorContext( + SvXMLImport& rImport, sal_Int32 nElement, + const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, const XMLPropertyState& rProp, + std::vector<XMLPropertyState>& rProps) + : XMLElementPropertyContext(rImport, nElement, rProp, rProps) + , mnRootElement(nElement) + , maComplexColorImport(maComplexColor) +{ + maComplexColorImport.fillAttributes(xAttrList); +} + +css::uno::Reference<css::xml::sax::XFastContextHandler> +XMLPropertyComplexColorContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) +{ + if (maComplexColorImport.handleTransformContext(nElement, xAttrList)) + return this; return nullptr; } -void XMLComplexColorContext::endFastElement(sal_Int32 nElement) +void XMLPropertyComplexColorContext::endFastElement(sal_Int32 nElement) { if (nElement == mnRootElement) { - if (maComplexColor.getSchemeType() != model::ThemeColorType::Unknown) + if (getComplexColor().getSchemeType() != model::ThemeColorType::Unknown) { - aProp.maValue <<= model::color::createXComplexColor(maComplexColor); + aProp.maValue <<= model::color::createXComplexColor(getComplexColor()); SetInsert(true); } } XMLElementPropertyContext::endFastElement(nElement); } +XMLComplexColorContext::XMLComplexColorContext( + SvXMLImport& rImport, model::ComplexColor& rComplexColor, + const uno::Reference<xml::sax::XFastAttributeList>& xAttrList) + : SvXMLImportContext(rImport) + , maComplexColorImport(rComplexColor) +{ + maComplexColorImport.fillAttributes(xAttrList); +} + +css::uno::Reference<css::xml::sax::XFastContextHandler> +XMLComplexColorContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) +{ + if (maComplexColorImport.handleTransformContext(nElement, xAttrList)) + return this; + return nullptr; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLComplexColorExport.cxx b/xmloff/source/text/XMLComplexColorExport.cxx index 6d950dff3051..4465e0d74585 100644 --- a/xmloff/source/text/XMLComplexColorExport.cxx +++ b/xmloff/source/text/XMLComplexColorExport.cxx @@ -12,7 +12,6 @@ #include <sal/config.h> #include <docmodel/uno/UnoComplexColor.hxx> -#include <xmloff/xmltoken.hxx> #include <xmloff/xmlnamespace.hxx> #include <xmloff/xmluconv.hxx> #include <xmloff/xmlexp.hxx> @@ -34,24 +33,18 @@ constexpr const std::array<XMLTokenEnum, 12> constThemeColorTypeToToken{ }; } -void XMLComplexColorExport::exportXML(const uno::Any& rAny, sal_uInt16 nPrefix, - const OUString& rLocalName) +void XMLComplexColorExport::doExport(model::ComplexColor const& rComplexColor, sal_uInt16 nPrefix, + const OUString& rLocalName) { - uno::Reference<util::XComplexColor> xComplexColor; - rAny >>= xComplexColor; - if (!xComplexColor.is()) + if (rComplexColor.getSchemeType() == model::ThemeColorType::Unknown) return; - model::ComplexColor aComplexColor = model::color::getFromXComplexColor(xComplexColor); - if (aComplexColor.getSchemeType() == model::ThemeColorType::Unknown) - return; - - XMLTokenEnum nToken = constThemeColorTypeToToken[sal_Int16(aComplexColor.getSchemeType())]; + XMLTokenEnum nToken = constThemeColorTypeToToken[sal_Int16(rComplexColor.getSchemeType())]; mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_THEME_TYPE, nToken); mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR_TYPE, "theme"); SvXMLElementExport aComplexColorElement(mrExport, nPrefix, rLocalName, true, true); - for (auto const& rTransform : aComplexColor.getTransformations()) + for (auto const& rTransform : rComplexColor.getTransformations()) { OUString aType; switch (rTransform.meType) @@ -82,4 +75,22 @@ void XMLComplexColorExport::exportXML(const uno::Any& rAny, sal_uInt16 nPrefix, } } +void XMLComplexColorExport::exportComplexColor(model::ComplexColor const& rComplexColor, + sal_uInt16 nPrefix, XMLTokenEnum nToken) +{ + doExport(rComplexColor, nPrefix, GetXMLToken(nToken)); +} + +void XMLComplexColorExport::exportXML(const uno::Any& rAny, sal_uInt16 nPrefix, + const OUString& rLocalName) +{ + uno::Reference<util::XComplexColor> xComplexColor; + rAny >>= xComplexColor; + if (!xComplexColor.is()) + return; + + model::ComplexColor aComplexColor = model::color::getFromXComplexColor(xComplexColor); + doExport(aComplexColor, nPrefix, rLocalName); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLTextPropertySetContext.cxx b/xmloff/source/text/XMLTextPropertySetContext.cxx index bfe18db611cd..472001287e05 100644 --- a/xmloff/source/text/XMLTextPropertySetContext.cxx +++ b/xmloff/source/text/XMLTextPropertySetContext.cxx @@ -70,7 +70,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextPropertySetCont break; case CTF_COMPLEX_COLOR: - return new XMLComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); + return new XMLPropertyComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); break; case CTF_DROPCAPFORMAT: diff --git a/xmloff/source/text/XMLTextShapeStyleContext.cxx b/xmloff/source/text/XMLTextShapeStyleContext.cxx index 729a94211e6a..52574c10d650 100644 --- a/xmloff/source/text/XMLTextShapeStyleContext.cxx +++ b/xmloff/source/text/XMLTextShapeStyleContext.cxx @@ -91,7 +91,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapePropertySe break; case CTF_COMPLEX_COLOR: - return new XMLComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); + return new XMLPropertyComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); case CTF_BACKGROUND_URL: DBG_ASSERT( rProp.mnIndex >= 3 && diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 3dd0ab102f4d..f700d2ac11ad 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -1713,10 +1713,18 @@ source-name source-range-address source-service space-before -sparkline-groups -sparkline-group -sparklines sparkline +sparklines +sparkline-axis-complex-color +sparkline-first-complex-color +sparkline-group +sparkline-groups +sparkline-high-complex-color +sparkline-last-complex-color +sparkline-low-complex-color +sparkline-markers-complex-color +sparkline-negative-complex-color +sparkline-series-complex-color span specular specular-color |