Kaydet (Commit) 06e696a0 authored tarafından Miklos Vajna's avatar Miklos Vajna

DOCX export: write <w:alias> inside <w:sdtPr>

Change-Id: Iaa020c00ddb3f9c6e6a9a6b2bc248a47c01a89d4
üst bd98c467
......@@ -3749,6 +3749,17 @@ DECLARE_OOXMLEXPORT_TEST(testSdt2Run, "sdt-2-run.docx")
assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r[1]/w:t", "first");
assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r[2]/w:t", "second");
}
DECLARE_OOXMLEXPORT_TEST(testSdtAlias, "sdt-alias.docx")
{
xmlDocPtr pXmlDoc = parseExport();
if (!pXmlDoc)
return;
// <w:alias> was completely missing.
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:alias", "val", "Subtitle");
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -291,7 +291,7 @@ void DocxAttributeOutput::StartParagraph( ww8::WW8TableNodeInfo::Pointer_t pText
m_bIsFirstParagraph = false;
}
static void lcl_deleteAndResetTheLists( ::sax_fastparser::FastAttributeList* &pSdtPrTokenChildren, ::sax_fastparser::FastAttributeList* &pSdtPrDataBindingAttrs)
static void lcl_deleteAndResetTheLists( ::sax_fastparser::FastAttributeList* &pSdtPrTokenChildren, ::sax_fastparser::FastAttributeList* &pSdtPrDataBindingAttrs, OUString& rSdtPrAlias)
{
if( pSdtPrTokenChildren )
{
......@@ -303,6 +303,8 @@ static void lcl_deleteAndResetTheLists( ::sax_fastparser::FastAttributeList* &pS
delete pSdtPrDataBindingAttrs;
pSdtPrDataBindingAttrs = NULL;
}
if (!rSdtPrAlias.isEmpty())
rSdtPrAlias = "";
}
void DocxAttributeOutput::PopulateFrameProperties(const SwFrmFmt* pFrmFmt, const Size& rSize)
......@@ -516,14 +518,15 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
}
m_pSerializer->endElementNS( XML_w, XML_p );
OUString aParagraphSdtPrAlias;
if( !m_bAnchorLinkedToNode )
WriteSdtBlock( m_nParagraphSdtPrToken, m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs, /*bPara=*/true );
WriteSdtBlock( m_nParagraphSdtPrToken, m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs, aParagraphSdtPrAlias, /*bPara=*/true );
else
{
//These should be written out to the actual Node and not to the anchor.
//Clear them as they will be repopulated when the node is processed.
m_nParagraphSdtPrToken = 0;
lcl_deleteAndResetTheLists( m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs );
lcl_deleteAndResetTheLists( m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs, aParagraphSdtPrAlias );
}
//sdtcontent is written so Set m_bParagraphHasDrawing to false
......@@ -559,6 +562,7 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT
void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken,
::sax_fastparser::FastAttributeList*& pSdtPrTokenChildren,
::sax_fastparser::FastAttributeList*& pSdtPrDataBindingAttrs,
OUString& rSdtPrAlias,
bool bPara )
{
if( nSdtPrToken > 0 || pSdtPrDataBindingAttrs )
......@@ -598,6 +602,11 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken,
m_pSerializer->singleElementNS( XML_w, XML_dataBinding, xAttrList );
}
if (!rSdtPrAlias.isEmpty())
m_pSerializer->singleElementNS(XML_w, XML_alias, FSNS(XML_w, XML_val),
OUStringToOString(rSdtPrAlias, RTL_TEXTENCODING_UTF8).getStr(),
FSEND);
m_pSerializer->endElementNS( XML_w, XML_sdtPr );
// sdt contents start tag
......@@ -621,6 +630,7 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken,
// do not delete yet; it's in xAttrList inside the parser
pSdtPrDataBindingAttrs = NULL;
}
rSdtPrAlias = "";
}
}
......@@ -1082,13 +1092,13 @@ void DocxAttributeOutput::EndRun()
// enclose in a sdt block, if necessary: if one is already started, then don't do it for now
// (so on export sdt blocks are never nested ATM)
if ( !m_bAnchorLinkedToNode && !m_bStartedCharSdt )
WriteSdtBlock( m_nRunSdtPrToken, m_pRunSdtPrTokenChildren, m_pRunSdtPrDataBindingAttrs, /*bPara=*/false );
WriteSdtBlock( m_nRunSdtPrToken, m_pRunSdtPrTokenChildren, m_pRunSdtPrDataBindingAttrs, m_aRunSdtPrAlias, /*bPara=*/false );
else
{
//These should be written out to the actual Node and not to the anchor.
//Clear them as they will be repopulated when the node is processed.
m_nRunSdtPrToken = 0;
lcl_deleteAndResetTheLists( m_pRunSdtPrTokenChildren, m_pRunSdtPrDataBindingAttrs );
lcl_deleteAndResetTheLists( m_pRunSdtPrTokenChildren, m_pRunSdtPrDataBindingAttrs, m_aRunSdtPrAlias );
}
m_pSerializer->mergeTopMarks();
......@@ -7776,6 +7786,11 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem )
rtl::OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() );
}
}
else if (aPropertyValue.Name == "ooxml:CT_SdtPr_alias" && m_aRunSdtPrAlias.isEmpty())
{
if (!(aPropertyValue.Value >>= m_aRunSdtPrAlias))
SAL_WARN("sw.ww8", "DocxAttributeOutput::CharGrabBag: unexpected sdt alias value");
}
//do not overwrite the parent node.
else if (aPropertyValue.Name == "ooxml:CT_SdtPr_text" && !m_pRunSdtPrTokenChildren)
m_nRunSdtPrToken = FSNS( XML_w, XML_text );
......
......@@ -691,7 +691,11 @@ private:
void WritePostponedDMLDrawing();
void WritePostponedCustomShape();
void WriteSdtBlock( sal_Int32& nSdtPrToken, ::sax_fastparser::FastAttributeList* &pSdtPrTokenChildren, ::sax_fastparser::FastAttributeList* &pSdtPrDataBindingAttrs, bool bPara );
void WriteSdtBlock(sal_Int32& nSdtPrToken,
::sax_fastparser::FastAttributeList*& pSdtPrTokenChildren,
::sax_fastparser::FastAttributeList*& pSdtPrDataBindingAttrs,
OUString& rSdtPrAlias,
bool bPara);
/// Closes a currently open SDT block.
void EndSdtBlock();
......@@ -892,6 +896,7 @@ private:
sal_Int32 m_nRunSdtPrToken;
::sax_fastparser::FastAttributeList *m_pRunSdtPrTokenChildren;
::sax_fastparser::FastAttributeList *m_pRunSdtPrDataBindingAttrs;
OUString m_aRunSdtPrAlias;
std::map<sal_uInt16, css::table::BorderLine2> m_aTableStyleConf;
......
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