include/xmloff/xmltoken.hxx | 1 oox/inc/drawingml/fillproperties.hxx | 1 oox/source/drawingml/fillproperties.cxx | 11 ++ oox/source/drawingml/shape.cxx | 4 oox/source/token/properties.txt | 1 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng | 53 +++++++----- sd/source/core/stlsheet.cxx | 12 ++ svx/qa/unit/styles.cxx | 7 + svx/source/table/cell.cxx | 10 ++ svx/source/unodraw/unoshape.cxx | 11 ++ xmloff/inc/enummaps.hxx | 1 xmloff/qa/unit/data/refer-to-theme.odp |binary xmloff/qa/unit/draw.cxx | 6 + xmloff/source/core/xmltoken.cxx | 1 xmloff/source/draw/sdpropls.cxx | 4 xmloff/source/token/tokens.txt | 1 16 files changed, 97 insertions(+), 27 deletions(-)
New commits: commit 1e93905e5136149d09b5c591e0fe2366d759f429 Author: Miklos Vajna <[email protected]> AuthorDate: Thu Mar 17 20:37:39 2022 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Jul 1 08:46:36 2022 +0200 sd theme: add ODP import/export for shape fill color Refer to the 12 pre-defined colors by name + don't write the attribute for the case when there is no theme. (cherry picked from commit 1868dea877b0c956ee34e92afad59920e66cad3f) Change-Id: I37c984b3371ec878a0d733977f5c937dce27c440 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136676 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index 1f2e4163d9b1..18f94dac4545 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -3469,6 +3469,7 @@ namespace xmloff::token { XML_THEME, XML_THEME_COLOR, + XML_FILL_THEME_COLOR, XML_DK1, XML_LT1, XML_DK2, diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index 770ba54816f1..861b4481c1a6 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -1762,6 +1762,12 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. <rng:ref name="color"/> </rng:attribute> </rng:optional> + <!-- TODO 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="draw:secondary-fill-color"> <rng:ref name="color"/> @@ -2258,29 +2264,10 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. <rng:ref name="zeroToHundredPercent"/> </rng:attribute> </rng:optional> - <!-- TODO no proposal --> + <!-- TODO no proposal for theme color of shape text --> <rng:optional> <rng:attribute name="loext:theme-color"> - <rng:choice> - <!-- Background 1 --> - <rng:value>dk1</rng:value> - <!-- Text 1 --> - <rng:value>lt1</rng:value> - <!-- Background 2 --> - <rng:value>dk2</rng:value> - <!-- Text 2 --> - <rng:value>lt2</rng:value> - <rng:value>accent1</rng:value> - <rng:value>accent2</rng:value> - <rng:value>accent3</rng:value> - <rng:value>accent4</rng:value> - <rng:value>accent5</rng:value> - <rng:value>accent6</rng:value> - <!-- Hyperlink --> - <rng:value>hlink</rng:value> - <!-- Followed hyperlink --> - <rng:value>folHlink</rng:value> - </rng:choice> + <rng:ref name="theme-color"/> </rng:attribute> </rng:optional> <rng:optional> @@ -3116,7 +3103,7 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. <rng:ref name="office-forms"/> </rng:optional> <rng:optional> - <!-- TODO no proposal --> + <!-- TODO no proposal for defining a theme --> <rng:ref name="loext-theme"/> </rng:optional> <rng:zeroOrMore> @@ -3130,4 +3117,26 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. </rng:optional> </rng:element> </rng:define> + <rng:define name="theme-color"> + <rng:choice> + <!-- Background 1 --> + <rng:value>dk1</rng:value> + <!-- Text 1 --> + <rng:value>lt1</rng:value> + <!-- Background 2 --> + <rng:value>dk2</rng:value> + <!-- Text 2 --> + <rng:value>lt2</rng:value> + <rng:value>accent1</rng:value> + <rng:value>accent2</rng:value> + <rng:value>accent3</rng:value> + <rng:value>accent4</rng:value> + <rng:value>accent5</rng:value> + <rng:value>accent6</rng:value> + <!-- Hyperlink --> + <rng:value>hlink</rng:value> + <!-- Followed hyperlink --> + <rng:value>folHlink</rng:value> + </rng:choice> + </rng:define> </rng:grammar> diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx index 30b4bc38eee8..feff63dbf69a 100644 --- a/sd/source/core/stlsheet.cxx +++ b/sd/source/core/stlsheet.cxx @@ -51,6 +51,7 @@ #include <svx/sdtayitm.hxx> #include <svx/sdtaiitm.hxx> #include <svx/xit.hxx> +#include <svx/xflclit.hxx> #include <tools/diagnose_ex.h> #include <stlsheet.hxx> #include <sdresid.hxx> @@ -1315,6 +1316,17 @@ PropertyState SAL_CALL SdStyleSheet::getPropertyState( const OUString& PropertyN if( ( pItem == nullptr ) || pItem->GetName().isEmpty() ) eState = PropertyState_DEFAULT_VALUE; } + break; + case XATTR_FILLCOLOR: + if (pEntry->nMemberId == MID_COLOR_THEME_INDEX) + { + const XFillColorItem* pColor = rStyleSet.GetItem<XFillColorItem>(pEntry->nWID); + if (pColor->GetThemeColor().GetThemeIndex() == -1) + { + eState = PropertyState_DEFAULT_VALUE; + } + } + break; } } diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx index f09de95e7826..5cb09e43bd35 100644 --- a/svx/source/table/cell.cxx +++ b/svx/source/table/cell.cxx @@ -56,6 +56,7 @@ #include <svx/xflbstit.hxx> #include <svx/xflbmtit.hxx> #include <svx/svdpool.hxx> +#include <svx/xflclit.hxx> #include <tools/diagnose_ex.h> @@ -1442,6 +1443,15 @@ PropertyState SAL_CALL Cell::getPropertyState( const OUString& PropertyName ) eState = PropertyState_DEFAULT_VALUE; } break; + case XATTR_FILLCOLOR: + if (pMap->nMemberId == MID_COLOR_THEME_INDEX) + { + const XFillColorItem* pColor = rSet.GetItem<XFillColorItem>(pMap->nWID); + if (pColor->GetThemeColor().GetThemeIndex() == -1) + { + eState = PropertyState_DEFAULT_VALUE; + } + } } } } diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index ee3e58dd0190..78285121aa4d 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -88,6 +88,7 @@ #include <svx/svdoutl.hxx> #include <svx/svdopath.hxx> #include <svx/SvxXTextColumns.hxx> +#include <svx/xflclit.hxx> #include <memory> #include <optional> @@ -2039,6 +2040,16 @@ beans::PropertyState SvxShape::_getPropertyState( const OUString& PropertyName ) eState = beans::PropertyState_DEFAULT_VALUE; } break; + case XATTR_FILLCOLOR: + if (pMap->nMemberId == MID_COLOR_THEME_INDEX) + { + const XFillColorItem* pColor = rSet.GetItem<XFillColorItem>(pMap->nWID); + if (pColor->GetThemeColor().GetThemeIndex() == -1) + { + eState = beans::PropertyState_DEFAULT_VALUE; + } + } + break; } } } diff --git a/xmloff/inc/enummaps.hxx b/xmloff/inc/enummaps.hxx index ae61adc3433a..a170559af996 100644 --- a/xmloff/inc/enummaps.hxx +++ b/xmloff/inc/enummaps.hxx @@ -19,5 +19,6 @@ template <typename EnumT> struct SvXMLEnumMapEntry; extern SvXMLEnumMapEntry<css::drawing::FillStyle> const aXML_FillStyle_EnumMap[]; extern SvXMLEnumMapEntry<css::drawing::RectanglePoint> const aXML_RefPoint_EnumMap[]; extern SvXMLEnumMapEntry<css::drawing::BitmapMode> const aXML_BitmapMode_EnumMap[]; +extern SvXMLEnumMapEntry<sal_uInt16> const pXML_ThemeColor_Enum[]; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/xmloff/qa/unit/data/refer-to-theme.odp b/xmloff/qa/unit/data/refer-to-theme.odp index cba4bfda1538..5fe9832d3eee 100644 Binary files a/xmloff/qa/unit/data/refer-to-theme.odp and b/xmloff/qa/unit/data/refer-to-theme.odp differ diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx index b354975fd891..4e05b3f7f788 100644 --- a/xmloff/qa/unit/draw.cxx +++ b/xmloff/qa/unit/draw.cxx @@ -218,6 +218,12 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testReferToTheme) "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"); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 6124ded2dcdb..1b0adb6d210d 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3472,6 +3472,7 @@ namespace xmloff::token { TOKEN("theme", XML_THEME ), TOKEN("theme-color", XML_THEME_COLOR ), + TOKEN("fill-theme-color", XML_FILL_THEME_COLOR ), TOKEN("dk1", XML_DK1 ), TOKEN("lt1", XML_LT1 ), TOKEN("dk2", XML_DK2 ), diff --git a/xmloff/source/draw/sdpropls.cxx b/xmloff/source/draw/sdpropls.cxx index c554b2411f6e..49ed30583814 100644 --- a/xmloff/source/draw/sdpropls.cxx +++ b/xmloff/source/draw/sdpropls.cxx @@ -106,6 +106,7 @@ const XMLPropertyMapEntry aXMLSDProperties[] = GMAP( "FillStyle", XML_NAMESPACE_DRAW, XML_FILL, XML_SD_TYPE_FILLSTYLE, CTF_FILLSTYLE ), GMAP_D("FillColor", XML_NAMESPACE_DRAW, XML_FILL_COLOR, XML_TYPE_COLOR, CTF_FILLCOLOR ), GMAP_D("FillColor2", XML_NAMESPACE_DRAW, XML_SECONDARY_FILL_COLOR, XML_TYPE_COLOR, 0), + GMAPV("FillColorTheme", XML_NAMESPACE_LO_EXT, XML_FILL_THEME_COLOR, XML_TYPE_THEME_COLOR, 0, SvtSaveOptions::ODFSVER_FUTURE_EXTENDED), GMAP( "FillGradientName", XML_NAMESPACE_DRAW, XML_FILL_GRADIENT_NAME, XML_TYPE_STYLENAME|MID_FLAG_NO_PROPERTY_IMPORT, CTF_FILLGRADIENTNAME ), GMAP( "FillGradientStepCount", XML_NAMESPACE_DRAW, XML_GRADIENT_STEP_COUNT, XML_TYPE_NUMBER16, 0 ), GMAP( "FillHatchName", XML_NAMESPACE_DRAW, XML_FILL_HATCH_NAME, XML_TYPE_STYLENAME|MID_FLAG_NO_PROPERTY_IMPORT, CTF_FILLHATCHNAME ), @@ -1281,6 +1282,9 @@ const XMLPropertyHandler* XMLSdPropHdlFactory::GetPropertyHandler( sal_Int32 nTy case XML_TYPE_TEXT_COLUMNS: pHdl = new XMLTextColumnsPropertyHandler; break; + case XML_TYPE_THEME_COLOR: + pHdl = new XMLConstantsPropertyHandler(pXML_ThemeColor_Enum, XML_TOKEN_INVALID); + break; } if(pHdl) diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index d41caf51445d..1183988d9eae 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3216,6 +3216,7 @@ symmetric linked-style-name theme theme-color +fill-theme-color dk1 lt1 dk2 commit b7b56e6031b77f23a3d8bd1431eae06df05c28c4 Author: Miklos Vajna <[email protected]> AuthorDate: Wed Mar 9 20:51:34 2022 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Jul 1 08:46:22 2022 +0200 sd theme: add PPTX import for shape fill color The theme index is typically not a direct property, but comes from style -> fillref -> theme index, so support that. (cherry picked from commit f5089e745367e111fb02c493c8c90e96a29e199c) Change-Id: I00733db44bb5321019bbc7337d10feb0a34661a2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136675 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/oox/inc/drawingml/fillproperties.hxx b/oox/inc/drawingml/fillproperties.hxx index f308f6aaec0d..532cb0ec3975 100644 --- a/oox/inc/drawingml/fillproperties.hxx +++ b/oox/inc/drawingml/fillproperties.hxx @@ -145,6 +145,7 @@ struct FillProperties const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation = 0, ::Color nPhClr = API_RGB_TRANSPARENT, + sal_Int16 nPhClrTheme = -1, bool bFlipH = false, bool bFlipV = false, bool bIsCustomShape = false ) const; diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index be7e86d7d029..f0b092bbb774 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -377,7 +377,7 @@ Color FillProperties::getBestSolidColor() const } void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, - const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, ::Color nPhClr, + const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, ::Color nPhClr, sal_Int16 nPhClrTheme, bool bFlipH, bool bFlipV, bool bIsCustomShape) const { if( !moFillType.has() ) @@ -394,9 +394,16 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, case XML_solidFill: if( maFillColor.isUsed() ) { - rPropMap.setProperty( ShapeProperty::FillColor, maFillColor.getColor( rGraphicHelper, nPhClr ) ); + ::Color aFillColor = maFillColor.getColor(rGraphicHelper, nPhClr); + rPropMap.setProperty(ShapeProperty::FillColor, aFillColor); if( maFillColor.hasTransparency() ) rPropMap.setProperty( ShapeProperty::FillTransparency, maFillColor.getTransparency() ); + + if (aFillColor == nPhClr) + { + rPropMap.setProperty(PROP_FillColorTheme, nPhClrTheme); + } + eFillStyle = FillStyle_SOLID; } break; diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index bebcbae240b6..e76d2386c800 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -1047,6 +1047,7 @@ Reference< XShape > const & Shape::createAndInsert( ::Color nLinePhClr(ColorTransparency, 0xffffffff); ::Color nFillPhClr(ColorTransparency, 0xffffffff); + sal_Int16 nFillPhClrTheme = -1; // TODO: use ph color when applying effect properties //sal_Int32 nEffectPhClr = -1; @@ -1083,6 +1084,7 @@ Reference< XShape > const & Shape::createAndInsert( if (!mbUseBgFill) { nFillPhClr = pFillRef->maPhClr.getColor(rGraphicHelper); + nFillPhClrTheme = pFillRef->maPhClr.getSchemeColorIndex(); } OUString sColorScheme = pFillRef->maPhClr.getSchemeColorName(); @@ -1145,7 +1147,7 @@ Reference< XShape > const & Shape::createAndInsert( if (getFillProperties().moFillType.has() && getFillProperties().moFillType.get() == XML_grpFill) getFillProperties().assignUsed(aFillProperties); if(!bIsCroppedGraphic) - aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr, mbFlipH, mbFlipV, bIsCustomShape ); + aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr, nFillPhClrTheme, mbFlipH, mbFlipV, bIsCustomShape ); LineProperties aLineProperties = getActualLineProperties(pTheme); aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr ); EffectProperties aEffectProperties = getActualEffectProperties(pTheme); diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index 87a6700bd35a..e318e0038ecb 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -176,6 +176,7 @@ FillBitmapSizeX FillBitmapSizeY FillBitmap FillColor +FillColorTheme FillGradient FillGradientName FillHatch diff --git a/svx/qa/unit/styles.cxx b/svx/qa/unit/styles.cxx index 3881fe1d1006..3bfa6d8cf09b 100644 --- a/svx/qa/unit/styles.cxx +++ b/svx/qa/unit/styles.cxx @@ -93,8 +93,11 @@ CPPUNIT_TEST_FIXTURE(Test, testThemeChange) uno::Reference<beans::XPropertySet> xShape4(xDrawPageShapes->getByIndex(4), uno::UNO_QUERY); // Blue. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4472c4), GetShapeFillColor(xShape4)); - // Set theme index to accent 1 till PPTX import is missing. - xShape4->setPropertyValue("FillColorTheme", uno::makeAny(static_cast<sal_Int16>(4))); + // The theme index of this filled shape is set by the PPTX import: + sal_Int32 nColorTheme = -1; + xShape4->getPropertyValue("FillColorTheme") >>= nColorTheme; + // 4 means accent1, this was -1 without the PPTX import bit in place. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), nColorTheme); // When changing the master slide of slide 1 to use the theme of the second master slide: uno::Reference<drawing::XMasterPageTarget> xDrawPage2(
