diff options
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/ImageCrop.docx | bin | 0 -> 71650 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 18 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 48 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 6 |
4 files changed, 63 insertions, 9 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/ImageCrop.docx b/sw/qa/extras/ooxmlexport/data/ImageCrop.docx Binary files differnew file mode 100644 index 000000000000..120ce78eb7de --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/ImageCrop.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 5141d360cc7f..925da1b93fc2 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 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 |