diff options
author | Luke Deller <luke@deller.id.au> | 2018-03-08 01:11:40 +1100 |
---|---|---|
committer | Aron Budea <aron.budea@collabora.com> | 2018-04-02 15:47:14 +0200 |
commit | ccef956c4f11ac6c0612a0d22845d02743c91039 (patch) | |
tree | 06a01e3e1c7f85e45121143598fffe49402e4226 /writerfilter | |
parent | c1f393d899360e11e25d562d90285895f1e751e9 (diff) |
tdf#116179 Support reading "auto" colour from docx
In docx a colour value is represented as a 6-digit hex RGB value, or
alternatively the word "auto" to represent automatic colour.
- Add support for reading the value "auto" as COL_AUTO. Previously
this would be read as if it were a hex value, stopping at the
letter 'u' which is not a valid hex digit, resulting in the colour
0x00000A - a very dark blue, which looks close enough to black that
it went unnoticed for a long time :-)
- Remove code which tried to handle this wrong 0x00000A value,
including the constant OOXML_COLOR_AUTO, as it is no longer needed
and will cause surprises for anyone who really wanted this exact
shade of dark blue
- Fix unit tests that were checking for 0x00000A
Reviewed-on: https://gerrit.libreoffice.org/50995
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Reviewed-on: https://gerrit.libreoffice.org/51461
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 3967aebca94be9ceea3e36b43f7f53589473ad4e)
Change-Id: I6000070341931147ff9341ad6281cd3b53c02b46
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/BorderHandler.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/CellColorHandler.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TDefTableHandler.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFactory.cxx | 9 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFactory.hxx | 1 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLPropertySet.cxx | 16 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLPropertySet.hxx | 7 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factoryimpl.py | 5 | ||||
-rw-r--r-- | writerfilter/source/ooxml/model.xml | 2 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 6 |
11 files changed, 50 insertions, 12 deletions
diff --git a/writerfilter/source/dmapper/BorderHandler.cxx b/writerfilter/source/dmapper/BorderHandler.cxx index 80cc8386d2fb..63f2083817bc 100644 --- a/writerfilter/source/dmapper/BorderHandler.cxx +++ b/writerfilter/source/dmapper/BorderHandler.cxx @@ -66,7 +66,7 @@ void BorderHandler::lcl_attribute(Id rName, Value & rVal) break; case NS_ooxml::LN_CT_Border_color: m_nLineColor = nIntValue; - appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true))); + appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue))); break; case NS_ooxml::LN_CT_Border_space: // border distance in points m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 ); diff --git a/writerfilter/source/dmapper/CellColorHandler.cxx b/writerfilter/source/dmapper/CellColorHandler.cxx index 6b276188c0af..40a6993bd630 100644 --- a/writerfilter/source/dmapper/CellColorHandler.cxx +++ b/writerfilter/source/dmapper/CellColorHandler.cxx @@ -108,8 +108,8 @@ void CellColorHandler::lcl_attribute(Id rName, Value & rVal) } break; case NS_ooxml::LN_CT_Shd_fill: - createGrabBag("fill", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true)))); - if( nIntValue == OOXML_COLOR_AUTO ) + createGrabBag("fill", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue)))); + if( nIntValue == sal_Int32(COL_AUTO) ) nIntValue = 0xffffff; //fill color auto means white else m_bAutoFillColor = false; @@ -117,8 +117,8 @@ void CellColorHandler::lcl_attribute(Id rName, Value & rVal) m_nFillColor = nIntValue; break; case NS_ooxml::LN_CT_Shd_color: - createGrabBag("color", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true)))); - if( nIntValue == OOXML_COLOR_AUTO ) + createGrabBag("color", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue)))); + if( nIntValue == sal_Int32(COL_AUTO) ) nIntValue = 0; //shading color auto means black //color of the shading m_nColor = nIntValue; @@ -285,7 +285,7 @@ TablePropertyMapPtr CellColorHandler::getProperties() pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR : PROP_CHAR_BACK_COLOR, uno::makeAny( nApplyColor )); - createGrabBag("originalColor", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nApplyColor, true)))); + createGrabBag("originalColor", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nApplyColor)))); return pPropertyMap; } diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 55f6a5f4e7a5..82d8e0057d97 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -301,7 +301,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) case NS_ooxml::LN_CT_Color_val: if (m_pImpl->GetTopContext()) m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR, uno::makeAny( nIntValue ) ); - m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "val", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true))); + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "val", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue))); break; case NS_ooxml::LN_CT_Underline_color: if (m_pImpl->GetTopContext()) diff --git a/writerfilter/source/dmapper/TDefTableHandler.cxx b/writerfilter/source/dmapper/TDefTableHandler.cxx index fa756e44ed6c..7e7282e95330 100644 --- a/writerfilter/source/dmapper/TDefTableHandler.cxx +++ b/writerfilter/source/dmapper/TDefTableHandler.cxx @@ -289,7 +289,7 @@ void TDefTableHandler::lcl_attribute(Id rName, Value & rVal) appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue)); break; case NS_ooxml::LN_CT_Border_color: - appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true))); + appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue))); m_nLineColor = nIntValue; break; case NS_ooxml::LN_CT_Border_space: diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx index b30b8adf3dba..4be37d89f356 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.cxx +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -98,6 +98,15 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, pFactory->attributeAction(pHandler, nToken, xValue); } break; + case RT_HexColor: + { + const char *pValue = ""; + pAttribs->getAsChar(nToken, pValue); + OOXMLValue::Pointer_t xValue(new OOXMLHexColorValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; case RT_TwipsMeasure: { const char *pValue = ""; diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx index 1527be15c0d6..d1b4f22dcf09 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.hxx +++ b/writerfilter/source/ooxml/OOXMLFactory.hxx @@ -41,6 +41,7 @@ enum ResourceType_t { RT_Integer, RT_Properties, RT_Hex, + RT_HexColor, RT_String, RT_Shape, RT_Boolean, diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.cxx b/writerfilter/source/ooxml/OOXMLPropertySet.cxx index 0b353dfb8039..f2fc19f5fa87 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySet.cxx +++ b/writerfilter/source/ooxml/OOXMLPropertySet.cxx @@ -23,6 +23,7 @@ #include <ooxml/QNameToString.hxx> #include <com/sun/star/drawing/XShape.hpp> #include <oox/token/tokens.hxx> +#include <tools/color.hxx> namespace writerfilter { namespace ooxml @@ -588,6 +589,21 @@ string OOXMLHexValue::toString() const } #endif +/* + class OOXMLHexColorValue +*/ +OOXMLHexColorValue::OOXMLHexColorValue(const char * pValue) +{ + if (!strcmp(pValue, "auto")) + { + mnValue = sal_uInt32(COL_AUTO); + } + else + { + mnValue = rtl_str_toUInt32(pValue, 16); + } +} + // OOXMLUniversalMeasureValue // ECMA-376 5th ed. Part 1 , 22.9.2.15 OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const char * pValue, sal_uInt32 npPt) diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.hxx b/writerfilter/source/ooxml/OOXMLPropertySet.hxx index 45aba15e2ccc..45c7a91404b5 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySet.hxx +++ b/writerfilter/source/ooxml/OOXMLPropertySet.hxx @@ -217,6 +217,7 @@ class OOXMLHexValue : public OOXMLValue { protected: sal_uInt32 mnValue; + OOXMLHexValue() {} public: explicit OOXMLHexValue(sal_uInt32 nValue); explicit OOXMLHexValue(const char * pValue); @@ -229,6 +230,12 @@ public: virtual OOXMLValue * clone() const override; }; +class OOXMLHexColorValue : public OOXMLHexValue +{ +public: + explicit OOXMLHexColorValue(const char * pValue); +}; + class OOXMLUniversalMeasureValue : public OOXMLValue { private: diff --git a/writerfilter/source/ooxml/factoryimpl.py b/writerfilter/source/ooxml/factoryimpl.py index 92fe4ddddeee..df5a237d181f 100644 --- a/writerfilter/source/ooxml/factoryimpl.py +++ b/writerfilter/source/ooxml/factoryimpl.py @@ -37,7 +37,10 @@ def createFastChildContextFromFactory(model): switch (nResource) {""") - resources = ["List", "Integer", "Hex", "String", "TwipsMeasure", "HpsMeasure", "Boolean"] + resources = [ + "List", "Integer", "Hex", "HexColor", "String", "TwipsMeasure", + "HpsMeasure", "Boolean", + ] for resource in [r.getAttribute("resource") for r in model.getElementsByTagName("resource")]: if resource not in resources: resources.append(resource) diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 453f15570451..76d718450e50 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -16708,7 +16708,7 @@ <value tokenid="ooxml:Value_ST_HexColorAuto_auto">auto</value> </resource> <resource name="ST_HexColorRGB" resource="Hex"/> - <resource name="ST_HexColor" resource="Hex"/> + <resource name="ST_HexColor" resource="HexColor"/> <resource name="CT_Color" resource="Properties"> <attribute name="val" tokenid="ooxml:CT_Color_val"/> <attribute name="themeColor" tokenid="ooxml:CT_Color_themeColor"/> diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index e1932c050847..713cd3874d15 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -75,8 +75,10 @@ void putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Po if (nParent == NS_ooxml::LN_CT_TcPrBase_shd) { // RTF default is 'auto', see writerfilter::dmapper::CellColorHandler - aAttributes.set(NS_ooxml::LN_CT_Shd_color, std::make_shared<RTFValue>(0x0a)); - aAttributes.set(NS_ooxml::LN_CT_Shd_fill, std::make_shared<RTFValue>(0x0a)); + aAttributes.set(NS_ooxml::LN_CT_Shd_color, + std::make_shared<RTFValue>(sal_uInt32(COL_AUTO))); + aAttributes.set(NS_ooxml::LN_CT_Shd_fill, + std::make_shared<RTFValue>(sal_uInt32(COL_AUTO))); } auto pParentValue = std::make_shared<RTFValue>(aAttributes); rSprms.set(nParent, pParentValue, eOverwrite); |