Kaydet (Commit) 9bb69561 authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez

ooxml: fix cell theme color and shade preservation

The cell property w:shd was not being properly preserved when the
shade value was different from "clear". The shading affects the cell
color and the exporter was not taking that into account when comparing
the cell color with the original color to know if the user had changed
it.

Besides, we were not preserving the attributes themeColor, themeTint
and themeShade.

I have modified the existing unit test testTableThemePreservation to
add a check for those new attributes.

Change-Id: I06d2e668486803cba039eacb717a69413bd5a1df
üst 2d8694c2
...@@ -1972,6 +1972,10 @@ DECLARE_OOXMLEXPORT_TEST(testTableThemePreservation, "table-theme-preservation.d ...@@ -1972,6 +1972,10 @@ DECLARE_OOXMLEXPORT_TEST(testTableThemePreservation, "table-theme-preservation.d
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFill", "accent6"); assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFill", "accent6");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFillShade", "80"); assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFillShade", "80");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFillTint", ""); assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFillTint", "");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "val", "horzStripe");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeColor", "accent3");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeTint", "33");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "color", "E7EEEE");
// check table style has been preserved // check table style has been preserved
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tblPr/w:tblStyle", "val", "Sombreadoclaro-nfasis1"); assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tblPr/w:tblStyle", "val", "Sombreadoclaro-nfasis1");
......
...@@ -2896,7 +2896,7 @@ void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_ ...@@ -2896,7 +2896,7 @@ void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_
sw::util::HasItem<SfxGrabBagItem>( pFmt->GetAttrSet(), RES_FRMATR_GRABBAG )->GetGrabBag(); sw::util::HasItem<SfxGrabBagItem>( pFmt->GetAttrSet(), RES_FRMATR_GRABBAG )->GetGrabBag();
OString sOriginalColor; OString sOriginalColor;
std::map<OUString, com::sun::star::uno::Any>::iterator aGrabBagElement = aGrabBag.find("fill"); std::map<OUString, com::sun::star::uno::Any>::iterator aGrabBagElement = aGrabBag.find("originalColor");
if( aGrabBagElement != aGrabBag.end() ) if( aGrabBagElement != aGrabBag.end() )
sOriginalColor = OUStringToOString( aGrabBagElement->second.get<OUString>(), RTL_TEXTENCODING_UTF8 ); sOriginalColor = OUStringToOString( aGrabBagElement->second.get<OUString>(), RTL_TEXTENCODING_UTF8 );
...@@ -2911,7 +2911,6 @@ void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_ ...@@ -2911,7 +2911,6 @@ void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_
else else
{ {
::sax_fastparser::FastAttributeList* aAttrList = NULL; ::sax_fastparser::FastAttributeList* aAttrList = NULL;
AddToAttrList( aAttrList, FSNS( XML_w, XML_fill ), sColor.getStr() );
for( aGrabBagElement = aGrabBag.begin(); aGrabBagElement != aGrabBag.end(); ++aGrabBagElement ) for( aGrabBagElement = aGrabBag.begin(); aGrabBagElement != aGrabBag.end(); ++aGrabBagElement )
{ {
...@@ -2922,6 +2921,14 @@ void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_ ...@@ -2922,6 +2921,14 @@ void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_
AddToAttrList( aAttrList, FSNS( XML_w, XML_themeFillTint ), sValue.getStr() ); AddToAttrList( aAttrList, FSNS( XML_w, XML_themeFillTint ), sValue.getStr() );
else if( aGrabBagElement->first == "themeFillShade") else if( aGrabBagElement->first == "themeFillShade")
AddToAttrList( aAttrList, FSNS( XML_w, XML_themeFillShade ), sValue.getStr() ); AddToAttrList( aAttrList, FSNS( XML_w, XML_themeFillShade ), sValue.getStr() );
else if( aGrabBagElement->first == "fill" )
AddToAttrList( aAttrList, FSNS( XML_w, XML_fill ), sValue.getStr() );
else if( aGrabBagElement->first == "themeColor")
AddToAttrList( aAttrList, FSNS( XML_w, XML_themeColor ), sValue.getStr() );
else if( aGrabBagElement->first == "themeTint")
AddToAttrList( aAttrList, FSNS( XML_w, XML_themeTint ), sValue.getStr() );
else if( aGrabBagElement->first == "themeShade")
AddToAttrList( aAttrList, FSNS( XML_w, XML_themeShade ), sValue.getStr() );
else if( aGrabBagElement->first == "color") else if( aGrabBagElement->first == "color")
AddToAttrList( aAttrList, FSNS( XML_w, XML_color ), sValue.getStr() ); AddToAttrList( aAttrList, FSNS( XML_w, XML_color ), sValue.getStr() );
else if( aGrabBagElement->first == "val") else if( aGrabBagElement->first == "val")
......
...@@ -131,6 +131,15 @@ void CellColorHandler::lcl_attribute(Id rName, Value & rVal) ...@@ -131,6 +131,15 @@ void CellColorHandler::lcl_attribute(Id rName, Value & rVal)
case NS_ooxml::LN_CT_Shd_themeFillTint: case NS_ooxml::LN_CT_Shd_themeFillTint:
createGrabBag("themeFillTint", uno::makeAny(OUString::number(nIntValue, 16))); createGrabBag("themeFillTint", uno::makeAny(OUString::number(nIntValue, 16)));
break; break;
case NS_ooxml::LN_CT_Shd_themeColor:
createGrabBag("themeColor", uno::makeAny(TDefTableHandler::getThemeColorTypeString(nIntValue)));
break;
case NS_ooxml::LN_CT_Shd_themeShade:
createGrabBag("themeShade", uno::makeAny(OUString::number(nIntValue, 16)));
break;
case NS_ooxml::LN_CT_Shd_themeTint:
createGrabBag("themeTint", uno::makeAny(OUString::number(nIntValue, 16)));
break;
default: default:
OSL_FAIL( "unknown attribute"); OSL_FAIL( "unknown attribute");
} }
...@@ -319,6 +328,10 @@ TablePropertyMapPtr CellColorHandler::getProperties() ...@@ -319,6 +328,10 @@ TablePropertyMapPtr CellColorHandler::getProperties()
pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR
: m_OutputFormat == Paragraph ? PROP_PARA_BACK_COLOR : m_OutputFormat == Paragraph ? PROP_PARA_BACK_COLOR
: PROP_CHAR_BACK_COLOR, uno::makeAny( nApplyColor )); : PROP_CHAR_BACK_COLOR, uno::makeAny( nApplyColor ));
createGrabBag("originalColor", uno::makeAny( OStringToOUString(
msfilter::util::ConvertColor( nApplyColor, true ), RTL_TEXTENCODING_UTF8 )));
return pPropertyMap; return pPropertyMap;
} }
......
...@@ -324,10 +324,10 @@ namespace dmapper { ...@@ -324,10 +324,10 @@ namespace dmapper {
CellColorHandlerPtr pCellColorHandler( new CellColorHandler ); CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
pCellColorHandler->enableInteropGrabBag("shd"); //enable to store shd unsupported props in grab bag pCellColorHandler->enableInteropGrabBag("shd"); //enable to store shd unsupported props in grab bag
pProperties->resolve( *pCellColorHandler ); pProperties->resolve( *pCellColorHandler );
TablePropertyMapPtr pPropertyMap = pCellColorHandler->getProperties();
beans::PropertyValue aGrabBag = pCellColorHandler->getInteropGrabBag(); beans::PropertyValue aGrabBag = pCellColorHandler->getInteropGrabBag();
if (m_pCurrentInteropGrabBag) if (m_pCurrentInteropGrabBag)
m_pCurrentInteropGrabBag->push_back(aGrabBag); m_pCurrentInteropGrabBag->push_back(aGrabBag);
TablePropertyMapPtr pPropertyMap = pCellColorHandler->getProperties();
pPropertyMap->Insert( PROP_CELL_INTEROP_GRAB_BAG, aGrabBag.Value ); pPropertyMap->Insert( PROP_CELL_INTEROP_GRAB_BAG, aGrabBag.Value );
cellProps( pPropertyMap ); cellProps( pPropertyMap );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment