Kaydet (Commit) 9ab844c7 authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst e0f1ddca
...@@ -1470,6 +1470,12 @@ void Test::testCalendar1() ...@@ -1470,6 +1470,12 @@ void Test::testCalendar1()
// Table style lost its paragraph / run properties. // 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:pPr/w:spacing", "lineRule", "auto");
assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Calendar1']/w:rPr/w:lang", "eastAsia", "ja-JP"); 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() void Test::testSmartart()
......
...@@ -111,6 +111,22 @@ void lcl_TableStyleShd(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be ...@@ -111,6 +111,22 @@ void lcl_TableStyleShd(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be
pSerializer->singleElementNS(XML_w, XML_shd, xAttributeList); 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. /// Export of w:lang in a table style.
void lcl_TableStyleRLang(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rLang) 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 ...@@ -138,6 +154,10 @@ void lcl_TableStyleRRFonts(sax_fastparser::FSHelperPtr pSerializer, uno::Sequenc
{ {
if (rRFonts[i].Name == "eastAsiaTheme") if (rRFonts[i].Name == "eastAsiaTheme")
pAttributeList->add(FSNS(XML_w, XML_eastAsiaTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); 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); sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
pSerializer->singleElementNS(XML_w, XML_rFonts, xAttributeList); pSerializer->singleElementNS(XML_w, XML_rFonts, xAttributeList);
...@@ -158,6 +178,14 @@ void lcl_TableStylePSpacing(sax_fastparser::FSHelperPtr pSerializer, uno::Sequen ...@@ -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()); pAttributeList->add(FSNS(XML_w, XML_line), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
else if (rSpacing[i].Name == "lineRule") else if (rSpacing[i].Name == "lineRule")
pAttributeList->add(FSNS(XML_w, XML_lineRule), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); 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); sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
pSerializer->singleElementNS(XML_w, XML_spacing, xAttributeList); pSerializer->singleElementNS(XML_w, XML_spacing, xAttributeList);
...@@ -181,6 +209,17 @@ void lcl_TableStyleTblInd(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence ...@@ -181,6 +209,17 @@ void lcl_TableStyleTblInd(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence
pSerializer->singleElementNS(XML_w, XML_tblInd, xAttributeList); 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. /// Export of w:rPr in a table style.
void lcl_TableStyleRPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rRPr) 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 ...@@ -189,16 +228,32 @@ void lcl_TableStyleRPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be
pSerializer->startElementNS(XML_w, XML_rPr, FSEND); 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) for (sal_Int32 i = 0; i < rRPr.getLength(); ++i)
{ {
if (rRPr[i].Name == "rFonts") if (rRPr[i].Name == "rFonts")
aRFonts = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); aRFonts = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
else if (rRPr[i].Name == "lang") else if (rRPr[i].Name == "lang")
aLang = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); 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_TableStyleRRFonts(pSerializer, aRFonts);
lcl_TableStyleRLang(pSerializer, aLang); 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); pSerializer->endElementNS(XML_w, XML_rPr);
} }
...@@ -212,11 +267,16 @@ void lcl_TableStylePPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be ...@@ -212,11 +267,16 @@ void lcl_TableStylePPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<be
pSerializer->startElementNS(XML_w, XML_pPr, FSEND); pSerializer->startElementNS(XML_w, XML_pPr, FSEND);
uno::Sequence<beans::PropertyValue> aSpacing; uno::Sequence<beans::PropertyValue> aSpacing;
bool bWordWrap = false;
for (sal_Int32 i = 0; i < rPPr.getLength(); ++i) for (sal_Int32 i = 0; i < rPPr.getLength(); ++i)
{ {
if (rPPr[i].Name == "spacing") if (rPPr[i].Name == "spacing")
aSpacing = rPPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); 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); lcl_TableStylePSpacing(pSerializer, aSpacing);
pSerializer->endElementNS(XML_w, XML_pPr); pSerializer->endElementNS(XML_w, XML_pPr);
...@@ -266,12 +326,19 @@ void lcl_TableStyleTcPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<b ...@@ -266,12 +326,19 @@ void lcl_TableStyleTcPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<b
pSerializer->startElementNS(XML_w, XML_tcPr, FSEND); pSerializer->startElementNS(XML_w, XML_tcPr, FSEND);
uno::Sequence<beans::PropertyValue> aShd; uno::Sequence<beans::PropertyValue> aShd;
OUString aVAlign;
for (sal_Int32 i = 0; i < rTcPr.getLength(); ++i) for (sal_Int32 i = 0; i < rTcPr.getLength(); ++i)
{ {
if (rTcPr[i].Name == "shd") if (rTcPr[i].Name == "shd")
aShd = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); 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); 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); pSerializer->endElementNS(XML_w, XML_tcPr);
} }
......
...@@ -948,13 +948,15 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) ...@@ -948,13 +948,15 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sStringValue )); m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sStringValue ));
break; break;
case NS_ooxml::LN_CT_Fonts_asciiTheme: case NS_ooxml::LN_CT_Fonts_asciiTheme:
m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "asciiTheme", ThemeTable::getStringForTheme(nIntValue));
if (m_pImpl->GetTopContext()) if (m_pImpl->GetTopContext())
m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( m_pImpl->GetThemeTable()->getFontNameForTheme(nIntValue) )); m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( m_pImpl->GetThemeTable()->getFontNameForTheme(nIntValue) ));
break; break;
case NS_ooxml::LN_CT_Fonts_hAnsi: case NS_ooxml::LN_CT_Fonts_hAnsi:
break;//unsupported break;//unsupported
case NS_ooxml::LN_CT_Fonts_hAnsiTheme: 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: case NS_ooxml::LN_CT_Fonts_eastAsia:
if (m_pImpl->GetTopContext()) if (m_pImpl->GetTopContext())
m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( sStringValue )); m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( sStringValue ));
...@@ -978,6 +980,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) ...@@ -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); m_pImpl->GetTopContext()->Insert(PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100( nIntValue ) ), false);
break; break;
case NS_ooxml::LN_CT_Spacing_beforeLines: case NS_ooxml::LN_CT_Spacing_beforeLines:
m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "beforeLines", OUString::number(nIntValue));
break; break;
case NS_ooxml::LN_CT_Spacing_after: case NS_ooxml::LN_CT_Spacing_after:
m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "after", OUString::number(nIntValue)); m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "after", OUString::number(nIntValue));
...@@ -986,6 +989,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) ...@@ -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); m_pImpl->GetTopContext()->Insert(PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100( nIntValue ) ), false);
break; break;
case NS_ooxml::LN_CT_Spacing_afterLines: case NS_ooxml::LN_CT_Spacing_afterLines:
m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "afterLines", OUString::number(nIntValue));
break; break;
case NS_ooxml::LN_CT_Spacing_line: //91434 case NS_ooxml::LN_CT_Spacing_line: //91434
case NS_ooxml::LN_CT_Spacing_lineRule: //91435 case NS_ooxml::LN_CT_Spacing_lineRule: //91435
...@@ -1173,12 +1177,14 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) ...@@ -1173,12 +1177,14 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
break; break;
// See SwWW8ImplReader::GetParagraphAutoSpace() on why these are 100 and 280 // See SwWW8ImplReader::GetParagraphAutoSpace() on why these are 100 and 280
case NS_ooxml::LN_CT_Spacing_beforeAutospacing: case NS_ooxml::LN_CT_Spacing_beforeAutospacing:
m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "beforeAutospacing", OUString::number(nIntValue));
if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing()) if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing())
m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) ); m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) );
else else
m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(100) ) ); m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(100) ) );
break; break;
case NS_ooxml::LN_CT_Spacing_afterAutospacing: case NS_ooxml::LN_CT_Spacing_afterAutospacing:
m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "afterAutospacing", OUString::number(nIntValue));
if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing()) if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing())
m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) ); m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) );
else else
......
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