[PATCH libreoffice-4-0] Fix fdo#59970 slowless of about box rendering

Thorsten Behrens (via Code Review) gerrit at gerrit.libreoffice.org
Fri Feb 15 16:25:34 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2183

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/83/2183/1

Fix fdo#59970 slowless of about box rendering

Prevent creation of transparent bitmap at arbitrary scale, and
subsequent scaling down. For remote X, that even has to fetch
pixel back from remote side for manual scaling.

Change-Id: I58e011231f2b81b913a6b02dd973385ef5664379
---
M cui/Library_cui.mk
M cui/source/dialogs/about.cxx
2 files changed, 103 insertions(+), 23 deletions(-)



diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk
index 404e72f..b367ad1 100644
--- a/cui/Library_cui.mk
+++ b/cui/Library_cui.mk
@@ -50,6 +50,7 @@
     comphelper \
     cppu \
     cppuhelper \
+    drawinglayer \
     editeng \
     i18nisolang1 \
     jvmfwk \
diff --git a/cui/source/dialogs/about.cxx b/cui/source/dialogs/about.cxx
index 2c9df74..7179110 100644
--- a/cui/source/dialogs/about.cxx
+++ b/cui/source/dialogs/about.cxx
@@ -20,6 +20,7 @@
 #include <vcl/svapp.hxx>
 #include <vcl/msgbox.hxx>
 
+#include <osl/process.h>
 #include <tools/stream.hxx>
 #include <rtl/bootstrap.hxx>
 #include <unotools/configmgr.hxx>
@@ -35,6 +36,13 @@
 #include "comphelper/anytostring.hxx"
 #include "cppuhelper/exc_hlp.hxx"
 #include "cppuhelper/bootstrap.hxx"
+#include <com/sun/star/graphic/XPrimitive2DRenderer.hpp>
+#include <basegfx/numeric/ftools.hxx>
+#include <vcl/canvastools.hxx>
+#include <com/sun/star/geometry/RealRectangle2D.hpp>
+#include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
 
 #include <sfx2/sfxuno.hxx>
 #include <sfx2/sfxcommands.h>
@@ -183,6 +191,91 @@
     aCancelButton.GrabFocus();
 }
 
+static bool loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth )
+{
+    // Load from disk
+    // ---------------------------------------------------------------------
+    rtl::OUString aBaseName = ( rtl::OUString("/") +
+                                rtl::OUString::createFromAscii( pName ) );
+    rtl::OUString aSvg( ".svg" );
+
+    rtl_Locale *pLoc = NULL;
+    osl_getProcessLocale (&pLoc);
+    LanguageTag aLanguageTag( *pLoc);
+
+    rtl::OUString aName = aBaseName + aSvg;
+    rtl::OUString aLocaleName = ( aBaseName + rtl::OUString("-") +
+                                  aLanguageTag.getBcp47() +
+                                  aSvg );
+    rtl::OUString uri = rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ) + aBaseName+aSvg;
+    rtl::Bootstrap::expandMacros( uri );
+    INetURLObject aObj( uri );
+    SvgData aSvgData(aObj.PathToFileName());
+
+    // transform into [0,0,width,width*aspect] std dimensions
+    // ---------------------------------------------------------------------
+    basegfx::B2DRange aRange(aSvgData.getRange());
+    const double fAspectRatio(aRange.getWidth()/aRange.getHeight());
+    basegfx::B2DHomMatrix aTransform(
+        basegfx::tools::createTranslateB2DHomMatrix(
+            -aRange.getMinX(),
+            -aRange.getMinY()));
+    aTransform.scale(
+        nWidth / aRange.getWidth(),
+        nWidth / fAspectRatio / aRange.getHeight());
+    const drawinglayer::primitive2d::Primitive2DReference xTransformRef(
+        new drawinglayer::primitive2d::TransformPrimitive2D(
+            aTransform,
+            aSvgData.getPrimitive2DSequence()));
+
+    // UNO dance to render from drawinglayer
+    // ---------------------------------------------------------------------
+    uno::Reference< lang::XMultiServiceFactory > xFactory(::comphelper::getProcessServiceFactory());
+    const rtl::OUString aServiceName("com.sun.star.graphic.Primitive2DTools");
+
+    try
+    {
+        const uno::Reference< graphic::XPrimitive2DRenderer > xPrimitive2DRenderer(
+            xFactory->createInstance(aServiceName),
+            uno::UNO_QUERY_THROW);
+
+        if(xPrimitive2DRenderer.is())
+        {
+            // cancel out rasterize's mm2pixel conversion
+            const double fFakeDPI=1000.0/2.54;
+
+            geometry::RealRectangle2D aRealRect(
+                0, 0,
+                nWidth, nWidth / fAspectRatio);
+
+            const uno::Reference< rendering::XBitmap > xBitmap(
+                xPrimitive2DRenderer->rasterize(
+                    drawinglayer::primitive2d::Primitive2DSequence(&xTransformRef, 1),
+                    uno::Sequence< beans::PropertyValue >(),
+                    fFakeDPI,
+                    fFakeDPI,
+                    aRealRect,
+                    500000));
+
+            if(xBitmap.is())
+            {
+                const uno::Reference< rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW);
+
+                if(xIntBmp.is())
+                {
+                    rBitmap = vcl::unotools::bitmapExFromXBitmap(xIntBmp);
+                    return true;
+                }
+            }
+        }
+    }
+    catch(const uno::Exception&)
+    {
+        OSL_ENSURE(sal_False, "Got no graphic::XPrimitive2DRenderer (!)" );
+    }
+    return false;
+}
+
 void AboutDialog::LayoutControls()
 {
     // Get the size of the screen
@@ -207,16 +300,14 @@
     Size aLogoSize( aIdealTextWidth, aIdealTextWidth / 20 );
     Point aLogoPos( 0, 0 );
 
-    if( Application::LoadBrandSVG("flat_logo", aLogoBitmap) &&
+    // load svg logo, specify desired width, scale height isotrophically
+    if( loadBrandSvg("flat_logo",
+                     aLogoBitmap,
+                     aDialogSize.Width()) &&
         !aLogoBitmap.IsEmpty() )
     {
-        const float aLogoWidthHeightRatio = (float)aLogoBitmap.GetSizePixel().Width() / (float)aLogoBitmap.GetSizePixel().Height();
-        aLogoSize.Width() = aDialogSize.Width() ;
-        aLogoSize.Height() = aLogoSize.Width() / aLogoWidthHeightRatio ;
-        aLogoBitmap.Scale(aLogoSize);
-
         aLogoImage.SetImage( Image( aLogoBitmap ) );
-        aLogoImage.SetPosSizePixel( aLogoPos, aLogoSize );
+        aLogoImage.SetPosSizePixel( aLogoPos, aLogoBitmap.GetSizePixel() );
         aLogoImage.Show();
     }
     else
@@ -274,22 +365,10 @@
 
 
     // Layout background image
-    if ( !(Application::GetSettings().GetStyleSettings().GetHighContrastMode()) &&
-          Application::LoadBrandSVG("shell/about", aBackgroundBitmap) &&
-          !aBackgroundBitmap.IsEmpty() )
-    {
-        const float aBackgroundWidthHeightRatio = (float)aBackgroundBitmap.GetSizePixel().Width() /
-            (float)aBackgroundBitmap.GetSizePixel().Height();
-        Size aBackgroundSize (aDialogSize.Width(), aDialogSize.Width() / aBackgroundWidthHeightRatio );
-
-        if ( aBackgroundSize.Height() < aDialogSize.Height())
-        {
-            aBackgroundSize.Width() = aDialogSize.Height() * aBackgroundWidthHeightRatio ;
-            aBackgroundSize.Height() = aDialogSize.Height();
-        }
-        aBackgroundBitmap.Scale(aBackgroundSize);
-    }
-
+    if ( !(Application::GetSettings().GetStyleSettings().GetHighContrastMode()) )
+        loadBrandSvg("shell/about",
+                     aBackgroundBitmap,
+                     aDialogSize.Width());
     SetOutputSizePixel( aDialogSize );
 
 }

-- 
To view, visit https://gerrit.libreoffice.org/2183
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I58e011231f2b81b913a6b02dd973385ef5664379
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Thorsten Behrens <tbehrens at suse.com>


More information about the LibreOffice mailing list