diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-01-01 23:25:38 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-01-13 00:49:24 +0000 |
commit | 197e5f81213d14fdcbff40edf73385ecd4cd9815 (patch) | |
tree | 5bc1735ec61200a895b5edcf684d846245286ba5 /oox/source | |
parent | c82fa434dab8744c548db166cd24ee82e8759e1f (diff) |
introduce {Char,Fill}ColorThemeReference which uses XThemeColor
Adds a unified UNO property for theme colors *ColorTheme
(CharColorTheme and FillColorTheme) which uses XThemeColor, that
replaces the properties *Theme, *TintOrShade, *LumOff, *LumMod.
The properties are still present for backwards compatibility and
to keep ODF support working in tests as that needs a bigger change.
Reactor the code and tests to accomodate for this change.
Change-Id: If7983decb4ba528b49fe7b5968aa9efc696a9efc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144783
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/drawingml/fillproperties.cxx | 21 | ||||
-rw-r--r-- | oox/source/drawingml/textcharacterproperties.cxx | 23 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 99 | ||||
-rw-r--r-- | oox/source/token/properties.txt | 2 |
4 files changed, 85 insertions, 60 deletions
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index ef709dd588ef..99fbfa41e990 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -26,6 +26,7 @@ #include <vcl/graph.hxx> #include <vcl/BitmapFilter.hxx> #include <vcl/BitmapMonochromeFilter.hxx> +#include <docmodel/uno/UnoThemeColor.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/awt/Gradient.hpp> @@ -448,15 +449,27 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, if( maFillColor.hasTransparency() ) rPropMap.setProperty( ShapeProperty::FillTransparency, maFillColor.getTransparency() ); + model::ThemeColor aThemeColor; if (aFillColor == nPhClr) { - rPropMap.setProperty(PROP_FillColorTheme, nPhClrTheme); + aThemeColor.setType(model::convertToThemeColorType(nPhClrTheme)); + rPropMap.setProperty(PROP_FillColorThemeReference, model::theme::createXThemeColor(aThemeColor)); } else if (maFillColor.getTintOrShade() == 0) { - rPropMap.setProperty(PROP_FillColorTheme, maFillColor.getSchemeColorIndex()); - rPropMap.setProperty(PROP_FillColorLumMod, maFillColor.getLumMod()); - rPropMap.setProperty(PROP_FillColorLumOff, maFillColor.getLumOff()); + aThemeColor.setType(model::convertToThemeColorType(maFillColor.getSchemeColorIndex())); + if (maFillColor.getLumMod() != 10000) + aThemeColor.addTransformation({model::TransformationType::LumMod, maFillColor.getLumMod()}); + if (maFillColor.getLumOff() != 0) + aThemeColor.addTransformation({model::TransformationType::LumOff, maFillColor.getLumOff()}); + if (maFillColor.getTintOrShade() > 0) + aThemeColor.addTransformation({model::TransformationType::Tint, maFillColor.getTintOrShade()}); + if (maFillColor.getTintOrShade() < 0) + { + sal_Int16 nShade = o3tl::narrowing<sal_Int16>(-maFillColor.getTintOrShade()); + aThemeColor.addTransformation({model::TransformationType::Shade, nShade}); + } + rPropMap.setProperty(PROP_FillColorThemeReference, model::theme::createXThemeColor(aThemeColor)); } eFillStyle = FillStyle_SOLID; diff --git a/oox/source/drawingml/textcharacterproperties.cxx b/oox/source/drawingml/textcharacterproperties.cxx index 3bc65ec1bb3d..a22606ef106c 100644 --- a/oox/source/drawingml/textcharacterproperties.cxx +++ b/oox/source/drawingml/textcharacterproperties.cxx @@ -26,6 +26,7 @@ #include <i18nlangtag/languagetag.hxx> #include <i18nlangtag/mslangid.hxx> #include <editeng/escapementitem.hxx> +#include <docmodel/uno/UnoThemeColor.hxx> #include <oox/helper/helper.hxx> #include <oox/helper/propertyset.hxx> #include <oox/core/xmlfilterbase.hxx> @@ -133,11 +134,23 @@ void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFil aColor = aLineColor; } rPropMap.setProperty(PROP_CharColor, aColor.getColor(rFilter.getGraphicHelper())); - // set color theme index - rPropMap.setProperty(PROP_CharColorTheme, aColor.getSchemeColorIndex()); - rPropMap.setProperty(PROP_CharColorTintOrShade, aColor.getTintOrShade()); - rPropMap.setProperty(PROP_CharColorLumMod, aColor.getLumMod()); - rPropMap.setProperty(PROP_CharColorLumOff, aColor.getLumOff()); + + // set theme color + model::ThemeColor aThemeColor; + aThemeColor.setType(model::convertToThemeColorType(aColor.getSchemeColorIndex())); + if (aColor.getTintOrShade() > 0) + aThemeColor.addTransformation({model::TransformationType::Tint, aColor.getTintOrShade()}); + if (aColor.getTintOrShade() < 0) + { + sal_Int16 nShade = o3tl::narrowing<sal_Int16>(-aColor.getTintOrShade()); + aThemeColor.addTransformation({model::TransformationType::Shade, nShade}); + } + if (aColor.getLumMod() != 10000) + aThemeColor.addTransformation({model::TransformationType::LumMod, aColor.getLumMod()}); + if (aColor.getLumOff() != 0) + aThemeColor.addTransformation({model::TransformationType::LumOff, aColor.getLumOff()}); + + rPropMap.setProperty(PROP_CharColorThemeReference, model::theme::createXThemeColor(aThemeColor)); rPropMap.setProperty(PROP_CharContoured, bContoured); if (aColor.hasTransparency()) diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index b98a785eb582..dde41bd16c35 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -125,6 +125,7 @@ #include <editeng/flditem.hxx> #include <editeng/escapementitem.hxx> #include <editeng/unonrule.hxx> +#include <docmodel/uno/UnoThemeColor.hxx> #include <svx/svdoashp.hxx> #include <svx/svdomedia.hxx> #include <svx/svdtrans.hxx> @@ -433,44 +434,41 @@ void DrawingML::WriteColorTransformations( const Sequence< PropertyValue >& aTra bool DrawingML::WriteCharColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet) { - if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("CharColorTheme")) - { + if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("CharColorThemeReference")) return false; - } - sal_Int32 nCharColorTheme = -1; - xPropertySet->getPropertyValue("CharColorTheme") >>= nCharColorTheme; - if (nCharColorTheme < 0 || nCharColorTheme > 11) - { + uno::Reference<util::XThemeColor> xThemeColor; + xPropertySet->getPropertyValue("CharColorThemeReference") >>= xThemeColor; + if (!xThemeColor.is()) return false; - } - - const char* pColorName = g_aPredefinedClrNames[nCharColorTheme]; - sal_Int32 nCharColorTintOrShade{}; - xPropertySet->getPropertyValue("CharColorTintOrShade") >>= nCharColorTintOrShade; - if (nCharColorTintOrShade != 0) - { + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + if (aThemeColor.getType() == model::ThemeColorType::Unknown) return false; - } - + const char* pColorName = g_aPredefinedClrNames[sal_Int16(aThemeColor.getType())]; mpFS->startElementNS(XML_a, XML_solidFill); mpFS->startElementNS(XML_a, XML_schemeClr, XML_val, pColorName); - - sal_Int32 nCharColorLumMod{}; - xPropertySet->getPropertyValue("CharColorLumMod") >>= nCharColorLumMod; - if (nCharColorLumMod != 10000) + for (auto const& rTransform : aThemeColor.getTransformations()) { - mpFS->singleElementNS(XML_a, XML_lumMod, XML_val, OString::number(nCharColorLumMod * 10)); - } - - sal_Int32 nCharColorLumOff{}; - xPropertySet->getPropertyValue("CharColorLumOff") >>= nCharColorLumOff; - if (nCharColorLumOff != 0) - { - mpFS->singleElementNS(XML_a, XML_lumOff, XML_val, OString::number(nCharColorLumOff * 10)); + switch (rTransform.meType) + { + case model::TransformationType::LumMod: + mpFS->singleElementNS(XML_a, XML_lumMod, XML_val, OString::number(rTransform.mnValue * 10)); + break; + case model::TransformationType::LumOff: + mpFS->singleElementNS(XML_a, XML_lumOff, XML_val, OString::number(rTransform.mnValue * 10)); + break; + case model::TransformationType::Tint: + mpFS->singleElementNS(XML_a, XML_tint, XML_val, OString::number(rTransform.mnValue * 10)); + break; + case model::TransformationType::Shade: + mpFS->singleElementNS(XML_a, XML_shade, XML_val, OString::number(rTransform.mnValue * 10)); + break; + default: + break; + } } - mpFS->endElementNS(XML_a, XML_schemeClr); mpFS->endElementNS(XML_a, XML_solidFill); @@ -589,35 +587,34 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet ) bool DrawingML::WriteFillColor(const uno::Reference<beans::XPropertySet>& xPropertySet) { - if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("FillColorTheme")) - { + if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("FillColorThemeReference")) return false; - } - sal_Int32 nFillColorTheme = -1; - xPropertySet->getPropertyValue("FillColorTheme") >>= nFillColorTheme; - if (nFillColorTheme < 0 || nFillColorTheme > 11) - { + uno::Reference<util::XThemeColor> xThemeColor; + xPropertySet->getPropertyValue("FillColorThemeReference") >>= xThemeColor; + if (!xThemeColor.is()) return false; - } - - const char* pColorName = g_aPredefinedClrNames[nFillColorTheme]; + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + if (aThemeColor.getType() == model::ThemeColorType::Unknown) + return false; + const char* pColorName = g_aPredefinedClrNames[sal_Int16(aThemeColor.getType())]; mpFS->startElementNS(XML_a, XML_solidFill); mpFS->startElementNS(XML_a, XML_schemeClr, XML_val, pColorName); - - sal_Int32 nFillColorLumMod{}; - xPropertySet->getPropertyValue("FillColorLumMod") >>= nFillColorLumMod; - if (nFillColorLumMod != 10000) + for (auto const& rTransform : aThemeColor.getTransformations()) { - mpFS->singleElementNS(XML_a, XML_lumMod, XML_val, OString::number(nFillColorLumMod * 10)); - } - - sal_Int32 nFillColorLumOff{}; - xPropertySet->getPropertyValue("FillColorLumOff") >>= nFillColorLumOff; - if (nFillColorLumOff != 0) - { - mpFS->singleElementNS(XML_a, XML_lumOff, XML_val, OString::number(nFillColorLumOff * 10)); + switch (rTransform.meType) + { + case model::TransformationType::LumMod: + mpFS->singleElementNS(XML_a, XML_lumMod, XML_val, OString::number(rTransform.mnValue * 10)); + break; + case model::TransformationType::LumOff: + mpFS->singleElementNS(XML_a, XML_lumOff, XML_val, OString::number(rTransform.mnValue * 10)); + break; + default: + break; + } } mpFS->endElementNS(XML_a, XML_schemeClr); diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index 5df793846a50..439ecc9cd8a0 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -53,6 +53,7 @@ Change CharBackColor CharCaseMap CharColor +CharColorThemeReference CharContoured CharColorTheme CharColorTintOrShade @@ -176,6 +177,7 @@ FillColor FillColorTheme FillColorLumMod FillColorLumOff +FillColorThemeReference FillGradient FillGradientName FillHatch |