Kaydet (Commit) 1ade66e7 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/14280Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst d15f4fc6
...@@ -726,13 +726,13 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe ...@@ -726,13 +726,13 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe
{ {
text::GraphicCrop aGraphCrop( 0, 0, 0, 0 ); text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
if ( oClipRect.X1 ) 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 ) 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 ) 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 ) 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); rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
} }
} }
......
...@@ -1063,10 +1063,10 @@ void DrawingML::WriteSrcRect( Reference< XPropertySet > rXPropSet, const OUStrin ...@@ -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) ) if ( (0 != aGraphicCropStruct.Left) || (0 != aGraphicCropStruct.Top) || (0 != aGraphicCropStruct.Right) || (0 != aGraphicCropStruct.Bottom) )
{ {
mpFS->singleElementNS( XML_a, XML_srcRect, mpFS->singleElementNS( XML_a, XML_srcRect,
XML_l, I32S(((aGraphicCropStruct.Left) * 100000) / aOriginalSize.Width()), XML_l, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Left) * 100000 / aOriginalSize.Width())),
XML_t, I32S(((aGraphicCropStruct.Top) * 100000) / aOriginalSize.Height()), XML_t, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Top) * 100000 / aOriginalSize.Height())),
XML_r, I32S(((aGraphicCropStruct.Right) * 100000) / aOriginalSize.Width()), XML_r, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Right) * 100000 / aOriginalSize.Width())),
XML_b, I32S(((aGraphicCropStruct.Bottom) * 100000) / aOriginalSize.Height()), XML_b, I32S(rtl::math::round(static_cast<double>(aGraphicCropStruct.Bottom) * 100000 / aOriginalSize.Height())),
FSEND ); FSEND );
} }
} }
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <comphelper/seqstream.hxx> #include <comphelper/seqstream.hxx>
#include <vcl/wmf.hxx> #include <vcl/wmf.hxx>
#include <vcl/svapp.hxx>
#include <tools/gen.hxx>
#include "oox/helper/containerhelper.hxx" #include "oox/helper/containerhelper.hxx"
#include "oox/helper/propertyset.hxx" #include "oox/helper/propertyset.hxx"
#include "oox/token/properties.hxx" #include "oox/token/properties.hxx"
...@@ -113,7 +115,10 @@ GraphicHelper::GraphicHelper( const Reference< XComponentContext >& rxContext, c ...@@ -113,7 +115,10 @@ GraphicHelper::GraphicHelper( const Reference< XComponentContext >& rxContext, c
// get the metric of the output device // get the metric of the output device
OSL_ENSURE( xFrame.is(), "GraphicHelper::GraphicHelper - cannot get target frame" ); 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 if( xFrame.is() ) try
{ {
Reference< awt::XDevice > xDevice( xFrame->getContainerWindow(), UNO_QUERY_THROW ); Reference< awt::XDevice > xDevice( xFrame->getContainerWindow(), UNO_QUERY_THROW );
......
...@@ -64,10 +64,7 @@ protected: ...@@ -64,10 +64,7 @@ protected:
bool mustTestImportOf(const char* filename) const SAL_OVERRIDE { bool mustTestImportOf(const char* filename) const SAL_OVERRIDE {
const char* aBlacklist[] = { const char* aBlacklist[] = {
"math-escape.docx", "math-escape.docx",
"math-mso2k7.docx", "math-mso2k7.docx"
"ImageCrop.docx",
"test_GIF_ImageCrop.docx",
"test_PNG_ImageCrop.docx"
}; };
std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist)); std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist));
...@@ -672,9 +669,7 @@ DECLARE_OOXMLEXPORT_TEST(testImageCrop, "ImageCrop.docx") ...@@ -672,9 +669,7 @@ DECLARE_OOXMLEXPORT_TEST(testImageCrop, "ImageCrop.docx")
CPPUNIT_ASSERT_EQUAL( sal_Int32( 2955 ), aGraphicCropStruct.Left ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 2955 ), aGraphicCropStruct.Left );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 5477 ), aGraphicCropStruct.Right ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 5477 ), aGraphicCropStruct.Right );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 2856 ), aGraphicCropStruct.Top ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 2856 ), aGraphicCropStruct.Top );
// FIXME import test is disabled (we only check after import-export-import) CPPUNIT_ASSERT_EQUAL( sal_Int32( 2291 ), aGraphicCropStruct.Bottom );
// The reason is that after import this is 2291 -- rounding error?
CPPUNIT_ASSERT_EQUAL( sal_Int32( 2290 ), aGraphicCropStruct.Bottom );
} }
DECLARE_OOXMLEXPORT_TEST(testLineSpacingexport, "test_line_spacing.docx") DECLARE_OOXMLEXPORT_TEST(testLineSpacingexport, "test_line_spacing.docx")
...@@ -800,12 +795,10 @@ DECLARE_OOXMLEXPORT_TEST(testGIFImageCrop, "test_GIF_ImageCrop.docx") ...@@ -800,12 +795,10 @@ DECLARE_OOXMLEXPORT_TEST(testGIFImageCrop, "test_GIF_ImageCrop.docx")
imageProperties->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct; imageProperties->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct;
// FIXME import test is disabled (we only check after import-export-import) CPPUNIT_ASSERT_EQUAL( sal_Int32( 1085 ), aGraphicCropStruct.Left );
// The reason is that after import this is 1171 -- why? CPPUNIT_ASSERT_EQUAL( sal_Int32( 3651 ), aGraphicCropStruct.Right );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 1265 ), aGraphicCropStruct.Left ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 953 ), aGraphicCropStruct.Top );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 4256 ), aGraphicCropStruct.Right ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 1244 ), aGraphicCropStruct.Bottom );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 1109 ), aGraphicCropStruct.Top );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 1448 ), aGraphicCropStruct.Bottom );
#endif #endif
} }
...@@ -823,12 +816,10 @@ DECLARE_OOXMLEXPORT_TEST(testPNGImageCrop, "test_PNG_ImageCrop.docx") ...@@ -823,12 +816,10 @@ DECLARE_OOXMLEXPORT_TEST(testPNGImageCrop, "test_PNG_ImageCrop.docx")
imageProperties->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct; imageProperties->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct;
// FIXME import test is disabled (we only check after import-export-import) CPPUNIT_ASSERT_EQUAL( sal_Int32( 1058 ), aGraphicCropStruct.Left );
// The reason is that after import this is 1141 -- why? CPPUNIT_ASSERT_EQUAL( sal_Int32( 1111 ), aGraphicCropStruct.Right );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 1231 ), aGraphicCropStruct.Left ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 1164 ), aGraphicCropStruct.Top );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 1295 ), aGraphicCropStruct.Right ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 635 ), aGraphicCropStruct.Bottom );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 1358 ), aGraphicCropStruct.Top );
CPPUNIT_ASSERT_EQUAL( sal_Int32( 737 ), aGraphicCropStruct.Bottom );
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment