dev/null |binary include/toolkit/awt/vclxfont.hxx | 7 include/xmloff/txtprmap.hxx | 2 include/xmloff/xmltoken.hxx | 8 oox/qa/unit/data/ReferenceShapeFill.odp |binary oox/qa/unit/export.cxx | 21 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng | 87 ++- toolkit/source/awt/vclxfont.cxx | 3 toolkit/source/helper/vclunohelper.cxx | 2 xmloff/CppunitTest_xmloff_draw.mk | 1 xmloff/CppunitTest_xmloff_uxmloff.mk | 1 xmloff/Library_xo.mk | 3 xmloff/inc/XMLThemeColorContext.hxx | 33 + xmloff/inc/XMLThemeColorExport.hxx | 30 + xmloff/inc/XMLThemeColorHandler.hxx | 39 - xmloff/inc/xmlprop.hxx | 8 xmloff/qa/unit/data/Reference-ThemeColors-TextAndFill.pptx |binary xmloff/qa/unit/data/ReferenceShapeFill.pptx |binary xmloff/qa/unit/draw.cxx | 268 +++++++++--- xmloff/source/core/xmltoken.cxx | 8 xmloff/source/draw/XMLShapePropertySetContext.cxx | 4 xmloff/source/draw/sdpropls.cxx | 4 xmloff/source/style/PagePropertySetContext.cxx | 4 xmloff/source/text/XMLTextPropertySetContext.cxx | 6 xmloff/source/text/XMLTextShapeStyleContext.cxx | 4 xmloff/source/text/XMLThemeColorContext.cxx | 116 +++++ xmloff/source/text/XMLThemeColorExport.cxx | 85 +++ xmloff/source/text/txtexppr.cxx | 7 xmloff/source/text/txtexppr.hxx | 2 xmloff/source/text/txtprhdl.cxx | 18 xmloff/source/text/txtprmap.cxx | 9 xmloff/source/token/tokens.txt | 8 32 files changed, 604 insertions(+), 184 deletions(-)
New commits: commit 3eb53d327fb5d9689b799ff991a6c53c05eff496 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Dec 31 20:59:03 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Jan 13 13:44:09 2023 +0000 xmloff: use XThemeColor in ODF, change the format for themes Change the xmloff filter to use XThemeColor and the associated proprties (CharColorThemeReference and FillColorThemeReference). Change the ODF format for referencing a theme color - make it an element instead a series of attributes on the *-properties style element. Change-Id: I0fa7d8ebffecc02897b7fe9824d6f1776ef36380 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144923 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/xmloff/txtprmap.hxx b/include/xmloff/txtprmap.hxx index 37c0d7a9f330..986bbd007d8a 100644 --- a/include/xmloff/txtprmap.hxx +++ b/include/xmloff/txtprmap.hxx @@ -202,7 +202,7 @@ #define CTF_FILLSTYLE (XML_TEXT_CTF_START + 173) #define CTF_FILLCOLOR (XML_TEXT_CTF_START + 174) #define CTF_PAGENUMBEROFFSET (XML_TEXT_CTF_START + 175) - +#define CTF_THEME_COLOR (XML_TEXT_CTF_START + 176) enum class TextPropMap { TEXT = 0, diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index 34bcf3099048..e33a39deb449 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -3481,8 +3481,8 @@ namespace xmloff::token { XML_LINKED_STYLE_NAME, XML_THEME, - XML_THEME_COLOR, - XML_FILL_THEME_COLOR, + XML_CHAR_COLOR_THEME_REFERENCE, + XML_FILL_COLOR_THEME_REFERENCE, XML_DK1, XML_LT1, XML_DK2, @@ -3495,10 +3495,6 @@ namespace xmloff::token { XML_ACCENT6, XML_HLINK, XML_FOLHLINK, - XML_COLOR_LUM_MOD, - XML_COLOR_LUM_OFF, - XML_FILL_COLOR_LUM_MOD, - XML_FILL_COLOR_LUM_OFF, XML_CONTENT_CONTROL, XML_SHOWING_PLACE_HOLDER, diff --git a/oox/qa/unit/data/ReferenceShapeFill.odp b/oox/qa/unit/data/ReferenceShapeFill.odp new file mode 100644 index 000000000000..91544d20b302 Binary files /dev/null and b/oox/qa/unit/data/ReferenceShapeFill.odp differ diff --git a/oox/qa/unit/data/refer-to-theme-shape-fill.odp b/oox/qa/unit/data/refer-to-theme-shape-fill.odp deleted file mode 100644 index 3a32aa71690a..000000000000 Binary files a/oox/qa/unit/data/refer-to-theme-shape-fill.odp and /dev/null differ diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx index 289bdf49611c..fdf97b328f45 100644 --- a/oox/qa/unit/export.cxx +++ b/oox/qa/unit/export.cxx @@ -353,27 +353,20 @@ CPPUNIT_TEST_FIXTURE(Test, testReferToTheme) assertXPath(pXmlDoc, "//p:sp[3]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumOff", 0); } -CPPUNIT_TEST_FIXTURE(Test, testReferToThemeShapeFill) +CPPUNIT_TEST_FIXTURE(Test, testThemeColor_ShapeFill) { // Given an ODP file that contains references to a theme for shape fill: - loadFromURL(u"refer-to-theme-shape-fill.odp"); + loadFromURL(u"ReferenceShapeFill.odp"); // When saving that document: save("Impress Office Open XML"); - // Then make sure the shape fill color is a scheme color: - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 1 - // - Actual : 0 - // i.e. the <a:schemeClr> element was not written. Note that this was already working from PPTX - // files via grab-bags, so this test intentionally uses an ODP file as input. + // Then make sure the shape fill color is a scheme color. + // Note that this was already working from PPTX files via grab-bags, + //so this test intentionally uses an ODP file as input. xmlDocUniquePtr pXmlDoc = parseExport("ppt/slides/slide1.xml"); - assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr", "val", "accent1"); - // Without the accompanying fix in place, this test would have failed with: - // - XPath '//p:sp[1]/p:spPr/a:solidFill/a:schemeClr/a:lumMod' number of nodes is incorrect - // i.e. the effects of the themed color were lost. - assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr/a:lumMod", "val", "40000"); - assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr/a:lumOff", "val", "60000"); + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr", "val", "accent6"); + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr/a:lumMod", "val", "75000"); } CPPUNIT_TEST_FIXTURE(Test, testTdf146690_endParagraphRunPropertiesNewLinesTextSize) diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index 24b062c2f839..682d93dfe6e9 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -1798,22 +1798,6 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. <rng:ref name="color"/> </rng:attribute> </rng:optional> - <!-- TODO(vmiklos) no proposal for theme color of shape fill --> - <rng:optional> - <rng:attribute name="loext:fill-theme-color"> - <rng:ref name="theme-color"/> - </rng:attribute> - </rng:optional> - <rng:optional> - <rng:attribute name="loext:fill-color-lum-mod"> - <rng:ref name="zeroToHundredPercent"/> - </rng:attribute> - </rng:optional> - <rng:optional> - <rng:attribute name="loext:fill-color-lum-off"> - <rng:ref name="zeroToHundredPercent"/> - </rng:attribute> - </rng:optional> <rng:optional> <rng:attribute name="draw:secondary-fill-color"> <rng:ref name="color"/> @@ -2310,22 +2294,6 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. <rng:ref name="zeroToHundredPercent"/> </rng:attribute> </rng:optional> - <!-- TODO(vmiklos) no proposal for theme color of shape text --> - <rng:optional> - <rng:attribute name="loext:theme-color"> - <rng:ref name="theme-color"/> - </rng:attribute> - </rng:optional> - <rng:optional> - <rng:attribute name="loext:color-lum-mod"> - <rng:ref name="zeroToHundredPercent"/> - </rng:attribute> - </rng:optional> - <rng:optional> - <rng:attribute name="loext:color-lum-off"> - <rng:ref name="zeroToHundredPercent"/> - </rng:attribute> - </rng:optional> </rng:define> <rng:define name="style-text-properties-attlist" combine="interleave"> @@ -3297,6 +3265,8 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. </rng:optional> </rng:element> </rng:define> + + <!-- Theme Elements --> <rng:define name="theme-color"> <rng:choice> <!-- Background 1 --> @@ -3320,6 +3290,59 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. </rng:choice> </rng:define> + <rng:define name="loext-transformation"> + <rng:element name="loext:transformation"> + <rng:attribute name="loext:type"> + <rng:ref name="string"/> + </rng:attribute> + <rng:attribute name="loext:value"> + <rng:ref name="integer"/> + </rng:attribute> + </rng:element> + </rng:define> + + <rng:define name="loext-theme-color-reference-attlist"> + <rng:interleave> + <rng:optional> + <rng:attribute name="loext:type"> + <rng:ref name="theme-color"/> + </rng:attribute> + </rng:optional> + </rng:interleave> + </rng:define> + + <rng:define name="loext-char-color-theme-reference"> + <rng:element name="loext:char-color-theme-reference"> + <rng:ref name="loext-theme-color-reference-attlist"/> + <rng:zeroOrMore> + <rng:ref name="loext-transformation"/> + </rng:zeroOrMore> + </rng:element> + </rng:define> + + <rng:define name="loext-fill-color-theme-reference"> + <rng:element name="loext:fill-color-theme-reference"> + <rng:ref name="loext-theme-color-reference-attlist"/> + <rng:zeroOrMore> + <rng:ref name="loext-transformation"/> + </rng:zeroOrMore> + </rng:element> + </rng:define> + + <!-- TODO no proposal --> + <rng:define name="style-text-properties-elements" combine="interleave"> + <rng:optional> + <rng:ref name="loext-char-color-theme-reference"/> + </rng:optional> + </rng:define> + + <!-- TODO no proposal --> + <rng:define name="style-graphic-properties-elements" combine="interleave"> + <rng:optional> + <rng:ref name="loext-fill-color-theme-reference"/> + </rng:optional> + </rng:define> + <!-- https://issues.oasis-open.org/browse/OFFICE-4136 --> <rng:define name="draw-frame-attlist" combine="interleave"> <rng:optional> diff --git a/xmloff/CppunitTest_xmloff_draw.mk b/xmloff/CppunitTest_xmloff_draw.mk index 8e842e6da32b..b495604ba785 100644 --- a/xmloff/CppunitTest_xmloff_draw.mk +++ b/xmloff/CppunitTest_xmloff_draw.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_draw, \ comphelper \ cppu \ cppuhelper \ + docmodel \ embobj \ sal \ subsequenttest \ diff --git a/xmloff/CppunitTest_xmloff_uxmloff.mk b/xmloff/CppunitTest_xmloff_uxmloff.mk index eaa83d554a92..35a270191717 100644 --- a/xmloff/CppunitTest_xmloff_uxmloff.mk +++ b/xmloff/CppunitTest_xmloff_uxmloff.mk @@ -41,6 +41,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_uxmloff, \ comphelper \ cppu \ cppuhelper \ + docmodel \ i18nlangtag \ sal \ salhelper \ diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index 14401f9eea8f..19c9db439e62 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -55,6 +55,7 @@ $(eval $(call gb_Library_use_libraries,xo,\ comphelper \ cppu \ cppuhelper \ + docmodel \ i18nlangtag \ sal \ salhelper \ @@ -339,6 +340,8 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/text/XMLTextCharStyleNamesElementExport \ xmloff/source/text/XMLTextColumnsContext \ xmloff/source/text/XMLTextColumnsExport \ + xmloff/source/text/XMLThemeColorContext \ + xmloff/source/text/XMLThemeColorExport \ xmloff/source/text/XMLTextFrameContext \ xmloff/source/text/XMLTextFrameHyperlinkContext \ xmloff/source/text/XMLTextHeaderFooterContext \ diff --git a/xmloff/inc/XMLThemeColorContext.hxx b/xmloff/inc/XMLThemeColorContext.hxx new file mode 100644 index 000000000000..444de3b15588 --- /dev/null +++ b/xmloff/inc/XMLThemeColorContext.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <memory> +#include "XMLElementPropertyContext.hxx" +#include <docmodel/uno/UnoThemeColor.hxx> + +class XMLThemeColorContext final : public XMLElementPropertyContext +{ + model::ThemeColor aThemeColor; + sal_Int32 mnRootElement; + +public: + XMLThemeColorContext(SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList, + const XMLPropertyState& rProp, std::vector<XMLPropertyState>& rProps); + + css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList>& AttrList) override; + + void SAL_CALL endFastElement(sal_Int32 nElement) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/inc/XMLThemeColorExport.hxx b/xmloff/inc/XMLThemeColorExport.hxx new file mode 100644 index 000000000000..9a360c2782d2 --- /dev/null +++ b/xmloff/inc/XMLThemeColorExport.hxx @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#pragma once + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +namespace com::sun::star::uno +{ +class Any; +} +class SvXMLExport; + +class XMLThemeColorExport +{ + SvXMLExport& mrExport; + +public: + XMLThemeColorExport(SvXMLExport& rExport); + + void exportXML(const css::uno::Any& rAny, sal_uInt16 nPrefix, const OUString& rLocalName); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/inc/XMLThemeColorHandler.hxx b/xmloff/inc/XMLThemeColorHandler.hxx index d505935f7127..2ede6f182048 100644 --- a/xmloff/inc/XMLThemeColorHandler.hxx +++ b/xmloff/inc/XMLThemeColorHandler.hxx @@ -9,39 +9,38 @@ #pragma once -#include <xmloff/xmlprhdl.hxx> +#include <docmodel/uno/UnoThemeColor.hxx> using namespace ::xmloff::token; +using namespace css; class XMLThemeColorHandler : public XMLPropertyHandler { public: - bool importXML(const OUString& rStrImpValue, css::uno::Any& rValue, + bool importXML(const OUString& /*rStrImpValue*/, css::uno::Any& /*rValue*/, const SvXMLUnitConverter&) const override { - sal_Int16 nValue; - bool bReturn = SvXMLUnitConverter::convertEnum(nValue, rStrImpValue, pXML_ThemeColor_Enum); - - if (bReturn) - rValue <<= nValue; - - return bReturn; + return false; } - bool exportXML(OUString& rStrExpValue, const css::uno::Any& rValue, + bool exportXML(OUString& /*rStrExpValue*/, const css::uno::Any& /*rValue*/, const SvXMLUnitConverter&) const override { - sal_Int16 nThemeIndex; - - if (!(rValue >>= nThemeIndex) || nThemeIndex == -1) // Default - return false; - - OUStringBuffer aOutBuffer; - bool bReturn = SvXMLUnitConverter::convertEnum(aOutBuffer, nThemeIndex, - pXML_ThemeColor_Enum, XML_NONE); - rStrExpValue = aOutBuffer.makeStringAndClear(); + return false; + } - return bReturn; + bool equals(const css::uno::Any& rAny1, const css::uno::Any& rAny2) const override + { + uno::Reference<util::XThemeColor> xThemeColor1; + uno::Reference<util::XThemeColor> xThemeColor2; + rAny1 >>= xThemeColor1; + rAny2 >>= xThemeColor2; + model::ThemeColor aThemeColor1; + model::ThemeColor aThemeColor2; + model::theme::setFromXThemeColor(aThemeColor1, xThemeColor1); + model::theme::setFromXThemeColor(aThemeColor2, xThemeColor2); + + return aThemeColor1 == aThemeColor2; } }; diff --git a/xmloff/inc/xmlprop.hxx b/xmloff/inc/xmlprop.hxx index f3629c228623..27adbde570d7 100644 --- a/xmloff/inc/xmlprop.hxx +++ b/xmloff/inc/xmlprop.hxx @@ -56,9 +56,7 @@ inline constexpr OUStringLiteral PROP_CharBottomBorder = u"CharBottomBorder"; inline constexpr OUStringLiteral PROP_CharBottomBorderDistance = u"CharBottomBorderDistance"; inline constexpr OUStringLiteral PROP_CharCaseMap = u"CharCaseMap"; inline constexpr OUStringLiteral PROP_CharColor = u"CharColor"; -inline constexpr OUStringLiteral PROP_CharColorLumMod = u"CharColorLumMod"; -inline constexpr OUStringLiteral PROP_CharColorLumOff = u"CharColorLumOff"; -inline constexpr OUStringLiteral PROP_CharColorTheme = u"CharColorTheme"; +inline constexpr OUStringLiteral PROP_CharColorThemeReference = u"CharColorThemeReference"; inline constexpr OUStringLiteral PROP_CharCombineIsOn = u"CharCombineIsOn"; inline constexpr OUStringLiteral PROP_CharCombinePrefix = u"CharCombinePrefix"; inline constexpr OUStringLiteral PROP_CharCombineSuffix = u"CharCombineSuffix"; @@ -209,9 +207,7 @@ inline constexpr OUStringLiteral PROP_FillBitmapSizeX = u"FillBitmapSizeX"; inline constexpr OUStringLiteral PROP_FillBitmapSizeY = u"FillBitmapSizeY"; inline constexpr OUStringLiteral PROP_FillColor = u"FillColor"; inline constexpr OUStringLiteral PROP_FillColor2 = u"FillColor2"; -inline constexpr OUStringLiteral PROP_FillColorLumMod = u"FillColorLumMod"; -inline constexpr OUStringLiteral PROP_FillColorLumOff = u"FillColorLumOff"; -inline constexpr OUStringLiteral PROP_FillColorTheme = u"FillColorTheme"; +inline constexpr OUStringLiteral PROP_FillColorThemeReference = u"FillColorThemeReference"; inline constexpr OUStringLiteral PROP_FillGradientName = u"FillGradientName"; inline constexpr OUStringLiteral PROP_FillGradientStepCount = u"FillGradientStepCount"; inline constexpr OUStringLiteral PROP_FillHatchName = u"FillHatchName"; diff --git a/xmloff/qa/unit/data/Reference-ThemeColors-TextAndFill.pptx b/xmloff/qa/unit/data/Reference-ThemeColors-TextAndFill.pptx new file mode 100644 index 000000000000..b2319fe6ea9c Binary files /dev/null and b/xmloff/qa/unit/data/Reference-ThemeColors-TextAndFill.pptx differ diff --git a/xmloff/qa/unit/data/ReferenceShapeFill.pptx b/xmloff/qa/unit/data/ReferenceShapeFill.pptx new file mode 100644 index 000000000000..782a54d7b2c1 Binary files /dev/null and b/xmloff/qa/unit/data/ReferenceShapeFill.pptx differ diff --git a/xmloff/qa/unit/data/refer-to-theme.odp b/xmloff/qa/unit/data/refer-to-theme.odp deleted file mode 100644 index 2c413ef766f9..000000000000 Binary files a/xmloff/qa/unit/data/refer-to-theme.odp and /dev/null differ diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx index b3643551995a..d66a96e1350c 100644 --- a/xmloff/qa/unit/draw.cxx +++ b/xmloff/qa/unit/draw.cxx @@ -29,6 +29,7 @@ #include <svx/unopage.hxx> #include <svx/svdpage.hxx> #include <svx/svdomedia.hxx> +#include <docmodel/uno/UnoThemeColor.hxx> using namespace ::com::sun::star; @@ -39,6 +40,33 @@ public: XmloffDrawTest(); void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; uno::Reference<drawing::XShape> getShape(sal_uInt8 nShapeIndex); + + uno::Reference<beans::XPropertySet> + getShapeTextPortion(sal_uInt32 nIndex, uno::Reference<drawing::XShape> const& xShape) + { + uno::Reference<beans::XPropertySet> xPortion; + + uno::Reference<container::XEnumerationAccess> xEnumAccess(xShape, uno::UNO_QUERY); + if (!xEnumAccess->hasElements()) + return xPortion; + uno::Reference<container::XEnumeration> xEnum(xEnumAccess->createEnumeration()); + uno::Reference<text::XTextContent> xTextContent; + xEnum->nextElement() >>= xTextContent; + if (!xTextContent.is()) + return xPortion; + + uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextContent, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParaEnum(xParaEnumAccess->createEnumeration()); + sal_uInt32 nCurrent = 0; + xPortion = uno::Reference<beans::XPropertySet>(xParaEnum->nextElement(), uno::UNO_QUERY); + while (nIndex != nCurrent) + { + ++nCurrent; + xPortion + = uno::Reference<beans::XPropertySet>(xParaEnum->nextElement(), uno::UNO_QUERY); + } + return xPortion; + } }; XmloffDrawTest::XmloffDrawTest() @@ -188,65 +216,201 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeImport) CPPUNIT_ASSERT_EQUAL(static_cast<util::Color>(0x954F72), aColorScheme[11]); } -CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testReferToTheme) +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeColorExportImport) { // Given a document that refers to a theme color: - loadFromURL(u"refer-to-theme.odp"); + loadFromURL(u"Reference-ThemeColors-TextAndFill.pptx"); save("impress8"); // Make sure the export result has the theme reference: xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); - // Without the accompanying fix in place, this test would have failed with: - // - XPath '//style:style[@style:name='T1']/style:text-properties' no attribute 'theme-color' exist - // i.e. only the direct color was written, but not the theme reference. - assertXPath(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", "theme-color", - "accent1"); - assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", - "color-lum-mod"); - assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", - "color-lum-off"); - - assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "theme-color", - "accent1"); - // Without the accompanying fix in place, this test would have failed with: - // - XPath '//style:style[@style:name='T2']/style:text-properties' no attribute 'color-lum-mod' exist - // i.e. effects on a referenced theme color were lost. - assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "color-lum-mod", - "40%"); - assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "color-lum-off", - "60%"); - - assertXPath(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", "theme-color", - "accent1"); - assertXPath(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", "color-lum-mod", - "75%"); - assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", - "color-lum-off"); - // Without the accompanying fix in place, this test would have failed with: - // - XPath '//style:style[@style:name='gr2']/style:graphic-properties' no attribute 'fill-theme-color' exist - // i.e. only the direct color was written, but not the theme reference. - assertXPath(pXmlDoc, "//style:style[@style:name='gr2']/style:graphic-properties", - "fill-theme-color", "accent1"); - - // Shape fill, 60% lighter. - assertXPath(pXmlDoc, "//style:style[@style:name='gr3']/style:graphic-properties", - "fill-theme-color", "accent1"); - // Without the accompanying fix in place, this test would have failed with: - // - XPath '//style:style[@style:name='gr3']/style:graphic-properties' no attribute 'fill-color-lum-mod' exist - // i.e. the themed color was fine, but its effects were lost. - assertXPath(pXmlDoc, "//style:style[@style:name='gr3']/style:graphic-properties", - "fill-color-lum-mod", "40%"); - assertXPath(pXmlDoc, "//style:style[@style:name='gr3']/style:graphic-properties", - "fill-color-lum-off", "60%"); - - // Shape fill, 25% darker. - assertXPath(pXmlDoc, "//style:style[@style:name='gr4']/style:graphic-properties", - "fill-theme-color", "accent1"); - assertXPath(pXmlDoc, "//style:style[@style:name='gr4']/style:graphic-properties", - "fill-color-lum-mod", "75%"); - assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='gr4']/style:graphic-properties", - "fill-color-lum-off"); + // Text color + OString aStyle1( + "//style:style[@style:name='T2']/style:text-properties/loext:char-color-theme-reference"); + assertXPath(pXmlDoc, aStyle1, "type", "accent3"); + assertXPath(pXmlDoc, aStyle1 + "/loext:transformation[1]", "type", "lummod"); + assertXPath(pXmlDoc, aStyle1 + "/loext:transformation[1]", "value", "2000"); + assertXPath(pXmlDoc, aStyle1 + "/loext:transformation[2]", "type", "lumoff"); + assertXPath(pXmlDoc, aStyle1 + "/loext:transformation[2]", "value", "8000"); + + OString aStyle2( + "//style:style[@style:name='T3']/style:text-properties/loext:char-color-theme-reference"); + assertXPath(pXmlDoc, aStyle2, "type", "accent3"); + assertXPath(pXmlDoc, aStyle2 + "/loext:transformation[1]", "type", "lummod"); + assertXPath(pXmlDoc, aStyle2 + "/loext:transformation[1]", "value", "6000"); + assertXPath(pXmlDoc, aStyle2 + "/loext:transformation[2]", "type", "lumoff"); + assertXPath(pXmlDoc, aStyle2 + "/loext:transformation[2]", "value", "4000"); + + OString aStyle3( + "//style:style[@style:name='T4']/style:text-properties/loext:char-color-theme-reference"); + assertXPath(pXmlDoc, aStyle3, "type", "accent3"); + assertXPath(pXmlDoc, aStyle3 + "/loext:transformation[1]", "type", "lummod"); + assertXPath(pXmlDoc, aStyle3 + "/loext:transformation[1]", "value", "5000"); + + // Shapes fill color + OString aShape1("//style:style[@style:name='gr1']/style:graphic-properties/" + "loext:fill-color-theme-reference"); + assertXPath(pXmlDoc, aShape1, "type", "accent2"); + assertXPath(pXmlDoc, aShape1 + "/loext:transformation[1]", "type", "lummod"); + assertXPath(pXmlDoc, aShape1 + "/loext:transformation[1]", "value", "2000"); + assertXPath(pXmlDoc, aShape1 + "/loext:transformation[2]", "type", "lumoff"); + assertXPath(pXmlDoc, aShape1 + "/loext:transformation[2]", "value", "8000"); + + OString aShape2("//style:style[@style:name='gr2']/style:graphic-properties/" + "loext:fill-color-theme-reference"); + assertXPath(pXmlDoc, aShape2, "type", "accent2"); + assertXPath(pXmlDoc, aShape2 + "/loext:transformation[1]", "type", "lummod"); + assertXPath(pXmlDoc, aShape2 + "/loext:transformation[1]", "value", "6000"); + assertXPath(pXmlDoc, aShape2 + "/loext:transformation[2]", "type", "lumoff"); + assertXPath(pXmlDoc, aShape2 + "/loext:transformation[2]", "value", "4000"); + + OString aShape3("//style:style[@style:name='gr3']/style:graphic-properties/" + "loext:fill-color-theme-reference"); + assertXPath(pXmlDoc, aShape3, "type", "accent2"); + assertXPath(pXmlDoc, aShape3 + "/loext:transformation[1]", "type", "lummod"); + assertXPath(pXmlDoc, aShape3 + "/loext:transformation[1]", "value", "5000"); + + // reload + load(maTempFile.GetURL()); + + // check fill color theme + { + uno::Reference<drawing::XShape> xShape(getShape(0)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + uno::Reference<util::XThemeColor> xThemeColor; + xShapeProperties->getPropertyValue("FillColorThemeReference") >>= xThemeColor; + CPPUNIT_ASSERT(xThemeColor.is()); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent2, aThemeColor.getType()); + CPPUNIT_ASSERT_EQUAL(size_t(2), aThemeColor.getTransformations().size()); + auto const& rTrans1 = aThemeColor.getTransformations()[0]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans1.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), rTrans1.mnValue); + auto const& rTrans2 = aThemeColor.getTransformations()[1]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTrans2.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(8000), rTrans2.mnValue); + } + { + uno::Reference<drawing::XShape> xShape(getShape(1)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + uno::Reference<util::XThemeColor> xThemeColor; + xShapeProperties->getPropertyValue("FillColorThemeReference") >>= xThemeColor; + CPPUNIT_ASSERT(xThemeColor.is()); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent2, aThemeColor.getType()); + CPPUNIT_ASSERT_EQUAL(size_t(2), aThemeColor.getTransformations().size()); + auto const& rTrans1 = aThemeColor.getTransformations()[0]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans1.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(6000), rTrans1.mnValue); + auto const& rTrans2 = aThemeColor.getTransformations()[1]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTrans2.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(4000), rTrans2.mnValue); + } + { + uno::Reference<drawing::XShape> xShape(getShape(2)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + uno::Reference<util::XThemeColor> xThemeColor; + xShapeProperties->getPropertyValue("FillColorThemeReference") >>= xThemeColor; + CPPUNIT_ASSERT(xThemeColor.is()); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent2, aThemeColor.getType()); + CPPUNIT_ASSERT_EQUAL(size_t(1), aThemeColor.getTransformations().size()); + auto const& rTrans1 = aThemeColor.getTransformations()[0]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans1.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTrans1.mnValue); + } + + // Char color theme + // Shape 4 + { + // Check the first text portion properties + uno::Reference<drawing::XShape> xShape(getShape(3)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xPortion = getShapeTextPortion(0, xShape); + CPPUNIT_ASSERT(xPortion.is()); + uno::Reference<util::XThemeColor> xThemeColor; + xPortion->getPropertyValue("CharColorThemeReference") >>= xThemeColor; + CPPUNIT_ASSERT(xThemeColor.is()); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent3, aThemeColor.getType()); + CPPUNIT_ASSERT_EQUAL(size_t(2), aThemeColor.getTransformations().size()); + auto const& rTrans1 = aThemeColor.getTransformations()[0]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans1.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), rTrans1.mnValue); + auto const& rTrans2 = aThemeColor.getTransformations()[1]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTrans2.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(8000), rTrans2.mnValue); + } + // Shape 5 + { + // Check the first text portion properties + uno::Reference<drawing::XShape> xShape(getShape(4)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xPortion = getShapeTextPortion(0, xShape); + CPPUNIT_ASSERT(xPortion.is()); + uno::Reference<util::XThemeColor> xThemeColor; + xPortion->getPropertyValue("CharColorThemeReference") >>= xThemeColor; + CPPUNIT_ASSERT(xThemeColor.is()); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent3, aThemeColor.getType()); + CPPUNIT_ASSERT_EQUAL(size_t(2), aThemeColor.getTransformations().size()); + auto const& rTrans1 = aThemeColor.getTransformations()[0]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans1.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(6000), rTrans1.mnValue); + auto const& rTrans2 = aThemeColor.getTransformations()[1]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTrans2.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(4000), rTrans2.mnValue); + } + // Shape 6 + { + // Check the first text portion properties + uno::Reference<drawing::XShape> xShape(getShape(5)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xPortion = getShapeTextPortion(0, xShape); + CPPUNIT_ASSERT(xPortion.is()); + uno::Reference<util::XThemeColor> xThemeColor; + xPortion->getPropertyValue("CharColorThemeReference") >>= xThemeColor; + CPPUNIT_ASSERT(xThemeColor.is()); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent3, aThemeColor.getType()); + CPPUNIT_ASSERT_EQUAL(size_t(1), aThemeColor.getTransformations().size()); + auto const& rTrans1 = aThemeColor.getTransformations()[0]; + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans1.meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTrans1.mnValue); + } +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeColor_ShapeFill) +{ + loadFromURL(u"ReferenceShapeFill.pptx"); + save("impress8"); + // reload + load(maTempFile.GetURL()); + + // check fill color theme + uno::Reference<drawing::XShape> xShape(getShape(0)); + CPPUNIT_ASSERT(xShape.is()); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + uno::Reference<util::XThemeColor> xThemeColor; + xShapeProperties->getPropertyValue("FillColorThemeReference") >>= xThemeColor; + CPPUNIT_ASSERT(xThemeColor.is()); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent6, aThemeColor.getType()); + CPPUNIT_ASSERT_EQUAL(size_t(1), aThemeColor.getTransformations().size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, + aThemeColor.getTransformations()[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(7500), aThemeColor.getTransformations()[0].mnValue); } CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTableInShape) diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 3eb529ea1517..d1d2047a50b9 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3484,8 +3484,8 @@ namespace xmloff::token { TOKEN("linked-style-name", XML_LINKED_STYLE_NAME ), TOKEN("theme", XML_THEME ), - TOKEN("theme-color", XML_THEME_COLOR ), - TOKEN("fill-theme-color", XML_FILL_THEME_COLOR ), + TOKEN("char-color-theme-reference", XML_CHAR_COLOR_THEME_REFERENCE), + TOKEN("fill-color-theme-reference", XML_FILL_COLOR_THEME_REFERENCE), TOKEN("dk1", XML_DK1 ), TOKEN("lt1", XML_LT1 ), TOKEN("dk2", XML_DK2 ), @@ -3498,10 +3498,6 @@ namespace xmloff::token { TOKEN("accent6", XML_ACCENT6 ), TOKEN("hlink", XML_HLINK ), TOKEN("folHlink", XML_FOLHLINK ), - TOKEN("color-lum-mod", XML_COLOR_LUM_MOD ), - TOKEN("color-lum-off", XML_COLOR_LUM_OFF ), - TOKEN("fill-color-lum-mod", XML_FILL_COLOR_LUM_MOD ), - TOKEN("fill-color-lum-off", XML_FILL_COLOR_LUM_OFF ), TOKEN("content-control", XML_CONTENT_CONTROL ), TOKEN("showing-place-holder", XML_SHOWING_PLACE_HOLDER ), diff --git a/xmloff/source/draw/XMLShapePropertySetContext.cxx b/xmloff/source/draw/XMLShapePropertySetContext.cxx index c702bccf9a91..471a22d2a098 100644 --- a/xmloff/source/draw/XMLShapePropertySetContext.cxx +++ b/xmloff/source/draw/XMLShapePropertySetContext.cxx @@ -19,6 +19,7 @@ #include <XMLShapePropertySetContext.hxx> #include <XMLTextColumnsContext.hxx> +#include <XMLThemeColorContext.hxx> #include <xmloff/xmlimp.hxx> #include <xmloff/xmlnumi.hxx> #include <xmltabi.hxx> @@ -81,6 +82,9 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLShapePropertySetCon rProperties ); case CTF_TEXTCOLUMNS: return new XMLTextColumnsContext(GetImport(), nElement, xAttrList, rProp, rProperties); + + case CTF_THEME_COLOR: + return new XMLThemeColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); } return SvXMLPropertySetContext::createFastChildContext( nElement, diff --git a/xmloff/source/draw/sdpropls.cxx b/xmloff/source/draw/sdpropls.cxx index 6c8731942782..278e0c2bc179 100644 --- a/xmloff/source/draw/sdpropls.cxx +++ b/xmloff/source/draw/sdpropls.cxx @@ -109,9 +109,7 @@ const XMLPropertyMapEntry aXMLSDProperties[] = GMAP( PROP_FillStyle, XML_NAMESPACE_DRAW, XML_FILL, XML_SD_TYPE_FILLSTYLE, CTF_FILLSTYLE ), GMAP_D(PROP_FillColor, XML_NAMESPACE_DRAW, XML_FILL_COLOR, XML_TYPE_COLOR, CTF_FILLCOLOR ), GMAP_D(PROP_FillColor2, XML_NAMESPACE_DRAW, XML_SECONDARY_FILL_COLOR, XML_TYPE_COLOR, 0), - GMAPV( PROP_FillColorTheme, XML_NAMESPACE_LO_EXT, XML_FILL_THEME_COLOR, XML_TYPE_THEME_COLOR, 0, SvtSaveOptions::ODFSVER_FUTURE_EXTENDED), - GMAPV( PROP_FillColorLumMod, XML_NAMESPACE_LO_EXT, XML_FILL_COLOR_LUM_MOD, XML_TYPE_PERCENT100, 0, SvtSaveOptions::ODFSVER_FUTURE_EXTENDED), - GMAPV( PROP_FillColorLumOff, XML_NAMESPACE_LO_EXT, XML_FILL_COLOR_LUM_OFF, XML_TYPE_PERCENT100, 0, SvtSaveOptions::ODFSVER_FUTURE_EXTENDED), + GMAPV( PROP_FillColorThemeReference, XML_NAMESPACE_LO_EXT, XML_FILL_COLOR_THEME_REFERENCE, XML_TYPE_THEME_COLOR|MID_FLAG_ELEMENT_ITEM, CTF_THEME_COLOR, SvtSaveOptions::ODFSVER_FUTURE_EXTENDED), GMAP( PROP_FillGradientName, XML_NAMESPACE_DRAW, XML_FILL_GRADIENT_NAME, XML_TYPE_STYLENAME|MID_FLAG_NO_PROPERTY_IMPORT, CTF_FILLGRADIENTNAME ), GMAP( PROP_FillGradientStepCount, XML_NAMESPACE_DRAW, XML_GRADIENT_STEP_COUNT, XML_TYPE_NUMBER16, 0 ), GMAP( PROP_FillHatchName, XML_NAMESPACE_DRAW, XML_FILL_HATCH_NAME, XML_TYPE_STYLENAME|MID_FLAG_NO_PROPERTY_IMPORT, CTF_FILLHATCHNAME ), diff --git a/xmloff/source/style/PagePropertySetContext.cxx b/xmloff/source/style/PagePropertySetContext.cxx index 31c541f56b35..583a5d14c321 100644 --- a/xmloff/source/style/PagePropertySetContext.cxx +++ b/xmloff/source/style/PagePropertySetContext.cxx @@ -98,9 +98,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > PagePropertySetContext break; case CTF_PM_TEXTCOLUMNS: - return new XMLTextColumnsContext( GetImport(), nElement, - xAttrList, rProp, - rProperties ); + return new XMLTextColumnsContext(GetImport(), nElement, xAttrList, rProp, rProperties); break; case CTF_PM_FTN_LINE_WEIGHT: diff --git a/xmloff/source/text/XMLTextPropertySetContext.cxx b/xmloff/source/text/XMLTextPropertySetContext.cxx index b2db201cac2e..fd87f837dbf7 100644 --- a/xmloff/source/text/XMLTextPropertySetContext.cxx +++ b/xmloff/source/text/XMLTextPropertySetContext.cxx @@ -20,6 +20,7 @@ #include <tools/debug.hxx> #include "XMLTextPropertySetContext.hxx" #include <XMLTextColumnsContext.hxx> +#include <XMLThemeColorContext.hxx> #include <XMLBackgroundImageContext.hxx> #include "XMLSectionFootnoteConfigImport.hxx" @@ -28,7 +29,6 @@ #include <xmltabi.hxx> #include "txtdropi.hxx" - using namespace ::com::sun::star::uno; using namespace ::com::sun::star; @@ -69,6 +69,10 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextPropertySetCont rProperties ); break; + case CTF_THEME_COLOR: + return new XMLThemeColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); + break; + case CTF_DROPCAPFORMAT: { DBG_ASSERT( rProp.mnIndex >= 2 && diff --git a/xmloff/source/text/XMLTextShapeStyleContext.cxx b/xmloff/source/text/XMLTextShapeStyleContext.cxx index 81df6cf85d6b..eeda57a558a8 100644 --- a/xmloff/source/text/XMLTextShapeStyleContext.cxx +++ b/xmloff/source/text/XMLTextShapeStyleContext.cxx @@ -27,6 +27,7 @@ #include <xmloff/XMLEventsImportContext.hxx> #include <XMLShapePropertySetContext.hxx> #include <XMLTextColumnsContext.hxx> +#include <XMLThemeColorContext.hxx> #include <XMLBackgroundImageContext.hxx> #include <xmloff/txtprmap.hxx> #include <xmloff/xmltypes.hxx> @@ -89,6 +90,9 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapePropertySe rProperties ); break; + case CTF_THEME_COLOR: + return new XMLThemeColorContext(GetImport(), nElement, xAttrList, rProp, rProperties); + case CTF_BACKGROUND_URL: DBG_ASSERT( rProp.mnIndex >= 3 && CTF_BACKGROUND_TRANSPARENCY == diff --git a/xmloff/source/text/XMLThemeColorContext.cxx b/xmloff/source/text/XMLThemeColorContext.cxx new file mode 100644 index 000000000000..c2cdd6cd35ce --- /dev/null +++ b/xmloff/source/text/XMLThemeColorContext.cxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <sal/log.hxx> +#include <sax/tools/converter.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/namespacemap.hxx> +#include <xmloff/xmlnamespace.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlement.hxx> +#include <xmloff/xmlprhdl.hxx> +#include <XMLThemeColorContext.hxx> + +using namespace css; +using namespace xmloff::token; + +SvXMLEnumMapEntry<sal_Int16> const pXML_ThemeColor_Enum[] + = { { XML_NONE, -1 }, { XML_DK1, 0 }, { XML_LT1, 1 }, { XML_DK2, 2 }, + { XML_LT2, 3 }, { XML_ACCENT1, 4 }, { XML_ACCENT2, 5 }, { XML_ACCENT3, 6 }, + { XML_ACCENT4, 7 }, { XML_ACCENT5, 8 }, { XML_ACCENT6, 9 }, { XML_HLINK, 10 }, + { XML_FOLHLINK, 11 }, { XML_TOKEN_INVALID, 0 } }; + +XMLThemeColorContext::XMLThemeColorContext( + 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) +{ + for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList)) + { + switch (aIter.getToken()) + { + case XML_ELEMENT(LO_EXT, XML_TYPE): + { + sal_Int16 nValue = -1; + if (SvXMLUnitConverter::convertEnum(nValue, aIter.toView(), pXML_ThemeColor_Enum)) + { + aThemeColor.setType(model::convertToThemeColorType(nValue)); + } + break; + } + default: + XMLOFF_WARN_UNKNOWN("xmloff", aIter); + break; + } + } +} + +css::uno::Reference<css::xml::sax::XFastContextHandler> +XMLThemeColorContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) +{ + if (nElement == XML_ELEMENT(LO_EXT, XML_TRANSFORMATION)) + { + auto eTransformationType = model::TransformationType::Undefined; + sal_Int16 nTransformationValue = 0; + for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList)) + { + switch (aIter.getToken()) + { + case XML_ELEMENT(LO_EXT, XML_TYPE): + { + const OUString aValue = aIter.toString(); + if (aValue == u"tint") + eTransformationType = model::TransformationType::Tint; + else if (aValue == u"shade") + eTransformationType = model::TransformationType::Shade; + else if (aValue == u"lumoff") + eTransformationType = model::TransformationType::LumOff; + else if (aValue == u"lummod") + eTransformationType = model::TransformationType::LumMod; + break; + } + case XML_ELEMENT(LO_EXT, XML_VALUE): + { + sal_Int32 nValue; + if (::sax::Converter::convertNumber(nValue, aIter.toView(), SHRT_MIN, SHRT_MAX)) + nTransformationValue = static_cast<sal_Int16>(nValue); + break; + } + default: + XMLOFF_WARN_UNKNOWN("xmloff", aIter); + break; + } + } + aThemeColor.addTransformation({ eTransformationType, nTransformationValue }); + return this; + } + XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); + return nullptr; +} + +void XMLThemeColorContext::endFastElement(sal_Int32 nElement) +{ + if (nElement == mnRootElement) + { + if (aThemeColor.getType() != model::ThemeColorType::Unknown) + { + aProp.maValue <<= model::theme::createXThemeColor(aThemeColor); + SetInsert(true); + } + } + XMLElementPropertyContext::endFastElement(nElement); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLThemeColorExport.cxx b/xmloff/source/text/XMLThemeColorExport.cxx new file mode 100644 index 000000000000..2f90e74ffbcf --- /dev/null +++ b/xmloff/source/text/XMLThemeColorExport.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <XMLThemeColorExport.hxx> + +#include <sal/config.h> + +#include <docmodel/uno/UnoThemeColor.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnamespace.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlexp.hxx> +#include <array> + +using namespace css; +using namespace ::xmloff::token; + +XMLThemeColorExport::XMLThemeColorExport(SvXMLExport& rExport) + : mrExport(rExport) +{ +} + +namespace +{ +constexpr const std::array<XMLTokenEnum, 12> constThemeColorTypeToToken{ + XML_DK1, XML_LT1, XML_DK2, XML_LT2, XML_ACCENT1, XML_ACCENT2, + XML_ACCENT3, XML_ACCENT4, XML_ACCENT5, XML_ACCENT6, XML_HLINK, XML_FOLHLINK +}; +} + +void XMLThemeColorExport::exportXML(const uno::Any& rAny, sal_uInt16 nPrefix, + const OUString& rLocalName) +{ + uno::Reference<util::XThemeColor> xThemeColor; + rAny >>= xThemeColor; + if (!xThemeColor.is()) + return; + + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + if (aThemeColor.getType() == model::ThemeColorType::Unknown) + return; + + XMLTokenEnum nToken = constThemeColorTypeToToken[sal_Int16(aThemeColor.getType())]; + mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_TYPE, nToken); + SvXMLElementExport aThemeColorElement(mrExport, nPrefix, rLocalName, true, true); + + for (auto const& rTransform : aThemeColor.getTransformations()) + { + OUString aType; + switch (rTransform.meType) + { + case model::TransformationType::Tint: + aType = "tint"; + break; + case model::TransformationType::Shade: + aType = "shade"; + break; + case model::TransformationType::LumMod: + aType = "lummod"; + break; + case model::TransformationType::LumOff: + aType = "lumoff"; + break; + default: + break; + } + if (!aType.isEmpty()) + { + mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_TYPE, aType); + mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_VALUE, + OUString::number(rTransform.mnValue)); + SvXMLElementExport aTransformElement(mrExport, XML_NAMESPACE_LO_EXT, XML_TRANSFORMATION, + true, true); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtexppr.cxx b/xmloff/source/text/txtexppr.cxx index 65cdf59b74ee..8d73fe303304 100644 --- a/xmloff/source/text/txtexppr.cxx +++ b/xmloff/source/text/txtexppr.cxx @@ -72,6 +72,12 @@ void XMLTextExportPropertySetMapper::handleElementItem( pThis->maTextColumnsExport.exportXML( rProperty.maValue ); break; + case CTF_THEME_COLOR: + pThis->maThemeColorExport.exportXML(rProperty.maValue, + getPropertySetMapper()->GetEntryNameSpace(rProperty.mnIndex), + getPropertySetMapper()->GetEntryXMLName(rProperty.mnIndex)); + break; + case CTF_BACKGROUND_URL: { const Any *pPos = nullptr, *pFilter = nullptr, *pTrans = nullptr; @@ -210,6 +216,7 @@ XMLTextExportPropertySetMapper::XMLTextExportPropertySetMapper( maDropCapExport( rExp ), maTabStopExport( rExp ), maTextColumnsExport( rExp ), + maThemeColorExport(rExp), maBackgroundImageExport( rExp ) { } diff --git a/xmloff/source/text/txtexppr.hxx b/xmloff/source/text/txtexppr.hxx index 6262613642f1..bb7e3c230a2c 100644 --- a/xmloff/source/text/txtexppr.hxx +++ b/xmloff/source/text/txtexppr.hxx @@ -24,6 +24,7 @@ #include <xmltabe.hxx> #include <XMLTextColumnsExport.hxx> #include <XMLBackgroundImageExport.hxx> +#include <XMLThemeColorExport.hxx> class SvXMLExport; class XMLTextExportPropertySetMapper: public SvXMLExportPropertyMapper @@ -52,6 +53,7 @@ private: XMLTextDropCapExport maDropCapExport; SvxXMLTabStopExport maTabStopExport; XMLTextColumnsExport maTextColumnsExport; + XMLThemeColorExport maThemeColorExport; XMLBackgroundImageExport maBackgroundImageExport; /** Application-specific filter. By default do nothing. */ diff --git a/xmloff/source/text/txtprhdl.cxx b/xmloff/source/text/txtprhdl.cxx index a4450ce230f4..c0259d2f9dc9 100644 --- a/xmloff/source/text/txtprhdl.cxx +++ b/xmloff/source/text/txtprhdl.cxx @@ -250,24 +250,6 @@ SvXMLEnumMapEntry<drawing::TextVerticalAdjust> const pXML_VerticalAlign_Enum[] = { XML_TOKEN_INVALID, drawing::TextVerticalAdjust(0) } }; -SvXMLEnumMapEntry<sal_Int16> const pXML_ThemeColor_Enum[] = -{ - { XML_NONE, -1 }, - { XML_DK1, 0 }, - { XML_LT1, 1 }, - { XML_DK2, 2 }, - { XML_LT2, 3 }, - { XML_ACCENT1, 4 }, - { XML_ACCENT2, 5 }, - { XML_ACCENT3, 6 }, - { XML_ACCENT4, 7 }, - { XML_ACCENT5, 8 }, - { XML_ACCENT6, 9 }, - { XML_HLINK, 10 }, - { XML_FOLHLINK, 11 }, - { XML_TOKEN_INVALID, 0 } -}; - namespace { class XMLDropCapPropHdl_Impl : public XMLPropertyHandler diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx index 527c63bbc1f0..6b8ab2960ca7 100644 --- a/xmloff/source/text/txtprmap.cxx +++ b/xmloff/source/text/txtprmap.cxx @@ -139,9 +139,7 @@ XMLPropertyMapEntry const aXMLParaPropMap[] = MT_ED( PROP_CharColor, STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ), MAP_EXT_I( PROP_CharTransparence, XML_NAMESPACE_DRAW, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), MAP_EXT( PROP_CharTransparence, XML_NAMESPACE_LO_EXT, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), - MAP_EXT( PROP_CharColorTheme, XML_NAMESPACE_LO_EXT, XML_THEME_COLOR, XML_TYPE_THEME_COLOR | XML_TYPE_PROP_TEXT, 0), - MAP_EXT( PROP_CharColorLumMod, XML_NAMESPACE_LO_EXT, XML_COLOR_LUM_MOD, XML_TYPE_PERCENT100 | XML_TYPE_PROP_TEXT, 0), - MAP_EXT( PROP_CharColorLumOff, XML_NAMESPACE_LO_EXT, XML_COLOR_LUM_OFF, XML_TYPE_PERCENT100 | XML_TYPE_PROP_TEXT, 0), + MAP_EXT( PROP_CharColorThemeReference, XML_NAMESPACE_LO_EXT, XML_CHAR_COLOR_THEME_REFERENCE, XML_TYPE_THEME_COLOR|XML_TYPE_PROP_TEXT|MID_FLAG_ELEMENT_ITEM, CTF_THEME_COLOR), // RES_CHRATR_CONTOUR MT_E( PROP_CharContoured, STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ), // RES_CHRATR_CROSSEDOUT @@ -488,9 +486,7 @@ XMLPropertyMapEntry const aXMLTextPropMap[] = MT_ED( PROP_CharColor, STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ), MAP_EXT_I( PROP_CharTransparence, XML_NAMESPACE_DRAW, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), MAP_EXT( PROP_CharTransparence, XML_NAMESPACE_LO_EXT, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), - MAP_EXT( PROP_CharColorTheme, XML_NAMESPACE_LO_EXT, XML_THEME_COLOR, XML_TYPE_THEME_COLOR | XML_TYPE_PROP_TEXT, 0), - MAP_EXT( PROP_CharColorLumMod, XML_NAMESPACE_LO_EXT, XML_COLOR_LUM_MOD, XML_TYPE_PERCENT100 | XML_TYPE_PROP_TEXT, 0), - MAP_EXT( PROP_CharColorLumOff, XML_NAMESPACE_LO_EXT, XML_COLOR_LUM_OFF, XML_TYPE_PERCENT100 | XML_TYPE_PROP_TEXT, 0), + MAP_EXT( PROP_CharColorThemeReference, XML_NAMESPACE_LO_EXT, XML_CHAR_COLOR_THEME_REFERENCE, XML_TYPE_THEME_COLOR|XML_TYPE_PROP_TEXT|MID_FLAG_ELEMENT_ITEM, CTF_THEME_COLOR), // RES_CHRATR_CONTOUR MT_E( PROP_CharContoured, STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ), // RES_CHRATR_CROSSEDOUT @@ -1037,6 +1033,7 @@ XMLPropertyMapEntry const aXMLCellPropMap[] = // text properties MT_ED( PROP_CharColor, FO, COLOR, XML_TYPE_COLORAUTO|MID_FLAG_MERGE_PROPERTY, 0 ), MT_ED( PROP_CharColor, STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ), + MAP_EXT( PROP_CharColorThemeReference, XML_NAMESPACE_LO_EXT, XML_CHAR_COLOR_THEME_REFERENCE, XML_TYPE_THEME_COLOR|XML_TYPE_PROP_TEXT|MID_FLAG_ELEMENT_ITEM, CTF_THEME_COLOR), MT_E( PROP_CharShadowed, FO, TEXT_SHADOW, XML_TYPE_TEXT_SHADOWED, 0 ), MT_E( PROP_CharContoured, STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ), MT_E( PROP_CharStrikeout, STYLE, TEXT_LINE_THROUGH_STYLE, XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ), diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 2fb710f1c323..e4a0a5fe7c36 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3228,8 +3228,8 @@ rtl symmetric linked-style-name theme -theme-color -fill-theme-color +char-color-theme-reference +fill-color-theme-reference dk1 lt1 dk2 @@ -3242,10 +3242,6 @@ accent5 accent6 hlink folHlink -color-lum-mod -color-lum-off -fill-color-lum-mod -fill-color-lum-off content-control showing-place-holder checked-state commit a6d44c4684f9b037e5c762430df78af2fc85cf34 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Jan 12 13:52:01 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Jan 13 13:43:56 2023 +0000 XUnoTunnel->dynamic_cast in VCLXFont Change-Id: I4afa34805e64f3ff37b76fe8ca4676c1f4eb3e14 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145468 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/toolkit/awt/vclxfont.hxx b/include/toolkit/awt/vclxfont.hxx index efad4b590da7..c4f768954c6e 100644 --- a/include/toolkit/awt/vclxfont.hxx +++ b/include/toolkit/awt/vclxfont.hxx @@ -23,7 +23,6 @@ #include <memory> #include <toolkit/dllapi.h> #include <com/sun/star/awt/XFont2.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> #include <comphelper/servicehelper.hxx> #include <cppuhelper/implbase.hxx> #include <mutex> @@ -38,8 +37,7 @@ class FontMetric; class TOOLKIT_DLLPUBLIC VCLXFont final : public cppu::WeakImplHelper< - css::awt::XFont2, - css::lang::XUnoTunnel> + css::awt::XFont2> { std::mutex maMutex; css::uno::Reference< css::awt::XDevice> mxDevice; @@ -56,9 +54,6 @@ public: void Init( css::awt::XDevice& rxDev, const vcl::Font& rFont ); const vcl::Font& GetFont() const { return maFont; } - // css::lang::XUnoTunnel - UNO3_GETIMPLEMENTATION_DECL(VCLXFont) - // css::lang::XFont css::awt::FontDescriptor SAL_CALL getFontDescriptor( ) override; css::awt::SimpleFontMetric SAL_CALL getFontMetric( ) override; diff --git a/toolkit/source/awt/vclxfont.cxx b/toolkit/source/awt/vclxfont.cxx index 866a362e710f..01e7aaae7944 100644 --- a/toolkit/source/awt/vclxfont.cxx +++ b/toolkit/source/awt/vclxfont.cxx @@ -64,9 +64,6 @@ bool VCLXFont::ImplAssertValidFontMetric() return mpFontMetric != nullptr; } -// css::lang::XUnoTunnel -UNO3_GETIMPLEMENTATION_IMPL( VCLXFont ); - css::awt::FontDescriptor VCLXFont::getFontDescriptor( ) { std::unique_lock aGuard( maMutex ); diff --git a/toolkit/source/helper/vclunohelper.cxx b/toolkit/source/helper/vclunohelper.cxx index bac88c66268a..42b55c6db04f 100644 --- a/toolkit/source/helper/vclunohelper.cxx +++ b/toolkit/source/helper/vclunohelper.cxx @@ -250,7 +250,7 @@ vcl::Font VCLUnoHelper::CreateFont( const css::awt::FontDescriptor& rDescr, cons vcl::Font VCLUnoHelper::CreateFont( const css::uno::Reference< css::awt::XFont >& rxFont ) { vcl::Font aFont; - VCLXFont* pVCLXFont = comphelper::getFromUnoTunnel<VCLXFont>( rxFont ); + VCLXFont* pVCLXFont = dynamic_cast<VCLXFont*>( rxFont.get() ); if ( pVCLXFont ) aFont = pVCLXFont->GetFont(); return aFont;