summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8/docxattributeoutput.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-06-11 00:57:36 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-06-18 13:32:12 +0200
commit9e121f3a6b95dab7525aa1583f810b2b504ce1b3 (patch)
tree7b576ed8feb1d1b183d01ad72f80c99ed03a38ef /sw/source/filter/ww8/docxattributeoutput.cxx
parentcd9afc213d768b9870c81c580fbb00282c0cf1c4 (diff)
ooxml: import and export background and fill theme colors props.
This adds support to import and export background and fill theme color properties. Change-Id: I0f40615fe2d06cdcb4f2f9752602fe2ec699c7b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152835 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/source/filter/ww8/docxattributeoutput.cxx')
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx28
1 files changed, 21 insertions, 7 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index ba5d14bd8c90..3b095a96aea6 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -290,7 +290,9 @@ auto detachFrom(rtl::Reference<sax_fastparser::FastAttributeList>& src)
return rtl::Reference(std::move(src));
}
-void lclAddThemeColorAttributes(rtl::Reference<sax_fastparser::FastAttributeList>& pAttrList, model::ComplexColor const& rComplexColor)
+void lclAddThemeValuesToCustomAttributes(
+ rtl::Reference<sax_fastparser::FastAttributeList>& pAttrList, model::ComplexColor const& rComplexColor,
+ sal_Int32 nThemeAttrId, sal_Int32 nThemeTintAttrId, sal_Int32 nThemeShadeAttrId)
{
static std::unordered_map<model::ThemeColorType, const char*> constThemeColorTypeTokenMap = {
{ model::ThemeColorType::Dark1, "dark1" },
@@ -326,7 +328,7 @@ void lclAddThemeColorAttributes(rtl::Reference<sax_fastparser::FastAttributeList
sSchemeType = "background2";
}
- DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, XML_themeColor), sSchemeType);
+ DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, nThemeAttrId), sSchemeType);
sal_Int16 nLumMod = 10'000;
sal_Int16 nLumOff = 0;
@@ -350,13 +352,13 @@ void lclAddThemeColorAttributes(rtl::Reference<sax_fastparser::FastAttributeList
{
// Convert from 0-100 into 0-255
sal_Int16 nTint255 = std::round(255.0 - (double(nTint) / 10000.0) * 255.0);
- DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, XML_themeTint), OString::number(nTint255, 16));
+ DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, nThemeTintAttrId), OString::number(nTint255, 16));
}
else if (nShade != 0)
{
// Convert from 0-100 into 0-255
sal_Int16 nShade255 = std::round(255.0 - (double(nShade) / 10000.0) * 255.0);
- DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, XML_themeShade), OString::number(nShade255, 16));
+ DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, nThemeShadeAttrId), OString::number(nShade255, 16));
}
}
else
@@ -372,13 +374,23 @@ void lclAddThemeColorAttributes(rtl::Reference<sax_fastparser::FastAttributeList
sal_Int16 nTintShade255 = std::round(255.0 - (std::abs(nPercentage) / 100.0) * 255.0);
if (nPercentage > 0)
- DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, XML_themeTint), OString::number(nTintShade255, 16));
+ DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, nThemeTintAttrId), OString::number(nTintShade255, 16));
else if (nPercentage < 0)
- DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, XML_themeShade), OString::number(nTintShade255, 16));
+ DocxAttributeOutput::AddToAttrList(pAttrList, FSNS(XML_w, nThemeShadeAttrId), OString::number(nTintShade255, 16));
}
}
}
+void lclAddThemeFillColorAttributes(rtl::Reference<sax_fastparser::FastAttributeList>& pAttrList, model::ComplexColor const& rComplexColor)
+{
+ lclAddThemeValuesToCustomAttributes(pAttrList, rComplexColor, XML_themeFill, XML_themeFillTint, XML_themeFillShade);
+}
+
+void lclAddThemeColorAttributes(rtl::Reference<sax_fastparser::FastAttributeList>& pAttrList, model::ComplexColor const& rComplexColor)
+{
+ lclAddThemeValuesToCustomAttributes(pAttrList, rComplexColor, XML_themeColor, XML_themeTint, XML_themeShade);
+}
+
} // end anonymous namespace
void DocxAttributeOutput::RTLAndCJKState( bool bIsRTL, sal_uInt16 /*nScript*/ )
@@ -9476,6 +9488,7 @@ static std::optional<sal_Int32> lcl_getDmlAlpha(const SvxBrushItem& rBrush)
void DocxAttributeOutput::FormatBackground( const SvxBrushItem& rBrush )
{
const Color aColor = rBrush.GetColor();
+ model::ComplexColor const& rComplexColor = rBrush.getComplexColor();
OString sColor = msfilter::util::ConvertColor( aColor.GetRGBColor() );
std::optional<sal_Int32> oAlpha = lcl_getDmlAlpha(rBrush);
if (m_rExport.SdrExporter().getTextFrameSyntax())
@@ -9490,7 +9503,8 @@ void DocxAttributeOutput::FormatBackground( const SvxBrushItem& rBrush )
AddToAttrList( m_rExport.SdrExporter().getFlyFillAttrList(), XML_opacity, OString::number(fOpacity) + "f" );
}
- AddToAttrList( m_rExport.SdrExporter().getFlyAttrList(), XML_fillcolor, "#" + sColor );
+ AddToAttrList(m_rExport.SdrExporter().getFlyAttrList(), XML_fillcolor, "#" + sColor );
+ lclAddThemeFillColorAttributes(m_rExport.SdrExporter().getFlyAttrList(), rComplexColor);
}
else if (m_rExport.SdrExporter().getDMLTextFrameSyntax())
{