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

Pallavi Jadhav pallavi.jadhav at synerzip.com
Thu Nov 14 02:17:47 PST 2013


 sw/qa/extras/ooxmlexport/data/ImageCrop.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx     |   18 ++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   48 +++++++++++++++++++++++----
 sw/source/filter/ww8/docxattributeoutput.hxx |    6 ++-
 4 files changed, 63 insertions(+), 9 deletions(-)

New commits:
commit 7b947fe24299108fd74baa79c6c25ed8022caf78
Author: Pallavi Jadhav <pallavi.jadhav at synerzip.com>
Date:   Mon Oct 14 14:47:15 2013 +0530

    Save Image-Crop information in docx
    
    Issue:-
    1] When MS Office docx file containing cropped image is
       round tripped with LibreOffice 4.2, image looses
       its cropping effect.
    
    Implentation:-
    1] Function WriteSrcRect() is implemnted inside docxattributeoutput.cxx
    2] It writes out xml tag <a:srcRect> which is responsible for storing
       cropping parameters
    3] Written Unit Test to verify cropping parameters
    
    Conflicts:
    	sw/qa/extras/ooxmlimport/ooxmlimport.cxx
    Reviewed on:
    	https://gerrit.libreoffice.org/6240
    
    Change-Id: I6ab30305bae44ca1bfef73b0df2967d943ee60fe

diff --git a/sw/qa/extras/ooxmlexport/data/ImageCrop.docx b/sw/qa/extras/ooxmlexport/data/ImageCrop.docx
new file mode 100644
index 0000000..120ce78
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/ImageCrop.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 5141d36..925da1b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -30,6 +30,7 @@
 #include <com/sun/star/view/XSelectionSupplier.hpp>
 #include <com/sun/star/table/BorderLine2.hpp>
 #include <com/sun/star/table/ShadowFormat.hpp>
+#include <com/sun/star/text/GraphicCrop.hpp>
 #include <com/sun/star/text/XPageCursor.hpp>
 #include <com/sun/star/awt/FontWeight.hpp>
 #include <com/sun/star/awt/FontUnderline.hpp>
@@ -92,6 +93,7 @@ protected:
         const char* aBlacklist[] = {
             "math-escape.docx",
             "math-mso2k7.docx",
+            "ImageCrop.docx",
         };
         std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist));
 
@@ -1629,6 +1631,22 @@ DECLARE_OOXML_TEST(testImageData, "image_data.docx")
     CPPUNIT_ASSERT(getXPath(pXmlDoc, "/w:hdr/w:p/w:r/w:pict/v:shape/v:imagedata", "detectmouseclick").match("t"));
 }
 
+DECLARE_OOXML_TEST(testImageCrop, "ImageCrop.docx")
+{
+    uno::Reference<drawing::XShape> image = getShape(1);
+    uno::Reference<beans::XPropertySet> imageProperties(image, uno::UNO_QUERY);
+    ::com::sun::star::text::GraphicCrop aGraphicCropStruct;
+
+    imageProperties->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct;
+
+    CPPUNIT_ASSERT_EQUAL( sal_Int32( 2955 ), aGraphicCropStruct.Left );
+    CPPUNIT_ASSERT_EQUAL( sal_Int32( 5477 ), aGraphicCropStruct.Right );
+    CPPUNIT_ASSERT_EQUAL( sal_Int32( 2856 ), aGraphicCropStruct.Top );
+    // FIXME import test is disabled (we only check after import-export-import)
+    // The reason is that after import this is 2291 -- rounding error?
+    CPPUNIT_ASSERT_EQUAL( sal_Int32( 2290 ), aGraphicCropStruct.Bottom );
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index cb16233..0173869 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -119,6 +119,7 @@
 #include <com/sun/star/xml/dom/XAttr.hpp>
 #include <com/sun/star/xml/sax/Writer.hpp>
 #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
+#include <com/sun/star/text/GraphicCrop.hpp>
 
 #if OSL_DEBUG_LEVEL > 1
 #include <stdio.h>
@@ -135,6 +136,7 @@ using namespace sw::util;
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::drawing;
 
+
 class FFDataWriterHelper
 {
     ::sax_fastparser::FSHelperPtr m_pSerializer;
@@ -1171,7 +1173,7 @@ void DocxAttributeOutput::WritePostponedGraphic()
     for( std::list< PostponedGraphic >::const_iterator it = m_postponedGraphic->begin();
          it != m_postponedGraphic->end();
          ++it )
-        FlyFrameGraphic( it->grfNode, it->size );
+        FlyFrameGraphic( it->grfNode, it->size, 0, 0, it->pSdrObj );
     delete m_postponedGraphic;
     m_postponedGraphic = NULL;
 }
@@ -2687,9 +2689,37 @@ OString lcl_ConvertTransparency(const Color& rColor)
         return OString("");
 }
 
-void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt, SwOLENode* pOLENode )
+/* Writes <a:srcRect> tag back to document.xml if a file conatins a cropped image.
+   NOTE : It works only for images of type JPEG,EMF/WMF and BMP.
+          It does not work for images of type PNG and GIF.
+*/
+void DocxAttributeOutput::WriteSrcRect(const SdrObject* pSdrObj )
+{
+    uno::Reference< drawing::XShape > xShape( ((SdrObject*)pSdrObj)->getUnoShape(), uno::UNO_QUERY );
+    uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
+
+    OUString sUrl;
+    xPropSet->getPropertyValue("GraphicURL") >>= sUrl;
+    Size aOriginalSize( GraphicObject::CreateGraphicObjectFromURL( sUrl ).GetPrefSize() );
+
+    ::com::sun::star::text::GraphicCrop aGraphicCropStruct;
+    xPropSet->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct;
+
+    if ( (0 != aGraphicCropStruct.Left) || (0 != aGraphicCropStruct.Top) || (0 != aGraphicCropStruct.Right) || (0 != aGraphicCropStruct.Bottom) )
+    {
+            m_pSerializer->singleElementNS( XML_a, XML_srcRect,
+                          XML_l, I32S(((aGraphicCropStruct.Left) * 100000)/aOriginalSize.Width()),
+                          XML_t, I32S(((aGraphicCropStruct.Top) * 100000)/aOriginalSize.Height()),
+                          XML_r, I32S(((aGraphicCropStruct.Right) * 100000)/aOriginalSize.Width()),
+                          XML_b, I32S(((aGraphicCropStruct.Bottom) * 100000)/aOriginalSize.Height()),
+                          FSEND );
+
+    }
+}
+
+void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt, SwOLENode* pOLENode, const SdrObject* pSdrObj )
 {
-    OSL_TRACE( "TODO DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt, SwOLENode* pOLENode ) - some stuff still missing" );
+    OSL_TRACE( "TODO DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt, SwOLENode* pOLENode, const SdrObject* pSdrObj  ) - some stuff still missing" );
     // detect mis-use of the API
     assert(pGrfNode || (pOLEFrmFmt && pOLENode));
     const SwFrmFmt* pFrmFmt = pGrfNode ? pGrfNode->GetFlyFmt() : pOLEFrmFmt;
@@ -2994,8 +3024,11 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
     m_pSerializer->singleElementNS( XML_a, XML_blip,
             FSNS( XML_r, nImageType ), aRelId.getStr(),
             FSEND );
-    m_pSerializer->singleElementNS( XML_a, XML_srcRect,
-            FSEND );
+
+    if (pSdrObj){
+        WriteSrcRect(pSdrObj);
+    }
+
     m_pSerializer->startElementNS( XML_a, XML_stretch,
             FSEND );
     m_pSerializer->singleElementNS( XML_a, XML_fillRect,
@@ -3283,15 +3316,16 @@ void DocxAttributeOutput::OutputFlyFrame_Impl( const sw::Frame &rFrame, const Po
     {
         case sw::Frame::eGraphic:
             {
+                const SdrObject* pSdrObj = rFrame.GetFrmFmt().FindRealSdrObject();
                 const SwNode *pNode = rFrame.GetContent();
                 const SwGrfNode *pGrfNode = pNode ? pNode->GetGrfNode() : 0;
                 if ( pGrfNode )
                 {
                     if( m_postponedGraphic == NULL )
-                        FlyFrameGraphic( pGrfNode, rFrame.GetLayoutSize() );
+                        FlyFrameGraphic( pGrfNode, rFrame.GetLayoutSize(), 0, 0, pSdrObj);
                     else // we are writing out attributes, but w:drawing should not be inside w:rPr,
                     {    // so write it out later
-                        m_postponedGraphic->push_back( PostponedGraphic( pGrfNode, rFrame.GetLayoutSize()));
+                        m_postponedGraphic->push_back( PostponedGraphic( pGrfNode, rFrame.GetLayoutSize(), pSdrObj));
                     }
                 }
             }
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 02f7761..1c8239b 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -361,7 +361,8 @@ private:
     /// replacement graphics, set the first as 0, and pass the remaining three.
     ///
     /// @see WriteOLE2Obj()
-    void FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt = 0, SwOLENode* pOLENode = 0);
+    void FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt = 0, SwOLENode* pOLENode = 0, const SdrObject* pSdrObj = 0);
+    void WriteSrcRect( const SdrObject* pSdrObj );
     void WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rNode, const Size& rSize, const SwFlyFrmFmt* pFlyFrmFmt);
     bool WriteOLEChart( const SdrObject* pSdrObj, const Size& rSize );
     bool WriteOLEMath( const SdrObject* pSdrObj, const SwOLENode& rNode, const Size& rSize );
@@ -727,9 +728,10 @@ private:
 
     struct PostponedGraphic
     {
-        PostponedGraphic( const SwGrfNode* n, Size s ) : grfNode( n ), size( s ) {};
+        PostponedGraphic( const SwGrfNode* n, Size s,  const SdrObject* sObj ) : grfNode( n ), size( s ),  pSdrObj(sObj) {};
         const SwGrfNode* grfNode;
         Size size;
+        const SdrObject* pSdrObj;
     };
     std::list< PostponedGraphic >* m_postponedGraphic;
     struct PostponedDiagram


More information about the Libreoffice-commits mailing list