oox/source/drawingml/fillproperties.cxx | 8 ++++---- oox/source/export/drawingml.cxx | 8 ++++---- oox/source/helper/graphichelper.cxx | 7 ++++++- sw/qa/extras/ooxmlexport/ooxmlexport3.cxx | 29 ++++++++++------------------- 4 files changed, 24 insertions(+), 28 deletions(-)
New commits: commit 1ade66e7e70ce13c419f1ffff5222dcedec281bd Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Mon Feb 2 15:24:06 2015 +0100 oox: 89 DPI is not such a great default Using the DPI from Application::GetDefaultDevice() is a much better idea, especially that now oox::GraphicHelper::GraphicHelper() and oox::drawingml::DrawingML::WriteSrcRect() are in sync. Should fix the testCropPixel() failure in CppunitTest_sw_ooxmlexport that appears on HiDPI systems. Also, fix all the rounding problems that now became visible when the DPI is the same for both import and export. Change-Id: Iceb34a8a5a1eaa8ce0824491521ad6b4d2f6949c Reviewed-on: https://gerrit.libreoffice.org/14280 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index d25f8bf..2c0d40f 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -726,13 +726,13 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe { text::GraphicCrop aGraphCrop( 0, 0, 0, 0 ); if ( oClipRect.X1 ) - aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 ); + aGraphCrop.Left = rtl::math::round( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 ); if ( oClipRect.Y1 ) - aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 ); + aGraphCrop.Top = rtl::math::round( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 ); if ( oClipRect.X2 ) - aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 ); + aGraphCrop.Right = rtl::math::round( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 ); if ( oClipRect.Y2 ) - aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 ); + aGraphCrop.Bottom = rtl::math::round( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 ); rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop); } } diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index fcacb7a..214652d 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -1063,10 +1063,10 @@ void DrawingML::WriteSrcRect( Reference< XPropertySet > rXPropSet, const OUStrin if ( (0 != aGraphicCropStruct.Left) || (0 != aGraphicCropStruct.Top) || (0 != aGraphicCropStruct.Right) || (0 != aGraphicCropStruct.Bottom) ) { mpFS->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()), + XML_l, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Left) * 100000 / aOriginalSize.Width())), + XML_t, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Top) * 100000 / aOriginalSize.Height())), + XML_r, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Right) * 100000 / aOriginalSize.Width())), + XML_b, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Bottom) * 100000 / aOriginalSize.Height())), FSEND ); } } diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx index 0638ffe..2714cf5 100644 --- a/oox/source/helper/graphichelper.cxx +++ b/oox/source/helper/graphichelper.cxx @@ -34,6 +34,8 @@ #include <osl/diagnose.h> #include <comphelper/seqstream.hxx> #include <vcl/wmf.hxx> +#include <vcl/svapp.hxx> +#include <tools/gen.hxx> #include "oox/helper/containerhelper.hxx" #include "oox/helper/propertyset.hxx" #include "oox/token/properties.hxx" @@ -113,7 +115,10 @@ GraphicHelper::GraphicHelper( const Reference< XComponentContext >& rxContext, c // get the metric of the output device OSL_ENSURE( xFrame.is(), "GraphicHelper::GraphicHelper - cannot get target frame" ); - maDeviceInfo.PixelPerMeterX = maDeviceInfo.PixelPerMeterY = 3500.0; // some default just in case + // some default just in case, 100 000 is 1 meter in MM100 + Size aDefault = Application::GetDefaultDevice()->LogicToPixel(Size(100000, 100000), MapMode(MAP_100TH_MM)); + maDeviceInfo.PixelPerMeterX = aDefault.Width(); + maDeviceInfo.PixelPerMeterY = aDefault.Height(); if( xFrame.is() ) try { Reference< awt::XDevice > xDevice( xFrame->getContainerWindow(), UNO_QUERY_THROW ); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx index 0c5a0f8..b5e3ff4 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx @@ -64,10 +64,7 @@ protected: bool mustTestImportOf(const char* filename) const SAL_OVERRIDE { const char* aBlacklist[] = { "math-escape.docx", - "math-mso2k7.docx", - "ImageCrop.docx", - "test_GIF_ImageCrop.docx", - "test_PNG_ImageCrop.docx" + "math-mso2k7.docx" }; std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist)); @@ -672,9 +669,7 @@ DECLARE_OOXMLEXPORT_TEST(testImageCrop, "ImageCrop.docx") 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 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 2291 ), aGraphicCropStruct.Bottom ); } DECLARE_OOXMLEXPORT_TEST(testLineSpacingexport, "test_line_spacing.docx") @@ -800,12 +795,10 @@ DECLARE_OOXMLEXPORT_TEST(testGIFImageCrop, "test_GIF_ImageCrop.docx") 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 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 1085 ), aGraphicCropStruct.Left ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 3651 ), aGraphicCropStruct.Right ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 953 ), aGraphicCropStruct.Top ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 1244 ), aGraphicCropStruct.Bottom ); #endif } @@ -823,12 +816,10 @@ DECLARE_OOXMLEXPORT_TEST(testPNGImageCrop, "test_PNG_ImageCrop.docx") imageProperties->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct; - // FIXME import test is disabled (we only check after import-export-import) - // The reason is that after import this is 1141 -- why? - CPPUNIT_ASSERT_EQUAL( sal_Int32( 1231 ), aGraphicCropStruct.Left ); - CPPUNIT_ASSERT_EQUAL( sal_Int32( 1295 ), aGraphicCropStruct.Right ); - CPPUNIT_ASSERT_EQUAL( sal_Int32( 1358 ), aGraphicCropStruct.Top ); - CPPUNIT_ASSERT_EQUAL( sal_Int32( 737 ), aGraphicCropStruct.Bottom ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 1058 ), aGraphicCropStruct.Left ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 1111 ), aGraphicCropStruct.Right ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 1164 ), aGraphicCropStruct.Top ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 635 ), aGraphicCropStruct.Bottom ); #endif } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits