canvas/source/cairo/cairo_canvasfont.cxx        |   10 ++++++++++
 canvas/source/cairo/cairo_canvasfont.hxx        |    7 ++++++-
 canvas/source/cairo/cairo_canvashelper_text.cxx |    5 +++--
 3 files changed, 19 insertions(+), 3 deletions(-)

New commits:
commit 28c27a0623bc78a0590858f97d03b620985bc84c
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Wed Dec 14 21:39:36 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Sun Dec 18 16:04:49 2022 +0000

    loplugin:unocast (cairocanvas::CanvasFont)
    
    (See the upcoming commit introducing that loplugin:unocast on why such
    dynamic_casts from UNO types are dangerous.)
    
    Change-Id: I2d5c330bb542dc74ea572f1667a24be8107fb87c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144351
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/canvas/source/cairo/cairo_canvasfont.cxx 
b/canvas/source/cairo/cairo_canvasfont.cxx
index 36c1733ef62a..9c660a5c4c6e 100644
--- a/canvas/source/cairo/cairo_canvasfont.cxx
+++ b/canvas/source/cairo/cairo_canvasfont.cxx
@@ -21,6 +21,7 @@
 
 #include <basegfx/numeric/ftools.hxx>
 #include <com/sun/star/rendering/PanoseProportion.hpp>
+#include <comphelper/servicehelper.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <rtl/math.hxx>
@@ -147,6 +148,15 @@ namespace cairocanvas
         return { "com.sun.star.rendering.CanvasFont" };
     }
 
+    sal_Int64 CanvasFont::getSomething(css::uno::Sequence<sal_Int8> const & 
aIdentifier) {
+        return comphelper::getSomethingImpl(aIdentifier, this);
+    }
+
+    css::uno::Sequence<sal_Int8> const & CanvasFont::getUnoTunnelId() {
+        static comphelper::UnoIdInit const id;
+        return id.getSeq();
+    }
+
     vcl::Font const & CanvasFont::getVCLFont() const
     {
         return *maFont;
diff --git a/canvas/source/cairo/cairo_canvasfont.hxx 
b/canvas/source/cairo/cairo_canvasfont.hxx
index 0ebe9acd81ce..3bb03847c3ce 100644
--- a/canvas/source/cairo/cairo_canvasfont.hxx
+++ b/canvas/source/cairo/cairo_canvasfont.hxx
@@ -23,6 +23,7 @@
 #include <cppuhelper/basemutex.hxx>
 
 #include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/geometry/Matrix2D.hpp>
 #include <com/sun/star/rendering/FontRequest.hpp>
 #include <com/sun/star/rendering/XCanvasFont.hpp>
@@ -39,7 +40,8 @@
 namespace cairocanvas
 {
     typedef ::cppu::WeakComponentImplHelper< css::rendering::XCanvasFont,
-                                             css::lang::XServiceInfo > 
CanvasFont_Base;
+                                             css::lang::XServiceInfo,
+                                             css::lang::XUnoTunnel > 
CanvasFont_Base;
 
     class CanvasFont : public ::cppu::BaseMutex,
                        public CanvasFont_Base
@@ -70,6 +72,9 @@ namespace cairocanvas
         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName 
) override;
         virtual css::uno::Sequence< OUString > SAL_CALL 
getSupportedServiceNames() override;
 
+        sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & 
aIdentifier) override;
+        static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
+
         vcl::Font const & getVCLFont() const;
 
     private:
diff --git a/canvas/source/cairo/cairo_canvashelper_text.cxx 
b/canvas/source/cairo/cairo_canvashelper_text.cxx
index 6973607d4824..b982e069589a 100644
--- a/canvas/source/cairo/cairo_canvashelper_text.cxx
+++ b/canvas/source/cairo/cairo_canvashelper_text.cxx
@@ -24,6 +24,7 @@
 #include <rtl/math.hxx>
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <comphelper/diagnose_ex.hxx>
+#include <comphelper/servicehelper.hxx>
 #include <vcl/canvastools.hxx>
 #include <vcl/metric.hxx>
 #include <vcl/virdev.hxx>
@@ -172,7 +173,7 @@ namespace cairocanvas
     {
         setupOutDevState( rOutDev, pOwner, viewState, renderState );
 
-        CanvasFont* pFont = dynamic_cast< CanvasFont* >( xFont.get() );
+        CanvasFont* pFont = comphelper::getFromUnoTunnel< CanvasFont >( xFont 
);
 
         ENSURE_ARG_OR_THROW( pFont,
                          "CanvasHelper::setupTextOutput(): Font not compatible 
with this canvas" );
@@ -247,7 +248,7 @@ namespace cairocanvas
             // TODO(F2): alpha
             mpVirtualDevice->SetLayoutMode( nLayoutMode );
 
-            rtl::Reference pTextLayout( new TextLayout(text, textDirection, 0, 
CanvasFont::Reference(dynamic_cast< CanvasFont* >( xFont.get() )), 
mpSurfaceProvider) );
+            rtl::Reference pTextLayout( new TextLayout(text, textDirection, 0, 
CanvasFont::Reference(comphelper::getFromUnoTunnel< CanvasFont >( xFont )), 
mpSurfaceProvider) );
             pTextLayout->draw(*mpVirtualDevice, aOutpos, viewState, 
renderState);
         }
 

Reply via email to