diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2013-10-30 15:19:18 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2013-10-30 17:50:36 +0100 |
commit | 9ab844c7fa907e2d1119a316c695198ef888a059 (patch) | |
tree | eb4674977538f7d8c11e41c8a07413aec33ecc93 | |
parent | e0f1ddca3f26df3e84d6fbf1cc373ec287396397 (diff) |
DOCX filter: roundtrip more table style properties
Handle wordWrap, beforeLines, afterLines, beforeAutospacing,
afterAutospacing, asciiTheme, hAnsiTheme, b, i, color, sz and vAlign.
With this, the export filter is now in sync with the import one again.
Change-Id: I7184447baf872374eaa69afdfcb149a7e6e45faa
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxtablestyleexport.cxx | 69 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 8 |
3 files changed, 81 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index ffe9c62b438b..502873316e50 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -1470,6 +1470,12 @@ void Test::testCalendar1() // Table style lost its paragraph / run properties. assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Calendar1']/w:pPr/w:spacing", "lineRule", "auto"); assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Calendar1']/w:rPr/w:lang", "eastAsia", "ja-JP"); + + // Table style lost its conditional table formatting properties. + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Calendar1']/w:tblStylePr[@w:type='firstRow']/w:pPr/w:wordWrap", 1); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Calendar1']/w:tblStylePr[@w:type='firstRow']/w:rPr/w:rFonts", "hAnsiTheme", "minorHAnsi"); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Calendar1']/w:tblStylePr[@w:type='firstRow']/w:tblPr", 1); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Calendar1']/w:tblStylePr[@w:type='firstRow']/w:tcPr/w:vAlign", "val", "bottom"); } void Test::testSmartart() diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx index db0608d15e51..634368a2edb1 100644 --- a/sw/source/filter/ww8/docxtablestyleexport.cxx +++ b/sw/source/filter/ww8/docxtablestyleexport.cxx @@ -111,6 +111,22 @@ void lcl_TableStyleShd(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be pSerializer->singleElementNS(XML_w, XML_shd, xAttributeList); } +/// Export of w:color in a table style. +void lcl_TableStyleRColor(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rColor) +{ + if (!rColor.hasElements()) + return; + + sax_fastparser::FastAttributeList* pAttributeList = pSerializer->createAttrList(); + for (sal_Int32 i = 0; i < rColor.getLength(); ++i) + { + if (rColor[i].Name == "val") + pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + } + sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); + pSerializer->singleElementNS(XML_w, XML_color, xAttributeList); +} + /// Export of w:lang in a table style. void lcl_TableStyleRLang(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rLang) { @@ -138,6 +154,10 @@ void lcl_TableStyleRRFonts(sax_fastparser::FSHelperPtr pSerializer, uno::Sequenc { if (rRFonts[i].Name == "eastAsiaTheme") pAttributeList->add(FSNS(XML_w, XML_eastAsiaTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + else if (rRFonts[i].Name == "asciiTheme") + pAttributeList->add(FSNS(XML_w, XML_asciiTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + else if (rRFonts[i].Name == "hAnsiTheme") + pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); pSerializer->singleElementNS(XML_w, XML_rFonts, xAttributeList); @@ -158,6 +178,14 @@ void lcl_TableStylePSpacing(sax_fastparser::FSHelperPtr pSerializer, uno::Sequen pAttributeList->add(FSNS(XML_w, XML_line), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); else if (rSpacing[i].Name == "lineRule") pAttributeList->add(FSNS(XML_w, XML_lineRule), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + else if (rSpacing[i].Name == "beforeLines") + pAttributeList->add(FSNS(XML_w, XML_beforeLines), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + else if (rSpacing[i].Name == "beforeAutospacing") + pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + else if (rSpacing[i].Name == "afterLines") + pAttributeList->add(FSNS(XML_w, XML_afterLines), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + else if (rSpacing[i].Name == "afterAutospacing") + pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); pSerializer->singleElementNS(XML_w, XML_spacing, xAttributeList); @@ -181,6 +209,17 @@ void lcl_TableStyleTblInd(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence pSerializer->singleElementNS(XML_w, XML_tblInd, xAttributeList); } +void lcl_handleBoolean(OUString aValue, sal_Int32 nToken, sax_fastparser::FSHelperPtr pSerializer) +{ + if (aValue.isEmpty()) + return; + sax_fastparser::FastAttributeList* pAttributeList = pSerializer->createAttrList(); + if (aValue != "1") + pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(aValue, RTL_TEXTENCODING_UTF8).getStr()); + sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); + pSerializer->singleElementNS(XML_w, nToken, xAttributeList); +} + /// Export of w:rPr in a table style. void lcl_TableStyleRPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rRPr) { @@ -189,16 +228,32 @@ void lcl_TableStyleRPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be pSerializer->startElementNS(XML_w, XML_rPr, FSEND); - uno::Sequence<beans::PropertyValue> aRFonts, aLang; + uno::Sequence<beans::PropertyValue> aRFonts, aLang, aColor; + OUString aB, aI, aSz; for (sal_Int32 i = 0; i < rRPr.getLength(); ++i) { if (rRPr[i].Name == "rFonts") aRFonts = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); else if (rRPr[i].Name == "lang") aLang = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); + else if (rRPr[i].Name == "b") + aB = rRPr[i].Value.get<OUString>(); + else if (rRPr[i].Name == "i") + aI = rRPr[i].Value.get<OUString>(); + else if (rRPr[i].Name == "color") + aColor = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); + else if (rRPr[i].Name == "sz") + aSz = rRPr[i].Value.get<OUString>(); } lcl_TableStyleRRFonts(pSerializer, aRFonts); lcl_TableStyleRLang(pSerializer, aLang); + lcl_handleBoolean(aB, XML_b, pSerializer); + lcl_handleBoolean(aI, XML_i, pSerializer); + lcl_TableStyleRColor(pSerializer, aColor); + if (!aSz.isEmpty()) + pSerializer->singleElementNS(XML_w, XML_sz, + FSNS(XML_w, XML_val), OUStringToOString(aSz, RTL_TEXTENCODING_UTF8).getStr(), + FSEND); pSerializer->endElementNS(XML_w, XML_rPr); } @@ -212,11 +267,16 @@ void lcl_TableStylePPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be pSerializer->startElementNS(XML_w, XML_pPr, FSEND); uno::Sequence<beans::PropertyValue> aSpacing; + bool bWordWrap = false; for (sal_Int32 i = 0; i < rPPr.getLength(); ++i) { if (rPPr[i].Name == "spacing") aSpacing = rPPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); + if (rPPr[i].Name == "wordWrap") + bWordWrap = true; } + if (bWordWrap) + pSerializer->singleElementNS(XML_w, XML_wordWrap, FSEND); lcl_TableStylePSpacing(pSerializer, aSpacing); pSerializer->endElementNS(XML_w, XML_pPr); @@ -266,12 +326,19 @@ void lcl_TableStyleTcPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<b pSerializer->startElementNS(XML_w, XML_tcPr, FSEND); uno::Sequence<beans::PropertyValue> aShd; + OUString aVAlign; for (sal_Int32 i = 0; i < rTcPr.getLength(); ++i) { if (rTcPr[i].Name == "shd") aShd = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); + else if (rTcPr[i].Name == "vAlign") + aVAlign = rTcPr[i].Value.get<OUString>(); } lcl_TableStyleShd(pSerializer, aShd); + if (!aVAlign.isEmpty()) + pSerializer->singleElementNS(XML_w, XML_vAlign, + FSNS(XML_w, XML_val), OUStringToOString(aVAlign, RTL_TEXTENCODING_UTF8).getStr(), + FSEND); pSerializer->endElementNS(XML_w, XML_tcPr); } diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 1139671f48de..a0c4bef1d261 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -948,13 +948,15 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sStringValue )); break; case NS_ooxml::LN_CT_Fonts_asciiTheme: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "asciiTheme", ThemeTable::getStringForTheme(nIntValue)); if (m_pImpl->GetTopContext()) m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( m_pImpl->GetThemeTable()->getFontNameForTheme(nIntValue) )); break; case NS_ooxml::LN_CT_Fonts_hAnsi: break;//unsupported case NS_ooxml::LN_CT_Fonts_hAnsiTheme: - break; //unsupported + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "hAnsiTheme", ThemeTable::getStringForTheme(nIntValue)); + break; case NS_ooxml::LN_CT_Fonts_eastAsia: if (m_pImpl->GetTopContext()) m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( sStringValue )); @@ -978,6 +980,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) m_pImpl->GetTopContext()->Insert(PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100( nIntValue ) ), false); break; case NS_ooxml::LN_CT_Spacing_beforeLines: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "beforeLines", OUString::number(nIntValue)); break; case NS_ooxml::LN_CT_Spacing_after: m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "after", OUString::number(nIntValue)); @@ -986,6 +989,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) m_pImpl->GetTopContext()->Insert(PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100( nIntValue ) ), false); break; case NS_ooxml::LN_CT_Spacing_afterLines: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "afterLines", OUString::number(nIntValue)); break; case NS_ooxml::LN_CT_Spacing_line: //91434 case NS_ooxml::LN_CT_Spacing_lineRule: //91435 @@ -1173,12 +1177,14 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) break; // See SwWW8ImplReader::GetParagraphAutoSpace() on why these are 100 and 280 case NS_ooxml::LN_CT_Spacing_beforeAutospacing: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "beforeAutospacing", OUString::number(nIntValue)); if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing()) m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) ); else m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(100) ) ); break; case NS_ooxml::LN_CT_Spacing_afterAutospacing: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "afterAutospacing", OUString::number(nIntValue)); if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing()) m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) ); else |