include/oox/export/vmlexport.hxx                    |    2 
 oox/source/export/vmlexport.cxx                     |   27 ++++++++-
 sw/qa/extras/ooxmlexport/data/pictureWatermark.docx |binary
 sw/qa/extras/ooxmlexport/data/textWatermark.docx    |binary
 sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx         |   26 ++++++++
 sw/source/filter/ww8/wrtw8nds.cxx                   |   58 +++++++++++++++++++-
 sw/source/filter/ww8/wrtww8.hxx                     |    2 
 7 files changed, 111 insertions(+), 4 deletions(-)

New commits:
commit ff2f55d6f0a515c8c6e4186e124db28cc4056f5b
Author: Ravindra Vidhate <ravindra.vidh...@synerzip.com>
Date:   Wed Mar 5 11:38:22 2014 +0530

    fdo#35324: Text and picture water are not imported  and not preserved in RT.
    
    Problem : Open docx file which has Text/Picture as water mark.
    1. The text is not imported properly also picture water mark is also 
considered as shape.
    2. It writes the watermarks in Document.xml, while it should write in only 
Header.xml.
    
    Conflicts:
        sw/qa/extras/ooxmlexport/ooxmlexport.cxx
    
    Reviewed on:
        https://gerrit.libreoffice.org/8457
    
    Change-Id: Ic988858da25a4cba3ae16e614d920e2e16053a5f

diff --git a/include/oox/export/vmlexport.hxx b/include/oox/export/vmlexport.hxx
index 2b414c0..744dbbd 100644
--- a/include/oox/export/vmlexport.hxx
+++ b/include/oox/export/vmlexport.hxx
@@ -90,7 +90,7 @@ public:
             sal_Int16 eVOri = -1, sal_Int16 eHRel = -1,
             sal_Int16 eVRel = -1, const Point* pNdTopLeft = 0, const sal_Bool 
bOOxmlExport = false );
     virtual void  AddSdrObjectVMLObject( const SdrObject& rObj);
-
+    static bool IsWaterMarkShape(const OUString& rStr);
 protected:
     /// Add an attribute to the generated <v:shape/> element.
     ///
diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx
index 35eeae7..fe82ea0 100644
--- a/oox/source/export/vmlexport.cxx
+++ b/oox/source/export/vmlexport.cxx
@@ -175,7 +175,28 @@ void VMLExport::AddShape( sal_uInt32 nShapeType, 
sal_uInt32 nShapeFlags, sal_uIn
 {
     m_nShapeType = nShapeType;
     m_nShapeFlags = nShapeFlags;
-    m_pShapeAttrList->add( XML_id, ShapeIdString( nShapeId ) );
+    // If shape is a watermark object - should keep the original shape's name
+    // because Microsoft detects if it is a watermark by the actual name
+    if (!IsWaterMarkShape(m_pSdrObject->GetName()))
+    {
+        // Not a watermark object
+        m_pShapeAttrList->add( XML_id, ShapeIdString( nShapeId ) );
+    }
+    else
+    {
+        // A watermark object - store the optional shape ID also ('o:spid')
+        m_pShapeAttrList->add( XML_id, 
OUStringToOString(m_pSdrObject->GetName(), RTL_TEXTENCODING_UTF8) );
+    }
+}
+
+bool VMLExport::IsWaterMarkShape(const OUString& rStr)
+{
+     if (rStr.isEmpty() )  return false;
+
+     if (rStr.match(OUString("PowerPlusWaterMarkObject")) || 
rStr.match(OUString("WordPictureWatermark")))
+        return true;
+     else
+        return false;
 }
 
 static void impl_AddArrowHead( sax_fastparser::FastAttributeList *pAttrList, 
sal_Int32 nElement, sal_uInt32 nValue )
@@ -787,7 +808,9 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, 
const Rectangle& rRect
                     aStream.Seek(0);
                     OUString idStr = 
SvxMSDffManager::MSDFFReadZString(aStream, it->nPropSize, true);
                     aStream.Seek(0);
-                    m_pShapeAttrList->add(XML_ID, OUStringToOString(idStr, 
RTL_TEXTENCODING_UTF8));
+                    if (!IsWaterMarkShape(m_pSdrObject->GetName()))
+                         m_pShapeAttrList->add(XML_ID, 
OUStringToOString(idStr, RTL_TEXTENCODING_UTF8));
+
                     bAlreadyWritten[ESCHER_Prop_wzName] = true;
                 }
                 break;
diff --git a/sw/qa/extras/ooxmlexport/data/pictureWatermark.docx 
b/sw/qa/extras/ooxmlexport/data/pictureWatermark.docx
new file mode 100644
index 0000000..b526ecf
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/pictureWatermark.docx differ
diff --git a/sw/qa/extras/ooxmlexport/data/textWatermark.docx 
b/sw/qa/extras/ooxmlexport/data/textWatermark.docx
new file mode 100644
index 0000000..c8bff75
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/textWatermark.docx 
differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
index 8842cdd..d46f583 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
@@ -911,6 +911,32 @@ DECLARE_OOXMLEXPORT_TEST(testDkVert, "dkvert.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(25), getProperty<drawing::Hatch>(xShape, 
"FillHatch").Distance);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTextWatermark, "textWatermark.docx")
+{
+    //The problem was that the watermark ID was not preserved,
+    //and Word uses the object ID to identify if it is a watermark.
+    //It has to have the 'PowerPlusWaterMarkObject' string in it
+    xmlDocPtr pXmlHeader1 = parseExport("word/header1.xml");
+    if (!pXmlHeader1)
+       return;
+
+    assertXPath(pXmlHeader1, 
"/w:hdr[1]/w:p[1]/w:r[1]/w:pict[1]/v:shape[1]","id","PowerPlusWaterMarkObject93701316");
+}
+
+DECLARE_OOXMLEXPORT_TEST(testPictureWatermark, "pictureWatermark.docx")
+{
+    //The problem was that the watermark ID was not preserved,
+    //and Word uses the object ID to identify if it is a watermark.
+    //It has to have the 'WordPictureWaterMarkObject' string in it
+
+    xmlDocPtr pXmlHeader1 = parseExport("word/header1.xml");
+    if (!pXmlHeader1)
+       return;
+
+    // Check the watermark ID
+    assertXPath(pXmlHeader1, 
"/w:hdr[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Fallback[1]/w:pict[1]/v:rect[1]","id","WordPictureWatermark11962361");
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index b10ece7..abe9360 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -81,6 +81,7 @@
 #include <fmtrowsplt.hxx>
 #include <com/sun/star/i18n/ScriptType.hpp>
 #include <com/sun/star/i18n/WordType.hpp>
+#include <oox/export/vmlexport.hxx>
 
 #include <filter/msfilter/sprmids.hxx>
 
@@ -103,6 +104,7 @@ using namespace sw::util;
 using namespace sw::types;
 using namespace sw::mark;
 using namespace nsFieldFlags;
+using namespace ::oox::vml;
 
 static OUString lcl_getFieldCode( const IFieldmark* pFieldmark )
 {
@@ -518,6 +520,26 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby )
         m_rExport.AttrOutput().OutputItem( *pGrabBag );
 }
 
+bool SwWW8AttrIter::IsWatermarkFrame()
+{
+    if (maFlyFrms.size() != 1)
+        return false;
+
+    while ( maFlyIter != maFlyFrms.end() )
+    {
+        const SdrObject* pSdrObj = maFlyIter->GetFrmFmt().FindRealSdrObject();
+
+        if (pSdrObj)
+        {
+            if (VMLExport::IsWaterMarkShape(pSdrObj->GetName()))
+                  return true;
+        }
+        ++maFlyIter;
+    }
+
+    return false;
+}
+
 void SwWW8AttrIter::OutFlys(sal_Int32 nSwPos)
 {
     /*
@@ -533,7 +555,34 @@ void SwWW8AttrIter::OutFlys(sal_Int32 nSwPos)
         if ( nPos != nSwPos )
             break;
 
-        m_rExport.AttrOutput().OutputFlyFrame( *maFlyIter );
+        const SdrObject* pSdrObj = maFlyIter->GetFrmFmt().FindRealSdrObject();
+
+        if (pSdrObj)
+        {
+            if (VMLExport::IsWaterMarkShape(pSdrObj->GetName()))
+            {
+                 // This is a watermark object. Should be written ONLY in the 
header
+                 if(m_rExport.nTxtTyp == TXT_HDFT)
+                 {
+                       // Should write a watermark in the header
+                       m_rExport.AttrOutput().OutputFlyFrame( *maFlyIter );
+                 }
+                 else
+                 {
+                       // Should not write watermark object in the main body 
text
+                 }
+            }
+            else
+            {
+                 // This is not a watermark object - write normally
+                 m_rExport.AttrOutput().OutputFlyFrame( *maFlyIter );
+            }
+        }
+        else
+        {
+            // This is not a watermark object - write normally
+            m_rExport.AttrOutput().OutputFlyFrame( *maFlyIter );
+        }
         ++maFlyIter;
     }
 }
@@ -1904,6 +1953,13 @@ void MSWordExportBase::OutputTextNode( const SwTxtNode& 
rNode )
             bLastCR = true;
     }
 
+    // In order to make sure watermark is stored in 'header.xml', check 
nTxtTyp.
+    // if it is document.xml, don't write the tags (watermark should be only 
in the 'header')
+    SwWW8AttrIter aWatermarkAttrIter( *this, rNode );
+    if (( TXT_HDFT != nTxtTyp) && aWatermarkAttrIter.IsWatermarkFrame())
+    {
+       return;
+    }
 
     bool bFlyInTable = mpParentFrame && IsInTable();
 
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 0dfcfb3..9a1d7b5 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -1539,6 +1539,8 @@ public:
     OUString GetSnippet(const OUString &rStr, sal_Int32 nAktPos,
         sal_Int32 nLen) const;
     const SwFmtDrop& GetSwFmtDrop() const { return mrSwFmtDrop; }
+
+    bool IsWatermarkFrame();
 };
 
 /// Class to collect and output the styles table.
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to