[Libreoffice-commits] core.git: 2 commits - sw/qa sw/source writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Jul 10 04:45:59 PDT 2014


 sw/qa/extras/ooxmlexport/data/sdt-alias.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx     |   11 +++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   25 ++++++++++++++++++++-----
 sw/source/filter/ww8/docxattributeoutput.hxx |    7 ++++++-
 writerfilter/source/dmapper/DomainMapper.cxx |   12 +++++++++++-
 5 files changed, 48 insertions(+), 7 deletions(-)

New commits:
commit 06e696a043114fcaba005cd8feac0ecb7ecede4a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 10 11:48:06 2014 +0200

    DOCX export: write <w:alias> inside <w:sdtPr>
    
    Change-Id: Iaa020c00ddb3f9c6e6a9a6b2bc248a47c01a89d4

diff --git a/sw/qa/extras/ooxmlexport/data/sdt-alias.docx b/sw/qa/extras/ooxmlexport/data/sdt-alias.docx
new file mode 100644
index 0000000..f46ef69
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/sdt-alias.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index d534ed9..d156805 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -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: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 85c45da..2026ddd 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -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 );
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 34362f3..99adbd9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -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;
 
commit bd98c467e415d506cd690730e38ead9f3633eb18
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 10 11:17:20 2014 +0200

    DOCX import: handle <w:alias> in <w:sdtPr>
    
    Change-Id: Ia064421ac9c6f84015b1527a3d179dede3f6f832

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index f6a91fb..8f0d765 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2304,6 +2304,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
     case NS_ooxml::LN_CT_SdtPr_group:
     case NS_ooxml::LN_CT_SdtPr_text:
     case NS_ooxml::LN_CT_SdtPr_id:
+    case NS_ooxml::LN_CT_SdtPr_alias:
     {
         // this is an unsupported SDT property, create a grab bag for it
         OUString sName;
@@ -2319,6 +2320,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
             case NS_ooxml::LN_CT_SdtPr_group:       sName = "ooxml:CT_SdtPr_group"; break;
             case NS_ooxml::LN_CT_SdtPr_text:        sName = "ooxml:CT_SdtPr_text"; break;
             case NS_ooxml::LN_CT_SdtPr_id:          sName = "ooxml:CT_SdtPr_id"; break;
+            case NS_ooxml::LN_CT_SdtPr_alias:       sName = "ooxml:CT_SdtPr_alias"; break;
             default: assert(false);
         };
         enableInteropGrabBag(sName);
@@ -2328,7 +2330,15 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
         if (pProperties.get() != NULL)
             pProperties->resolve(*this);
 
-        m_pImpl->m_pSdtHelper->appendToInteropGrabBag(getInteropGrabBag());
+        if (nSprmId == NS_ooxml::LN_CT_SdtPr_alias)
+        {
+            beans::PropertyValue aValue;
+            aValue.Name = sName;
+            aValue.Value <<= sStringValue;
+            m_pImpl->m_pSdtHelper->appendToInteropGrabBag(aValue);
+        }
+        else
+            m_pImpl->m_pSdtHelper->appendToInteropGrabBag(getInteropGrabBag());
         m_pImpl->disableInteropGrabBag();
     }
     break;


More information about the Libreoffice-commits mailing list