summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-02-27 21:20:49 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-04-09 15:39:29 +0200
commitf707834e8538c0a183716b26ebdf04381482ca6d (patch)
tree371d0fc7c40295c1b8137216ebd7bd0f3f412feb
parent424ff8486b15de152225634a51e3048527e23f21 (diff)
oox: write color transforms to model::ColorDefinition
Change-Id: I438c10b5181ffd20f2aa041479da2df62a92b156 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147952 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--oox/source/drawingml/colorchoicecontext.cxx56
-rw-r--r--sw/qa/core/theme/ThemeTest.cxx163
2 files changed, 197 insertions, 22 deletions
diff --git a/oox/source/drawingml/colorchoicecontext.cxx b/oox/source/drawingml/colorchoicecontext.cxx
index 3d559299f4c2..927ff41de9c0 100644
--- a/oox/source/drawingml/colorchoicecontext.cxx
+++ b/oox/source/drawingml/colorchoicecontext.cxx
@@ -30,7 +30,7 @@ namespace oox::drawingml {
namespace
{
-std::unordered_map<sal_Int32, model::SystemColorType> constSystemColorMap =
+const std::unordered_map<sal_Int32, model::SystemColorType> constSystemColorMap =
{
{ XML_scrollBar, model::SystemColorType::ScrollBar },
{ XML_background, model::SystemColorType::Background },
@@ -63,6 +63,39 @@ std::unordered_map<sal_Int32, model::SystemColorType> constSystemColorMap =
{ XML_menuHighlight, model::SystemColorType::MenuHighlight },
{ XML_menuBar, model::SystemColorType::MenuBar }
};
+
+const std::unordered_map<sal_Int32, model::TransformationType> constTransformTypeMap =
+{
+ { XML_alpha, model::TransformationType::Alpha },
+ { XML_alphaMod, model::TransformationType::AlphaMod },
+ { XML_alphaOff, model::TransformationType::AlphaOff },
+ { XML_blue, model::TransformationType::Blue },
+ { XML_blueMod, model::TransformationType::BlueMod },
+ { XML_blueOff, model::TransformationType::BlueOff },
+ { XML_hue, model::TransformationType::Hue },
+ { XML_hueMod, model::TransformationType::HueMod},
+ { XML_hueOff, model::TransformationType::HueOff },
+ { XML_lum, model::TransformationType::Lum },
+ { XML_lumMod, model::TransformationType::LumMod },
+ { XML_lumOff, model::TransformationType::LumOff },
+ { XML_green, model::TransformationType::Green },
+ { XML_greenMod, model::TransformationType::GreenMod },
+ { XML_greenOff, model::TransformationType::GreenOff },
+ { XML_red, model::TransformationType::Red },
+ { XML_redMod, model::TransformationType::RedMod },
+ { XML_redOff, model::TransformationType::RedOff },
+ { XML_sat, model::TransformationType::Sat },
+ { XML_satMod, model::TransformationType::SatMod },
+ { XML_satOff, model::TransformationType::SatMod },
+ { XML_shade, model::TransformationType::Shade },
+ { XML_tint, model::TransformationType::Tint },
+ { XML_comp, model::TransformationType::Comp },
+ { XML_gamma, model::TransformationType::Gamma },
+ { XML_gray, model::TransformationType::Gray },
+ { XML_inv, model::TransformationType::Inv },
+ { XML_invGamma, model::TransformationType::InvGamma }
+};
+
}
ColorValueContext::ColorValueContext(ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition)
@@ -168,6 +201,7 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs )
mrColor.setPrstClr(nToken);
if (mpColorDefinition)
{
+ // TODO - just converted to RGB for now
::Color nRgbValue = Color::getDmlPresetColor(nToken, API_RGB_TRANSPARENT);
mpColorDefinition->mnComponent1 = nRgbValue.GetRed();
mpColorDefinition->mnComponent2 = nRgbValue.GetGreen();
@@ -227,6 +261,26 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs )
mrColor.addTransformation( nElement );
break;
}
+
+ if (mpColorDefinition)
+ {
+ auto aIterator = constTransformTypeMap.find(getBaseToken(nElement));
+ if (aIterator != constTransformTypeMap.end())
+ {
+ auto const& aPair = *aIterator;
+ model::TransformationType eType = aPair.second;
+
+ OUString aValueString = rAttribs.getStringDefaulted(XML_val);
+ sal_Int32 nValue = 0;
+ if (aValueString.endsWith("%"))
+ nValue = aValueString.toDouble() * PER_PERCENT;
+ else
+ nValue = rAttribs.getInteger(XML_val, 0);
+
+ mpColorDefinition->maTransformations.push_back({eType, sal_Int16(nValue / 10.0)});
+ }
+ }
+
return nullptr;
}
diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx
index c94b195eef0e..f9270663a5bb 100644
--- a/sw/qa/core/theme/ThemeTest.cxx
+++ b/sw/qa/core/theme/ThemeTest.cxx
@@ -87,54 +87,175 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExistsDOCX)
CPPUNIT_ASSERT_EQUAL(size_t(3), rFormatScheme.getFillStyleList().size());
CPPUNIT_ASSERT_EQUAL(size_t(3), rFormatScheme.getBackgroundFillStyleList().size());
+ // Fill style 1
{
model::FillStyle const& rFillStyle = rFormatScheme.getFillStyleList().at(0);
CPPUNIT_ASSERT(rFillStyle.mpFill);
CPPUNIT_ASSERT_EQUAL(model::FillType::Solid, rFillStyle.mpFill->meType);
auto* pSolidFill = static_cast<model::SolidFill*>(rFillStyle.mpFill.get());
CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColorDefinition.meType);
+ CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColorDefinition.maTransformations.size());
}
+ // Fill style 2
{
model::FillStyle const& rFillStyle = rFormatScheme.getFillStyleList().at(1);
CPPUNIT_ASSERT(rFillStyle.mpFill);
CPPUNIT_ASSERT_EQUAL(model::FillType::Gradient, rFillStyle.mpFill->meType);
auto* pGradientFill = static_cast<model::GradientFill*>(rFillStyle.mpFill.get());
+
+ // Gradient Properties
CPPUNIT_ASSERT_EQUAL(model::GradientType::Linear, pGradientFill->meGradientType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5400000), pGradientFill->maLinearGradient.mnAngle);
+ CPPUNIT_ASSERT_EQUAL(false, pGradientFill->maLinearGradient.mbScaled);
+
+ // Gradient stops
CPPUNIT_ASSERT_EQUAL(size_t(3), pGradientFill->maGradientStops.size());
+ {
+ auto const& rGradientStop = pGradientFill->maGradientStops[0];
+ CPPUNIT_ASSERT_EQUAL(0.0, rGradientStop.mfPosition);
+ CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, rGradientStop.maColor.meType);
+ CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop.maColor.maTransformations.size());
- CPPUNIT_ASSERT_EQUAL(0.0, pGradientFill->maGradientStops[0].mfPosition);
- CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder,
- pGradientFill->maGradientStops[0].maColor.meType);
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[0];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(11000), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[1];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10500), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[2];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(6700), rTrasnsformation.mnValue);
+ }
+ }
+ {
+ auto const& rGradientStop = pGradientFill->maGradientStops[1];
+ CPPUNIT_ASSERT_EQUAL(0.5, rGradientStop.mfPosition);
+ CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, rGradientStop.maColor.meType);
+ CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop.maColor.maTransformations.size());
- CPPUNIT_ASSERT_EQUAL(0.5, pGradientFill->maGradientStops[1].mfPosition);
- CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder,
- pGradientFill->maGradientStops[1].maColor.meType);
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[0];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10500), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[1];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10300), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[2];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(7300), rTrasnsformation.mnValue);
+ }
+ }
+ {
+ auto const& rGradientStop = pGradientFill->maGradientStops[2];
+ CPPUNIT_ASSERT_EQUAL(1.0, rGradientStop.mfPosition);
+ CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, rGradientStop.maColor.meType);
+ CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop.maColor.maTransformations.size());
- CPPUNIT_ASSERT_EQUAL(1.0, pGradientFill->maGradientStops[2].mfPosition);
- CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder,
- pGradientFill->maGradientStops[2].maColor.meType);
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[0];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10500), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[1];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10900), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[2];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(8100), rTrasnsformation.mnValue);
+ }
+ }
}
+ // Fill style 3
{
model::FillStyle const& rFillStyle = rFormatScheme.getFillStyleList().at(2);
CPPUNIT_ASSERT(rFillStyle.mpFill);
CPPUNIT_ASSERT_EQUAL(model::FillType::Gradient, rFillStyle.mpFill->meType);
auto* pGradientFill = static_cast<model::GradientFill*>(rFillStyle.mpFill.get());
- CPPUNIT_ASSERT_EQUAL(model::GradientType::Linear, pGradientFill->meGradientType);
- CPPUNIT_ASSERT_EQUAL(size_t(3), pGradientFill->maGradientStops.size());
- CPPUNIT_ASSERT_EQUAL(0.0, pGradientFill->maGradientStops[0].mfPosition);
- CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder,
- pGradientFill->maGradientStops[0].maColor.meType);
-
- CPPUNIT_ASSERT_EQUAL(0.5, pGradientFill->maGradientStops[1].mfPosition);
- CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder,
- pGradientFill->maGradientStops[1].maColor.meType);
+ // Gradient Properties
+ CPPUNIT_ASSERT_EQUAL(model::GradientType::Linear, pGradientFill->meGradientType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5400000), pGradientFill->maLinearGradient.mnAngle);
+ CPPUNIT_ASSERT_EQUAL(false, pGradientFill->maLinearGradient.mbScaled);
- CPPUNIT_ASSERT_EQUAL(1.0, pGradientFill->maGradientStops[2].mfPosition);
- CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder,
- pGradientFill->maGradientStops[2].maColor.meType);
+ // Gradient Stops
+ CPPUNIT_ASSERT_EQUAL(size_t(3), pGradientFill->maGradientStops.size());
+ {
+ auto const& rGradientStop = pGradientFill->maGradientStops[0];
+ CPPUNIT_ASSERT_EQUAL(0.0, rGradientStop.mfPosition);
+ CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, rGradientStop.maColor.meType);
+ CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop.maColor.maTransformations.size());
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[0];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10300), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[1];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10200), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[2];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::Tint, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(9400), rTrasnsformation.mnValue);
+ }
+ }
+ {
+ auto const& rGradientStop = pGradientFill->maGradientStops[1];
+ CPPUNIT_ASSERT_EQUAL(0.5, rGradientStop.mfPosition);
+ CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, rGradientStop.maColor.meType);
+ CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop.maColor.maTransformations.size());
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[0];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(11000), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[1];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10000), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[2];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::Shade, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(10000), rTrasnsformation.mnValue);
+ }
+ }
+ {
+ auto const& rGradientStop = pGradientFill->maGradientStops[2];
+ CPPUNIT_ASSERT_EQUAL(1.0, rGradientStop.mfPosition);
+ CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, rGradientStop.maColor.meType);
+ CPPUNIT_ASSERT_EQUAL(size_t(3), rGradientStop.maColor.maTransformations.size());
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[0];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(9900), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[1];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::SatMod, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(12000), rTrasnsformation.mnValue);
+ }
+ {
+ auto const& rTrasnsformation = rGradientStop.maColor.maTransformations[2];
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::Shade, rTrasnsformation.meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(7800), rTrasnsformation.mnValue);
+ }
+ }
}
}