summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-01-05 13:12:34 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-01-13 23:07:22 +0000
commitaf8fdba1194e657237f9abc460381a1c4bc49982 (patch)
tree706c2a25bf0e477a07beaf8047a1f4002c3fe2d5 /oox
parentc9b0eacae71f111209cb77f14f2693d73e5e8d90 (diff)
support theme color for lines + oox support + tests
Extended XLineColor to handle model::ThemeColor which then maps to the newly added LineColorThemeData property. Extended oox import and export to map the scheme color elements to and from ThemeColor. Added a new test to check the theme line color in impress shapes. Change-Id: I23ecc18c88b5b47608c9110f5681f189d02e2f36 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145071 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/inc/drawingml/lineproperties.hxx3
-rw-r--r--oox/qa/unit/data/ThemeShapesReference.pptxbin0 -> 42644 bytes
-rw-r--r--oox/qa/unit/drawingml.cxx71
-rw-r--r--oox/source/drawingml/lineproperties.cxx34
-rw-r--r--oox/source/drawingml/shape.cxx4
-rw-r--r--oox/source/export/drawingml.cxx64
-rw-r--r--oox/source/token/properties.txt1
7 files changed, 121 insertions, 56 deletions
diff --git a/oox/inc/drawingml/lineproperties.hxx b/oox/inc/drawingml/lineproperties.hxx
index f2d37a7f8a9f..52c27825bdaf 100644
--- a/oox/inc/drawingml/lineproperties.hxx
+++ b/oox/inc/drawingml/lineproperties.hxx
@@ -69,7 +69,8 @@ struct LineProperties
void pushToPropMap(
ShapePropertyMap& rPropMap,
const GraphicHelper& rGraphicHelper,
- ::Color nPhClr = API_RGB_TRANSPARENT ) const;
+ ::Color nPhClr = API_RGB_TRANSPARENT,
+ sal_Int16 nPhClrTheme = -1) const;
/** Calculates the line style attribute from the internal state of the object */
css::drawing::LineStyle getLineStyle() const;
diff --git a/oox/qa/unit/data/ThemeShapesReference.pptx b/oox/qa/unit/data/ThemeShapesReference.pptx
new file mode 100644
index 000000000000..d871cc56a099
--- /dev/null
+++ b/oox/qa/unit/data/ThemeShapesReference.pptx
Binary files differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index f47853e3b5f7..5c09ca3de463 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -439,7 +439,7 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf132557_footerCustomShapes)
xShapeSlideNum->getShapeType());
}
-CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testThemeTint)
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testThemeColorTint_Table)
{
// Given a document with a table style, using theme color with tinting in the A2 cell:
loadFromURL(u"theme-tint.pptx");
@@ -483,6 +483,75 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testThemeTint)
}
}
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testThemeColor_Shape)
+{
+ // Given a document with a table style, using theme color with tinting in the A2 cell:
+ loadFromURL(u"ThemeShapesReference.pptx");
+
+ // Then make sure that we only import theming info to the doc model if the effects are limited
+ // to lum mod / off that we can handle (i.e. no tint/shade):
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+
+ // check line and fill theme color of shape1
+ {
+ model::ThemeColor aThemeColor;
+ uno::Reference<util::XThemeColor> xThemeColor;
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+
+ CPPUNIT_ASSERT(xShape->getPropertyValue("FillColorThemeReference") >>= xThemeColor);
+ CPPUNIT_ASSERT(xThemeColor.is());
+ model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+ CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent6, aThemeColor.getType());
+ {
+ auto const& rTrans = aThemeColor.getTransformations();
+ CPPUNIT_ASSERT_EQUAL(size_t(2), rTrans.size());
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans[0].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(4000), rTrans[0].mnValue);
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTrans[1].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(6000), rTrans[1].mnValue);
+ }
+
+ CPPUNIT_ASSERT(xShape->getPropertyValue("LineColorThemeReference") >>= xThemeColor);
+ CPPUNIT_ASSERT(xThemeColor.is());
+ model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+ CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent6, aThemeColor.getType());
+ {
+ auto const& rTrans = aThemeColor.getTransformations();
+ CPPUNIT_ASSERT_EQUAL(size_t(1), rTrans.size());
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans[0].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTrans[0].mnValue);
+ }
+ }
+ // check line and fill theme color of shape2
+ {
+ model::ThemeColor aThemeColor;
+ uno::Reference<util::XThemeColor> xThemeColor;
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
+
+ CPPUNIT_ASSERT(xShape->getPropertyValue("FillColorThemeReference") >>= xThemeColor);
+ CPPUNIT_ASSERT(xThemeColor.is());
+ model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+ CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aThemeColor.getType());
+ {
+ auto const& rTrans = aThemeColor.getTransformations();
+ CPPUNIT_ASSERT_EQUAL(size_t(0), rTrans.size());
+ }
+
+ CPPUNIT_ASSERT(xShape->getPropertyValue("LineColorThemeReference") >>= xThemeColor);
+ CPPUNIT_ASSERT(xThemeColor.is());
+ model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
+ CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aThemeColor.getType());
+ {
+ auto const& rTrans = aThemeColor.getTransformations();
+ CPPUNIT_ASSERT_EQUAL(size_t(1), rTrans.size());
+ CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTrans[0].meType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(7500), rTrans[0].mnValue);
+ }
+ }
+}
+
CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testVert270AndTextRot)
{
// tdf##149551. The document contains a shape with attributes 'rot="720000"' and 'vert="vert270"'
diff --git a/oox/source/drawingml/lineproperties.cxx b/oox/source/drawingml/lineproperties.cxx
index e1cef771c24e..8e9d676de800 100644
--- a/oox/source/drawingml/lineproperties.cxx
+++ b/oox/source/drawingml/lineproperties.cxx
@@ -33,6 +33,9 @@
#include <oox/drawingml/shapepropertymap.hxx>
#include <oox/helper/graphichelper.hxx>
#include <oox/token/tokens.hxx>
+#include <oox/token/properties.hxx>
+#include <docmodel/uno/UnoThemeColor.hxx>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
@@ -430,7 +433,7 @@ void LineProperties::assignUsed( const LineProperties& rSourceProps )
}
void LineProperties::pushToPropMap( ShapePropertyMap& rPropMap,
- const GraphicHelper& rGraphicHelper, ::Color nPhClr ) const
+ const GraphicHelper& rGraphicHelper, ::Color nPhClr, sal_Int16 nPhClrTheme) const
{
// line fill type must exist, otherwise ignore other properties
if( !maLineFill.moFillType.has_value() )
@@ -491,11 +494,36 @@ void LineProperties::pushToPropMap( ShapePropertyMap& rPropMap,
// line color and transparence
Color aLineColor = maLineFill.getBestSolidColor();
- if( aLineColor.isUsed() )
+ if (aLineColor.isUsed())
{
- rPropMap.setProperty( ShapeProperty::LineColor, aLineColor.getColor( rGraphicHelper, nPhClr ) );
+ ::Color aColor = aLineColor.getColor(rGraphicHelper, nPhClr);
+ rPropMap.setProperty(ShapeProperty::LineColor, aColor);
if( aLineColor.hasTransparency() )
rPropMap.setProperty( ShapeProperty::LineTransparency, aLineColor.getTransparency() );
+
+ model::ThemeColor aThemeColor;
+
+ if (aColor == nPhClr)
+ {
+ aThemeColor.setType(model::convertToThemeColorType(nPhClrTheme));
+ rPropMap.setProperty(PROP_LineColorThemeReference, model::theme::createXThemeColor(aThemeColor));
+ }
+ else
+ {
+ aThemeColor.setType(model::convertToThemeColorType(aLineColor.getSchemeColorIndex()));
+ if (aLineColor.getLumMod() != 10000)
+ aThemeColor.addTransformation({model::TransformationType::LumMod, aLineColor.getLumMod()});
+ if (aLineColor.getLumOff() != 0)
+ aThemeColor.addTransformation({model::TransformationType::LumOff, aLineColor.getLumOff()});
+ if (aLineColor.getTintOrShade() > 0)
+ aThemeColor.addTransformation({model::TransformationType::Tint, aLineColor.getTintOrShade()});
+ if (aLineColor.getTintOrShade() < 0)
+ {
+ sal_Int16 nShade = o3tl::narrowing<sal_Int16>(-aLineColor.getTintOrShade());
+ aThemeColor.addTransformation({model::TransformationType::Shade, nShade});
+ }
+ rPropMap.setProperty(PROP_LineColorThemeReference, model::theme::createXThemeColor(aThemeColor));
+ }
}
// line markers
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index c7d4567dd0c2..b3162381534a 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -1167,6 +1167,7 @@ Reference< XShape > const & Shape::createAndInsert(
::Color nLinePhClr(ColorTransparency, 0xffffffff);
::Color nFillPhClr(ColorTransparency, 0xffffffff);
sal_Int16 nFillPhClrTheme = -1;
+ sal_Int16 nLinePhClrTheme = -1;
// TODO: use ph color when applying effect properties
//sal_Int32 nEffectPhClr = -1;
@@ -1183,6 +1184,7 @@ Reference< XShape > const & Shape::createAndInsert(
if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) )
aLineProperties.assignUsed( *pLineProps );
nLinePhClr = pLineRef->maPhClr.getColor( rGraphicHelper );
+ nLinePhClrTheme = pLineRef->maPhClr.getSchemeColorIndex();
// Store style-related properties to InteropGrabBag to be able to export them back
uno::Sequence<beans::PropertyValue> aProperties = comphelper::InitPropertySequence(
@@ -1275,7 +1277,7 @@ Reference< XShape > const & Shape::createAndInsert(
if(!bIsCroppedGraphic)
aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr, nFillPhClrTheme, mbFlipH, mbFlipV, bIsCustomShape );
LineProperties aLineProperties = getActualLineProperties(pTheme);
- aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr );
+ aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr, nLinePhClrTheme);
EffectProperties aEffectProperties = getActualEffectProperties(pTheme);
// TODO: use ph color when applying effect properties
aEffectProperties.pushToPropMap( aShapeProps, rGraphicHelper );
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index dde41bd16c35..751aabc859eb 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -432,49 +432,6 @@ void DrawingML::WriteColorTransformations( const Sequence< PropertyValue >& aTra
}
}
-bool DrawingML::WriteCharColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet)
-{
- if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("CharColorThemeReference"))
- return false;
-
- uno::Reference<util::XThemeColor> xThemeColor;
- xPropertySet->getPropertyValue("CharColorThemeReference") >>= xThemeColor;
- if (!xThemeColor.is())
- return false;
-
- 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);
- for (auto const& rTransform : aThemeColor.getTransformations())
- {
- 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);
-
- return true;
-}
-
void DrawingML::WriteSolidFill( ::Color nColor, sal_Int32 nAlpha )
{
mpFS->startElementNS(XML_a, XML_solidFill);
@@ -567,7 +524,7 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet )
else if ( nFillColor != nOriginalColor )
{
// the user has set a different color for the shape
- if (!WriteFillColor(rXPropSet))
+ if (!WriteSchemeColor(u"FillColorThemeReference", rXPropSet))
{
WriteSolidFill(::Color(ColorTransparency, nFillColor & 0xffffff), nAlpha);
}
@@ -585,13 +542,13 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet )
}
}
-bool DrawingML::WriteFillColor(const uno::Reference<beans::XPropertySet>& xPropertySet)
+bool DrawingML::WriteSchemeColor(OUString const& rPropertyName, const uno::Reference<beans::XPropertySet>& xPropertySet)
{
- if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("FillColorThemeReference"))
+ if (!xPropertySet->getPropertySetInfo()->hasPropertyByName(rPropertyName))
return false;
uno::Reference<util::XThemeColor> xThemeColor;
- xPropertySet->getPropertyValue("FillColorThemeReference") >>= xThemeColor;
+ xPropertySet->getPropertyValue(rPropertyName) >>= xThemeColor;
if (!xThemeColor.is())
return false;
@@ -612,6 +569,12 @@ bool DrawingML::WriteFillColor(const uno::Reference<beans::XPropertySet>& xPrope
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;
}
@@ -1072,7 +1035,8 @@ void DrawingML::WriteOutline( const Reference<XPropertySet>& rXPropSet, Referenc
if( nColor != nOriginalColor )
{
// the user has set a different color for the line
- WriteSolidFill( nColor, nColorAlpha );
+ if (!WriteSchemeColor(u"LineColorThemeReference", rXPropSet))
+ WriteSolidFill(nColor, nColorAlpha);
}
else if( !sColorFillScheme.isEmpty() )
{
@@ -2396,7 +2360,7 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool
else
{
color.SetAlpha(255);
- if (!WriteCharColor(rXPropSet))
+ if (!WriteSchemeColor(u"CharColorThemeReference", rXPropSet))
WriteSolidFill(color, nTransparency);
}
mpFS->endElementNS(XML_a, XML_ln);
@@ -2409,7 +2373,7 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool
{
color.SetAlpha(255);
// TODO: special handle embossed/engraved
- if (!WriteCharColor(rXPropSet))
+ if (!WriteSchemeColor(u"CharColorThemeReference", rXPropSet))
{
WriteSolidFill(color, nTransparency);
}
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index 439ecc9cd8a0..43bed81c5d62 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -316,6 +316,7 @@ LeftPageHeaderContent
LegacyFragment
LineCap
LineColor
+LineColorThemeReference
LineCount
LineDash
LineDashName