cui/qa/uitest/tabpages/tpcolor.py | 69 ++++++++++++++++++++ cui/source/inc/cuitabarea.hxx | 4 - cui/source/tabpages/tpcolor.cxx | 84 +++++++++++++++---------- include/oox/export/drawingml.hxx | 1 oox/qa/unit/data/refer-to-theme-shape-fill.odp |binary oox/qa/unit/export.cxx | 19 +++++ oox/source/export/drawingml.cxx | 28 ++++++++ 7 files changed, 171 insertions(+), 34 deletions(-)
New commits: commit cee85716085ace82a042c3701fdaa1b291b02774 Author: Miklos Vajna <[email protected]> AuthorDate: Wed Mar 30 19:57:10 2022 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Jul 1 08:47:02 2022 +0200 sd theme: add UI (area dialog) for shape fill color SvxColorTabPage::FillItemSet() has to produce a color item that has the theme index, which means SvxColorTabPage::SelectValSetHdl_Impl() has to change the current color to an svx::NamedThemedColor. The rest is just fallout from this, now that the current color has theming metadata. (cherry picked from commit 5dd4802c73dac4c3bd5c609562ce994d3b51e6a9) Conflicts: cui/source/tabpages/tpcolor.cxx Change-Id: If0018c651239ba74f45745e69e41ff7040ac9b97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136678 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/cui/qa/uitest/tabpages/tpcolor.py b/cui/qa/uitest/tabpages/tpcolor.py new file mode 100644 index 000000000000..e6ae91adaac3 --- /dev/null +++ b/cui/qa/uitest/tabpages/tpcolor.py @@ -0,0 +1,69 @@ +# +# 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/. +# + +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.framework import UITestCase +from uitest.uihelper.common import select_pos +from uitest.uihelper.common import select_by_text + + +# Test for cui/source/tabpages/tpcolor.cxx. +class Test(UITestCase): + + def testSvxColorTabPageTheme(self): + # Given an Impress document with a theme: + with self.ui_test.create_doc_in_start_center("impress") as component: + template = self.xUITest.getTopFocusWindow() + self.ui_test.close_dialog_through_button(template.getChild("close")) + doc = self.xUITest.getTopFocusWindow() + editWin = doc.getChild("impress_win") + # Set theme colors. + drawPage = component.getDrawPages().getByIndex(0) + master = drawPage.MasterPage + theme = mkPropertyValues({ + "Name": "nameA", + "ColorSchemeName": "colorSetA", + "ColorScheme": tuple([ + 0x000000, # dk1 + 0x000000, # lt1 + 0x000000, # dk2 + 0x000000, # lt2 + 0x0000ff, # accent1 + 0x000000, # accent2 + 0x000000, # accent3 + 0x000000, # accent4 + 0x000000, # accent5 + 0x000000, # accent6 + 0x000000, # hlink + 0x000000, # folHlink + ]) + }) + master.Theme = theme + # Select the title shape. + editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"})) + + # When using right click -> Area to refer to a theme for shape fill: + with self.ui_test.execute_dialog_through_command(".uno:FormatArea") as xDialog: + tabControl = xDialog.getChild("tabcontrol") + # Area + select_pos(tabControl, "0") + # Color + btnColor = xDialog.getChild("btncolor") + btnColor.executeAction("CLICK", tuple()) + paletteSelector = xDialog.getChild("paletteselector") + select_by_text(paletteSelector, "Theme colors") + colorSelector = xDialog.getChild("colorset") + colorSelector.executeAction("CHOOSE", mkPropertyValues({"POS": "4"})) + + # Then make sure the doc model is updated accordingly: + shape = drawPage.getByIndex(0) + # Without the accompanying fix in place, this test would have failed with: + # AssertionError: -1 != 4 + # i.e. the theme metadata of the selected fill color was lost. + self.assertEqual(shape.FillColorTheme, 4) + + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx index b5af2475a218..14cd6922631e 100644 --- a/cui/source/inc/cuitabarea.hxx +++ b/cui/source/inc/cuitabarea.hxx @@ -640,7 +640,7 @@ private: ColorModel eCM; Color aPreviousColor; - Color aCurrentColor; + svx::NamedThemedColor aCurrentColor; css::uno::Reference< css::uno::XComponentContext > m_context; @@ -698,7 +698,7 @@ private: DECL_LINK(SelectPaletteLBHdl, weld::ComboBox&, void); DECL_LINK( SelectValSetHdl_Impl, ValueSet*, void ); DECL_LINK( SelectColorModeHdl_Impl, weld::Toggleable&, void ); - void ChangeColor(const Color &rNewColor, bool bUpdatePreset = true); + void ChangeColor(const svx::NamedThemedColor &rNewColor, bool bUpdatePreset = true); void SetColorModel(ColorModel eModel); void ChangeColorModel(); void UpdateColorValues( bool bUpdatePreset = true ); diff --git a/cui/source/tabpages/tpcolor.cxx b/cui/source/tabpages/tpcolor.cxx index 9639ed1ac342..a6f3813f6e48 100644 --- a/cui/source/tabpages/tpcolor.cxx +++ b/cui/source/tabpages/tpcolor.cxx @@ -205,7 +205,9 @@ void SvxColorTabPage::ActivatePage( const SfxItemSet& ) ChangeColorModel(); const Color aColor = static_cast<const XFillColorItem*>(pPoolItem)->GetColorValue(); - ChangeColor( aColor ); + svx::NamedThemedColor aThemedColor; + aThemedColor.m_aColor = aColor; + ChangeColor( aThemedColor ); sal_Int32 nPos = FindInPalette( aColor ); if ( nPos != -1 ) @@ -232,12 +234,17 @@ bool SvxColorTabPage::FillItemSet( SfxItemSet* rSet ) { Color aColor = m_xValSetColorList->GetItemColor( m_xValSetColorList->GetSelectedItemId() ); OUString sColorName; - if ( aCurrentColor == aColor ) + if ( aCurrentColor.m_aColor == aColor ) sColorName = m_xValSetColorList->GetItemText( m_xValSetColorList->GetSelectedItemId() ); else - sColorName = "#" + aCurrentColor.AsRGBHexString().toAsciiUpperCase(); - maPaletteManager.AddRecentColor( aCurrentColor, sColorName ); - rSet->Put( XFillColorItem( sColorName, aCurrentColor ) ); + sColorName = "#" + aCurrentColor.m_aColor.AsRGBHexString().toAsciiUpperCase(); + maPaletteManager.AddRecentColor( aCurrentColor.m_aColor, sColorName ); + XFillColorItem aColorItem( sColorName, aCurrentColor.m_aColor ); + if (aCurrentColor.m_nThemeIndex != -1) + { + aColorItem.GetThemeColor().SetThemeIndex(aCurrentColor.m_nThemeIndex); + } + rSet->Put( aColorItem ); rSet->Put( XFillStyleItem( drawing::FillStyle_SOLID ) ); return true; } @@ -267,7 +274,9 @@ void SvxColorTabPage::Reset( const SfxItemSet* rSet ) SetColorModel( eCM ); ChangeColorModel(); - ChangeColor(aNewColor); + svx::NamedThemedColor aThemedColor; + aThemedColor.m_aColor = aNewColor; + ChangeColor(aThemedColor); UpdateModified(); } @@ -281,12 +290,12 @@ std::unique_ptr<SfxTabPage> SvxColorTabPage::Create(weld::Container* pPage, weld IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton&, void) { // read current MtrFields, if cmyk, then k-value as transparency - aCurrentColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())), + aCurrentColor.m_aColor = Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())), static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())), static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value()))); UpdateColorValues(); - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); @@ -295,13 +304,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton&, void) IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, weld::MetricSpinButton&, void) { // read current MtrFields, if cmyk, then k-value as transparency - aCurrentColor = Color(ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))), + aCurrentColor.m_aColor = Color(ColorTransparency, static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))), static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))), static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))), static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE)))); - ConvertColorValues (aCurrentColor, ColorModel::RGB); + ConvertColorValues (aCurrentColor.m_aColor, ColorModel::RGB); - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); @@ -309,10 +318,10 @@ IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, weld::MetricSpinButton IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl, weld::Entry&, void) { - aCurrentColor = m_xHexcustom->GetColor(); + aCurrentColor.m_aColor = m_xHexcustom->GetColor(); UpdateColorValues(); - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); @@ -366,13 +375,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, weld::Button&, void) sal_Int32 nSize = aCustomColorList.getLength(); aCustomColorList.realloc( nSize + 1 ); aCustomColorNameList.realloc( nSize + 1 ); - aCustomColorList.getArray()[nSize] = sal_Int32(aCurrentColor); + aCustomColorList.getArray()[nSize] = sal_Int32(aCurrentColor.m_aColor); aCustomColorNameList.getArray()[nSize] = aName; officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, batch); officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList, batch); batch->commit(); sal_uInt16 nId = m_xValSetColorList->GetItemId(nSize - 1); - m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor, aName ); + m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor.m_aColor, aName ); m_xValSetColorList->SelectItem( nId + 1 ); m_xBtnDelete->set_sensitive(false); m_xBtnDelete->set_tooltip_text( CuiResId(RID_SVXSTR_DELETEUSERCOLOR2) ); @@ -386,13 +395,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl, weld::Button&, void) { SvColorDialog aColorDlg; - aColorDlg.SetColor (aCurrentColor); + aColorDlg.SetColor (aCurrentColor.m_aColor); aColorDlg.SetMode( svtools::ColorPickerMode::Modify ); if (aColorDlg.Execute(GetFrameWeld()) == RET_OK) { Color aPreviewColor = aColorDlg.GetColor(); - aCurrentColor = aPreviewColor; + aCurrentColor.m_aColor = aPreviewColor; UpdateColorValues( false ); // fill ItemSet and pass it on to XOut rXFSet.Put( XFillColorItem( OUString(), aPreviewColor ) ); @@ -489,7 +498,20 @@ IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, ValueSet*, pValSet, void) rXFSet.Put( XFillColorItem( OUString(), aColor ) ); m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); m_aCtlPreviewNew.Invalidate(); - ChangeColor(aColor, false); + + bool bThemePaletteSelected = false; + if (pValSet == m_xValSetColorList.get()) + { + bThemePaletteSelected = maPaletteManager.IsThemePaletteSelected(); + } + svx::NamedThemedColor aThemedColor; + aThemedColor.m_aColor = aColor; + if (bThemePaletteSelected) + { + PaletteManager::GetThemeIndexLumModOff(nPos, aThemedColor.m_nThemeIndex, aThemedColor.m_nLumMod, aThemedColor.m_nLumOff); + } + + ChangeColor(aThemedColor, false); if (pValSet == m_xValSetColorList.get()) { @@ -552,13 +574,13 @@ IMPL_STATIC_LINK_NOARG(SvxColorTabPage, OnMoreColorsClick, weld::Button&, void) comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs); } -void SvxColorTabPage::ChangeColor(const Color &rNewColor, bool bUpdatePreset ) +void SvxColorTabPage::ChangeColor(const svx::NamedThemedColor &rNewColor, bool bUpdatePreset ) { - aPreviousColor = rNewColor; + aPreviousColor = rNewColor.m_aColor; aCurrentColor = rNewColor; UpdateColorValues( bUpdatePreset ); // fill ItemSet and pass it on to XOut - rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) ); + rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) ); m_aCtlPreviewNew.SetAttributes(aXFillAttr.GetItemSet()); m_aCtlPreviewNew.Invalidate(); } @@ -600,12 +622,12 @@ void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset ) if (eCM != ColorModel::RGB) { ConvertColorValues (aPreviousColor, eCM ); - ConvertColorValues (aCurrentColor, eCM); + ConvertColorValues (aCurrentColor.m_aColor, eCM); - m_xCcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ), FieldUnit::PERCENT ); - m_xMcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ), FieldUnit::PERCENT ); - m_xYcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ), FieldUnit::PERCENT ); - m_xKcustom->set_value( ColorToPercent_Impl( 255 - aCurrentColor.GetAlpha() ), FieldUnit::PERCENT ); + m_xCcustom->set_value( ColorToPercent_Impl( aCurrentColor.m_aColor.GetRed() ), FieldUnit::PERCENT ); + m_xMcustom->set_value( ColorToPercent_Impl( aCurrentColor.m_aColor.GetBlue() ), FieldUnit::PERCENT ); + m_xYcustom->set_value( ColorToPercent_Impl( aCurrentColor.m_aColor.GetGreen() ), FieldUnit::PERCENT ); + m_xKcustom->set_value( ColorToPercent_Impl( 255 - aCurrentColor.m_aColor.GetAlpha() ), FieldUnit::PERCENT ); if( bUpdatePreset ) { @@ -620,14 +642,14 @@ void SvxColorTabPage::UpdateColorValues( bool bUpdatePreset ) } ConvertColorValues (aPreviousColor, ColorModel::RGB); - ConvertColorValues (aCurrentColor, ColorModel::RGB); + ConvertColorValues (aCurrentColor.m_aColor, ColorModel::RGB); } else { - m_xRcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ) ); - m_xGcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ) ); - m_xBcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ) ); - m_xHexcustom->SetColor( aCurrentColor ); + m_xRcustom->set_value( ColorToPercent_Impl( aCurrentColor.m_aColor.GetRed() ) ); + m_xGcustom->set_value( ColorToPercent_Impl( aCurrentColor.m_aColor.GetGreen() ) ); + m_xBcustom->set_value( ColorToPercent_Impl( aCurrentColor.m_aColor.GetBlue() ) ); + m_xHexcustom->SetColor( aCurrentColor.m_aColor ); if( bUpdatePreset ) { commit 54272b950525fd6462006cb3624635e17b6008ae Author: Miklos Vajna <[email protected]> AuthorDate: Wed Mar 23 20:06:49 2022 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Jul 1 08:46:48 2022 +0200 sd theme: add PPTX export for shape fill color Do this only in case there are no effects on the color, as that is not yet handled. Note that the theme color was already stored in the grab-bag, so this is primarily interesting in case the theme color was changed or the source format was ODP. (cherry picked from commit 37c41f2c445ecf519f4137c23fb36f3942328b6b) Conflicts: oox/qa/unit/export.cxx Change-Id: Ia4995be68d5f243875632eec4aaf8afbb8f4d5cc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136677 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx index b15bf9d81aba..f2ef8c910da0 100644 --- a/include/oox/export/drawingml.hxx +++ b/include/oox/export/drawingml.hxx @@ -230,6 +230,7 @@ public: void WriteConnectorConnections( EscherConnectorListEntry& rConnectorEntry, sal_Int32 nStartID, sal_Int32 nEndID ); bool WriteCharColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet); + bool WriteFillColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet); void WriteSolidFill( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT ); void WriteSolidFill( const OUString& sSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT ); diff --git a/oox/qa/unit/data/refer-to-theme-shape-fill.odp b/oox/qa/unit/data/refer-to-theme-shape-fill.odp new file mode 100644 index 000000000000..b12772e111e3 Binary files /dev/null and b/oox/qa/unit/data/refer-to-theme-shape-fill.odp differ diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx index 960df6dd43e7..009e63d23e85 100644 --- a/oox/qa/unit/export.cxx +++ b/oox/qa/unit/export.cxx @@ -612,6 +612,25 @@ CPPUNIT_TEST_FIXTURE(Test, testReferToTheme) "75000"); 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) +{ + // Given an ODP file that contains references to a theme for shape fill: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "refer-to-theme-shape-fill.odp"; + + // When saving that document: + loadAndSave(aURL, "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. + std::unique_ptr<SvStream> pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr", "val", "accent1"); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 46098e9d04a3..23d67eb1c713 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -555,7 +555,10 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet ) else if ( nFillColor != nOriginalColor ) { // the user has set a different color for the shape - WriteSolidFill( ::Color(ColorTransparency, nFillColor & 0xffffff), nAlpha ); + if (aTransformations.hasElements() || !WriteFillColor(rXPropSet)) + { + WriteSolidFill(::Color(ColorTransparency, nFillColor & 0xffffff), nAlpha); + } } else if ( !sColorFillScheme.isEmpty() ) { @@ -570,6 +573,29 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet ) } } +bool DrawingML::WriteFillColor(const uno::Reference<beans::XPropertySet>& xPropertySet) +{ + if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("FillColorTheme")) + { + return false; + } + + sal_Int32 nFillColorTheme = -1; + xPropertySet->getPropertyValue("FillColorTheme") >>= nFillColorTheme; + if (nFillColorTheme < 0 || nFillColorTheme > 11) + { + return false; + } + + const char* pColorName = g_aPredefinedClrNames[nFillColorTheme]; + + mpFS->startElementNS(XML_a, XML_solidFill); + mpFS->singleElementNS(XML_a, XML_schemeClr, XML_val, pColorName); + mpFS->endElementNS(XML_a, XML_solidFill); + + return true; +} + void DrawingML::WriteGradientStop(sal_uInt16 nStop, ::Color nColor, sal_Int32 nAlpha) { mpFS->startElementNS(XML_a, XML_gs, XML_pos, OString::number(nStop * 1000));
