summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorPallavi Jadhav <pallavi.jadhav@synerzip.com>2013-11-15 13:10:30 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-11-15 17:15:28 +0100
commit09d381adbfba893331a07918c9ec9b3c58939dfb (patch)
tree93d047a91eec179282346873107c16eb81971f76 /sw
parent4837353ed445fb0b89398a7f2ae2b6cde3dea347 (diff)
Save Image-Crop information for GIF in docx
Issue:- 1] When MS Office docx file containing cropped image is round tripped with LibreOffice 4.2, image looses its cropping effect. Implementation:- 1] Converted MAP unit, MAP_PIXEL to MAP_100TH_MM using PixelToLogic function. As for calculating EMU values for XML, we need Original Height and Width of an image in 100thMM(HMM) format. 2] Written Export Unit Test (GIF) to verify cropping parameters. Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport.cxx Reviewed on: https://gerrit.libreoffice.org/6595 Change-Id: I54d7b08c96608a0cfca3c2f8833684c09848351c
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/test_GIF_ImageCrop.docxbin0 -> 19624 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx18
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx10
3 files changed, 26 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/test_GIF_ImageCrop.docx b/sw/qa/extras/ooxmlexport/data/test_GIF_ImageCrop.docx
new file mode 100644
index 000000000000..8fe7ff2225c3
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/test_GIF_ImageCrop.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 23fe7cd53b52..b7bdaef0f95f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -94,6 +94,7 @@ protected:
"math-escape.docx",
"math-mso2k7.docx",
"ImageCrop.docx",
+ "test_GIF_ImageCrop.docx"
};
std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist));
@@ -1839,6 +1840,23 @@ DECLARE_OOXML_TEST(testParaAutoSpacing, "para-auto-spacing.docx")
CPPUNIT_ASSERT(getXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "beforeAutospacing").match("1"));
CPPUNIT_ASSERT(getXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "afterAutospacing").match("1"));
}
+
+DECLARE_OOXML_TEST(testGIFImageCrop, "test_GIF_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;
+
+ // FIXME import test is disabled (we only check after import-export-import)
+ // The reason is that after import this is 1171 -- why?
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 1265 ), aGraphicCropStruct.Left );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 4256 ), aGraphicCropStruct.Right );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 1109 ), aGraphicCropStruct.Top );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 1448 ), aGraphicCropStruct.Bottom );
+}
+
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 70361fad9fa0..80c17e3eeb63 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2689,8 +2689,7 @@ OString lcl_ConvertTransparency(const Color& rColor)
}
/* 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.
+* NOTE : Tested on images of type JPEG,EMF/WMF,BMP, PNG and GIF.
*/
void DocxAttributeOutput::WriteSrcRect(const SdrObject* pSdrObj )
{
@@ -2704,6 +2703,13 @@ void DocxAttributeOutput::WriteSrcRect(const SdrObject* pSdrObj )
::com::sun::star::text::GraphicCrop aGraphicCropStruct;
xPropSet->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct;
+ const MapMode aMap100mm( MAP_100TH_MM );
+ const MapMode& mapMode = GraphicObject::CreateGraphicObjectFromURL( sUrl ).GetPrefMapMode();
+ if( mapMode.GetMapUnit() == MAP_PIXEL )
+ {
+ aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aOriginalSize, aMap100mm );
+ }
+
if ( (0 != aGraphicCropStruct.Left) || (0 != aGraphicCropStruct.Top) || (0 != aGraphicCropStruct.Right) || (0 != aGraphicCropStruct.Bottom) )
{
double widthMultiplier = 100000.0/aOriginalSize.Width();