diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-12-09 08:43:27 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-29 09:04:07 +0200 |
commit | ae2b901849bbc6a1a75ea3c9b855676617e0958e (patch) | |
tree | 6e63b27320e56ed008706c583698aa518e7ffedc /xmloff | |
parent | 3d210f998928cb00e6989d9c2ad64ef1fa699175 (diff) |
ODP import/export: refer to theme from shape text 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 91f649a119d4b7ece26f9737a38663664953a57a)
Conflicts:
xmloff/source/token/tokens.txt
Change-Id: Ib6ab5b7b34d896a36e04309bf0cb410998acce01
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136527
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/qa/unit/data/refer-to-theme.odp | bin | 0 -> 14488 bytes | |||
-rw-r--r-- | xmloff/qa/unit/draw.cxx | 24 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 13 | ||||
-rw-r--r-- | xmloff/source/draw/sdxmlexp.cxx | 30 | ||||
-rw-r--r-- | xmloff/source/text/txtprhdl.cxx | 20 | ||||
-rw-r--r-- | xmloff/source/text/txtprmap.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 13 |
7 files changed, 87 insertions, 15 deletions
diff --git a/xmloff/qa/unit/data/refer-to-theme.odp b/xmloff/qa/unit/data/refer-to-theme.odp Binary files differnew file mode 100644 index 000000000000..83bad49b5f56 --- /dev/null +++ b/xmloff/qa/unit/data/refer-to-theme.odp diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx index f3bab2a69996..2ea5ec785f44 100644 --- a/xmloff/qa/unit/draw.cxx +++ b/xmloff/qa/unit/draw.cxx @@ -179,6 +179,30 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeImport) CPPUNIT_ASSERT_EQUAL(static_cast<util::Color>(0x954F72), aColorScheme[11]); } +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testReferToTheme) +{ + // Given a document that refers to a theme color: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "refer-to-theme.odp"; + + // When loading and saving that document: + getComponent() = loadFromDesktop(aURL); + utl::TempFile aTempFile; + save("impress8", aTempFile); + + // Make sure the export result has the theme reference: + std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//style:style[@style:name='T1']/style:text-properties' no attribute 'theme-color' exist + // i.e. only the direct color was written, but not the theme reference. + assertXPath(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", "theme-color", + "accent1"); + assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "theme-color", + "accent1"); + assertXPath(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", "theme-color", + "accent1"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index cd8186c89617..6f6e02ecbe9c 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3471,6 +3471,19 @@ namespace xmloff::token { TOKEN("linked-style-name", XML_LINKED_STYLE_NAME ), TOKEN("theme", XML_THEME ), + TOKEN("theme-color", XML_THEME_COLOR ), + TOKEN("dk1", XML_DK1 ), + TOKEN("lt1", XML_LT1 ), + TOKEN("dk2", XML_DK2 ), + TOKEN("lt2", XML_LT2 ), + TOKEN("accent1", XML_ACCENT1 ), + TOKEN("accent2", XML_ACCENT2 ), + TOKEN("accent3", XML_ACCENT3 ), + TOKEN("accent4", XML_ACCENT4 ), + TOKEN("accent5", XML_ACCENT5 ), + TOKEN("accent6", XML_ACCENT6 ), + TOKEN("hlink", XML_HLINK ), + TOKEN("folHlink", XML_FOLHLINK ), TOKEN("content-control", XML_CONTENT_CONTROL ), TOKEN("showing-place-holder", XML_SHOWING_PLACE_HOLDER ), diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx index 9388cedb25e4..b789f7342d90 100644 --- a/xmloff/source/draw/sdxmlexp.cxx +++ b/xmloff/source/draw/sdxmlexp.cxx @@ -2410,26 +2410,26 @@ void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x } SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, XML_COLOR_TABLE, true, true); - static const std::u16string_view aColorNames[] = { - u"dk1", // Background 1 - u"lt1", // Text 1 - u"dk2", // Background 2 - u"lt2", // Text 2 - u"accent1", // Accent 1 - u"accent2", // Accent 2 - u"accent3", // Accent 3 - u"accent4", // Accent 4 - u"accent5", // Accent 5 - u"accent6", // Accent 6 - u"hlink", // Hyperlink - u"folHlink", // Followed hyperlink + static const XMLTokenEnum aColorTokens[] = { + XML_DK1, // Background 1 + XML_LT1, // Text 1 + XML_DK2, // Background 2 + XML_LT2, // Text 2 + XML_ACCENT1, + XML_ACCENT2, + XML_ACCENT3, + XML_ACCENT4, + XML_ACCENT5, + XML_ACCENT6, + XML_HLINK, // Hyperlink + XML_FOLHLINK, // Followed hyperlink }; for (size_t nColor = 0; nColor < aColors.size(); ++nColor) { // Import goes via svx::Theme::FromAny(), which sanitizes user input. - assert(nColor < SAL_N_ELEMENTS(aColorNames)); + assert(nColor < SAL_N_ELEMENTS(aColorTokens)); - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, OUString(aColorNames[nColor])); + AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, GetXMLToken(aColorTokens[nColor])); OUStringBuffer sValue; sax::Converter::convertColor(sValue, aColors[nColor]); diff --git a/xmloff/source/text/txtprhdl.cxx b/xmloff/source/text/txtprhdl.cxx index 2068c9b934a6..22fbe4174dd6 100644 --- a/xmloff/source/text/txtprhdl.cxx +++ b/xmloff/source/text/txtprhdl.cxx @@ -249,6 +249,23 @@ SvXMLEnumMapEntry<drawing::TextVerticalAdjust> const pXML_VerticalAlign_Enum[] = { XML_TOKEN_INVALID, drawing::TextVerticalAdjust(0) } }; +SvXMLEnumMapEntry<sal_uInt16> const pXML_ThemeColor_Enum[] = +{ + { XML_DK1, 0 }, + { XML_LT1, 1 }, + { XML_DK2, 2 }, + { XML_LT2, 3 }, + { XML_ACCENT1, 4 }, + { XML_ACCENT2, 5 }, + { XML_ACCENT3, 6 }, + { XML_ACCENT4, 7 }, + { XML_ACCENT5, 8 }, + { XML_ACCENT6, 9 }, + { XML_HLINK, 10 }, + { XML_FOLHLINK, 11 }, + { XML_TOKEN_INVALID, 0 } +}; + namespace { class XMLDropCapPropHdl_Impl : public XMLPropertyHandler @@ -1412,6 +1429,9 @@ static const XMLPropertyHandler *GetPropertyHandler case XML_TYPE_GRAPHIC: pHdl = new XMLGraphicPropertyHandler; break; + case XML_TYPE_THEME_COLOR: + pHdl = new XMLConstantsPropertyHandler(pXML_ThemeColor_Enum, XML_TOKEN_INVALID); + break; default: { OSL_ENSURE(false, "XMLPropertyHandler missing (!)"); diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx index 2e8297d7947e..f51db1aa2ab6 100644 --- a/xmloff/source/text/txtprmap.cxx +++ b/xmloff/source/text/txtprmap.cxx @@ -138,6 +138,7 @@ XMLPropertyMapEntry const aXMLParaPropMap[] = MT_ED( "CharColor", STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ), MAP_EXT_I("CharTransparence", XML_NAMESPACE_DRAW, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), MAP_EXT("CharTransparence", XML_NAMESPACE_LO_EXT, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), + MAP_EXT("CharColorTheme", XML_NAMESPACE_LO_EXT, XML_THEME_COLOR, XML_TYPE_THEME_COLOR, 0), // RES_CHRATR_CONTOUR MT_E( "CharContoured", STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ), // RES_CHRATR_CROSSEDOUT @@ -481,6 +482,7 @@ XMLPropertyMapEntry const aXMLTextPropMap[] = MT_ED( "CharColor", STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ), MAP_EXT_I("CharTransparence", XML_NAMESPACE_DRAW, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), MAP_EXT("CharTransparence", XML_NAMESPACE_LO_EXT, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0), + MAP_EXT("CharColorTheme", XML_NAMESPACE_LO_EXT, XML_THEME_COLOR, XML_TYPE_THEME_COLOR | XML_TYPE_PROP_TEXT, 0), // RES_CHRATR_CONTOUR MT_E( "CharContoured", STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ), // RES_CHRATR_CROSSEDOUT diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 3af58c6aac26..2ef220bda33c 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3215,6 +3215,19 @@ rtl symmetric linked-style-name theme +theme-color +dk1 +lt1 +dk2 +lt2 +accent1 +accent2 +accent3 +accent4 +accent5 +accent6 +hlink +folHlink content-control showing-place-holder checked-state |