summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorPallavi Jadhav <pallavi.jadhav@synerzip.com>2013-10-14 14:47:15 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-11-14 11:17:23 +0100
commit7b947fe24299108fd74baa79c6c25ed8022caf78 (patch)
treecf341e7337ee45b4c2e6d534b938c3aefe0f8989 /sw/source
parent0d388a00adf2f588796be1b7c743f858f8dc0fc4 (diff)
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
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx48
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx6
2 files changed, 45 insertions, 9 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index cb16233320cc..01738692dfe4 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 02f7761e2404..1c8239b0d9e9 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