summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorLuke Deller <luke@deller.id.au>2018-03-08 01:11:40 +1100
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-03-13 14:06:13 +0100
commitfe6da2feb57c3d5e355a36f6b8ac09b48412ff39 (patch)
treee8ed7fa33846280e54667d6e8a5435111391ff0b /writerfilter
parentfc6a8994055db18b9ba2dce1e26d2b1ea9ea41f3 (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 Change-Id: I6000070341931147ff9341ad6281cd3b53c02b46 Reviewed-on: https://gerrit.libreoffice.org/50995 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/BorderHandler.cxx2
-rw-r--r--writerfilter/source/dmapper/CellColorHandler.cxx10
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx2
-rw-r--r--writerfilter/source/dmapper/TDefTableHandler.cxx2
-rw-r--r--writerfilter/source/ooxml/OOXMLFactory.cxx9
-rw-r--r--writerfilter/source/ooxml/OOXMLFactory.hxx1
-rw-r--r--writerfilter/source/ooxml/OOXMLPropertySet.cxx16
-rw-r--r--writerfilter/source/ooxml/OOXMLPropertySet.hxx8
-rw-r--r--writerfilter/source/ooxml/factoryimpl.py5
-rw-r--r--writerfilter/source/ooxml/model.xml2
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx6
11 files changed, 51 insertions, 12 deletions
diff --git a/writerfilter/source/dmapper/BorderHandler.cxx b/writerfilter/source/dmapper/BorderHandler.cxx
index e2528c28d50e..0a07c9753393 100644
--- a/writerfilter/source/dmapper/BorderHandler.cxx
+++ b/writerfilter/source/dmapper/BorderHandler.cxx
@@ -67,7 +67,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 cb8fccac1f71..968c1b1f553f 100644
--- a/writerfilter/source/dmapper/CellColorHandler.cxx
+++ b/writerfilter/source/dmapper/CellColorHandler.cxx
@@ -109,8 +109,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;
@@ -118,8 +118,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;
@@ -283,7 +283,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 60f65a481084..310bf761f3b7 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -304,7 +304,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 bd594fc510cb..b86f37ed8bf3 100644
--- a/writerfilter/source/dmapper/TDefTableHandler.cxx
+++ b/writerfilter/source/dmapper/TDefTableHandler.cxx
@@ -287,7 +287,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 c164ff949757..91eb7b0e4c96 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -96,6 +96,15 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
pFactory->attributeAction(pHandler, nToken, xValue);
}
break;
+ case ResourceType::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 ResourceType::TwipsMeasure:
{
const char *pValue = "";
diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx
index dce03696185c..fcf89155ae7c 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.hxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.hxx
@@ -40,6 +40,7 @@ enum class ResourceType {
Integer,
Properties,
Hex,
+ HexColor,
String,
Shape,
Boolean,
diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.cxx b/writerfilter/source/ooxml/OOXMLPropertySet.cxx
index 195d75b83185..13c5cf0493b7 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
@@ -577,6 +578,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 fbedaeda6498..d8c38d87d904 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySet.hxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySet.hxx
@@ -211,7 +211,9 @@ public:
class OOXMLHexValue : public OOXMLValue
{
+protected:
sal_uInt32 mnValue;
+ OOXMLHexValue() {}
public:
explicit OOXMLHexValue(sal_uInt32 nValue);
explicit OOXMLHexValue(const char * pValue);
@@ -224,6 +226,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 3605892fe71f..acbaf4234261 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", "MeasurementOrPercent"]
+ resources = [
+ "List", "Integer", "Hex", "HexColor", "String", "TwipsMeasure",
+ "HpsMeasure", "Boolean", "MeasurementOrPercent",
+ ]
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 a9ffbdfa6c65..25f8a267bb8a 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -16710,7 +16710,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 b5d839f85027..4d5cf17c0b6e 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -86,8 +86,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);