[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - include/oox oox/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 21 09:45:34 UTC 2021


 include/oox/helper/graphichelper.hxx |    5 ++-
 oox/source/helper/graphichelper.cxx  |   54 ++++++++++++++---------------------
 2 files changed, 26 insertions(+), 33 deletions(-)

New commits:
commit cf3453de6400374f3486585ae758423ef621a220
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Jun 18 16:24:11 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jun 21 11:44:11 2021 +0200

    fix loading calc files with embedded form macros
    
    GraphicHelper was trying to use the current frame/
    window to convert values, but during initial load
    there is no current window.
    
    Change-Id: I8a79501df1d2e83a13d3cfb64ae8e66152c60561
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117470
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    (cherry picked from commit 8fa14ac550ddc43790b65858f18d23f522aff1f2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117553

diff --git a/include/oox/helper/graphichelper.hxx b/include/oox/helper/graphichelper.hxx
index 50c54175db93..6e6a255d9bd6 100644
--- a/include/oox/helper/graphichelper.hxx
+++ b/include/oox/helper/graphichelper.hxx
@@ -32,6 +32,7 @@
 #include <sal/types.h>
 #include <com/sun/star/graphic/XGraphicProvider2.hpp>
 #include <com/sun/star/graphic/XGraphicMapper.hpp>
+#include <vcl/vclptr.hxx>
 
 struct WmfExternal;
 
@@ -46,6 +47,7 @@ namespace com::sun::star {
     namespace graphic { class XGraphicProvider; }
     namespace uno { class XComponentContext; }
 }
+class OutputDevice;
 
 namespace oox {
 
@@ -105,6 +107,7 @@ public:
     /** Converts the passed size from 1/100 mm to AppFont units. */
     css::awt::Size convertHmmToAppFont( const css::awt::Size& rHmm ) const;
 
+
     // Graphics and graphic objects  ------------------------------------------
 
     /** Imports a graphic from the passed input stream. */
@@ -134,7 +137,7 @@ private:
 
     css::uno::Reference< css::uno::XComponentContext > mxContext;
     css::uno::Reference< css::graphic::XGraphicProvider2 > mxGraphicProvider;
-    css::uno::Reference< css::awt::XUnitConversion > mxUnitConversion;
+    VclPtr<OutputDevice> mxDefaultOutputDevice;
     css::awt::DeviceInfo maDeviceInfo; ///< Current output device info.
     ::std::map< sal_Int32, ::Color >  maSystemPalette;  ///< Maps system colors (XML tokens) to RGB color values.
     StorageRef          mxStorage;                  ///< Storage containing embedded graphics.
diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx
index 522ffff73f6f..7bc3178173e3 100644
--- a/oox/source/helper/graphichelper.cxx
+++ b/oox/source/helper/graphichelper.cxx
@@ -35,6 +35,7 @@
 #include <vcl/svapp.hxx>
 #include <vcl/outdev.hxx>
 #include <tools/gen.hxx>
+#include <tools/diagnose_ex.h>
 #include <comphelper/sequence.hxx>
 #include <oox/helper/containerhelper.hxx>
 #include <oox/helper/propertyset.hxx>
@@ -60,7 +61,7 @@ sal_Int32 lclConvertScreenPixelToHmm( double fPixel, double fPixelPerHmm )
 
 } // namespace
 
-GraphicHelper::GraphicHelper( const Reference< XComponentContext >& rxContext, const Reference< XFrame >& rxTargetFrame, const StorageRef& rxStorage ) :
+GraphicHelper::GraphicHelper( const Reference< XComponentContext >& rxContext, const Reference< XFrame >& /*rxTargetFrame*/, const StorageRef& rxStorage ) :
     mxContext( rxContext ),
     mxStorage( rxStorage )
 {
@@ -100,35 +101,15 @@ GraphicHelper::GraphicHelper( const Reference< XComponentContext >& rxContext, c
     maSystemPalette[ XML_windowFrame ]              = Color(0x000000);
     maSystemPalette[ XML_windowText ]               = Color(0x000000);
 
-    // if no target frame has been passed (e.g. OLE objects), try to fallback to the active frame
-    // TODO: we need some mechanism to keep and pass the parent frame
-    Reference< XFrame > xFrame = rxTargetFrame;
-    if( !xFrame.is() && mxContext.is() ) try
-    {
-        Reference< XDesktop2 > xFramesSupp = Desktop::create( mxContext );
-        xFrame = xFramesSupp->getActiveFrame();
-    }
-    catch( Exception& )
-    {
-    }
-
-    // get the metric of the output device
-    OSL_ENSURE( xFrame.is(), "GraphicHelper::GraphicHelper - cannot get target frame" );
-    // some default just in case, 100 000 is 1 meter in MM100
-    Size aDefault = Application::GetDefaultDevice()->LogicToPixel(Size(100000, 100000), MapMode(MapUnit::Map100thMM));
+    // Note that we cannot try to get DeviceInfo from the current frame here,
+    // because there might not be a current frame yet
+    mxDefaultOutputDevice = Application::GetDefaultDevice();
+    maDeviceInfo = mxDefaultOutputDevice->GetDeviceInfo();
+    // 100 000 is 1 meter in MM100.
+    // various unit tests rely on these values being exactly this and not the "true" values
+    Size aDefault = mxDefaultOutputDevice->LogicToPixel(Size(100000, 100000), MapMode(MapUnit::Map100thMM));
     maDeviceInfo.PixelPerMeterX = aDefault.Width();
     maDeviceInfo.PixelPerMeterY = aDefault.Height();
-    if( xFrame.is() ) try
-    {
-        Reference< awt::XDevice > xDevice( xFrame->getContainerWindow(), UNO_QUERY_THROW );
-        mxUnitConversion.set( xDevice, UNO_QUERY );
-        OSL_ENSURE( mxUnitConversion.is(), "GraphicHelper::GraphicHelper - cannot get unit converter" );
-        maDeviceInfo = xDevice->getInfo();
-    }
-    catch( Exception& )
-    {
-        OSL_FAIL( "GraphicHelper::GraphicHelper - cannot get output device info" );
-    }
     mfPixelPerHmmX = maDeviceInfo.PixelPerMeterX / 100000.0;
     mfPixelPerHmmY = maDeviceInfo.PixelPerMeterY / 100000.0;
 }
@@ -215,30 +196,39 @@ awt::Size GraphicHelper::convertHmmToScreenPixel( const awt::Size& rHmm ) const
 
 awt::Point GraphicHelper::convertHmmToAppFont( const awt::Point& rHmm ) const
 {
-    if( mxUnitConversion.is() ) try
+    try
     {
         awt::Point aPixel = convertHmmToScreenPixel( rHmm );
-        return mxUnitConversion->convertPointToLogic( aPixel, css::util::MeasureUnit::APPFONT );
+        MapMode aMode(MapUnit::MapAppFont);
+        ::Point aVCLPoint(aPixel.X, aPixel.Y);
+        ::Point aDevPoint = mxDefaultOutputDevice->PixelToLogic(aVCLPoint, aMode );
+        return awt::Point(aDevPoint.X(), aDevPoint.Y());
     }
     catch( Exception& )
     {
+        DBG_UNHANDLED_EXCEPTION("oox");
     }
     return awt::Point( 0, 0 );
 }
 
 awt::Size GraphicHelper::convertHmmToAppFont( const awt::Size& rHmm ) const
 {
-    if( mxUnitConversion.is() ) try
+    try
     {
         awt::Size aPixel = convertHmmToScreenPixel( rHmm );
-        return mxUnitConversion->convertSizeToLogic( aPixel, css::util::MeasureUnit::APPFONT );
+        MapMode aMode(MapUnit::MapAppFont);
+        ::Size aVCLSize(aPixel.Width, aPixel.Height);
+        ::Size aDevSz = mxDefaultOutputDevice->PixelToLogic(aVCLSize, aMode );
+        return awt::Size(aDevSz.Width(), aDevSz.Height());
     }
     catch( Exception& )
     {
+        DBG_UNHANDLED_EXCEPTION("oox");
     }
     return awt::Size( 0, 0 );
 }
 
+
 // Graphics and graphic objects  ----------------------------------------------
 
 Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStream >& rxInStrm,


More information about the Libreoffice-commits mailing list