include/vcl/outdev.hxx         |    2 -
 include/vcl/print.hxx          |    1 
 vcl/source/gdi/print.cxx       |   15 -------
 vcl/source/outdev/font.cxx     |   80 ++++++++++++++---------------------------
 vcl/source/outdev/text.cxx     |   29 ++------------
 vcl/source/outdev/textline.cxx |   11 +----
 6 files changed, 36 insertions(+), 102 deletions(-)

New commits:
commit e5a7ee832b4385fa83a914f4d7d81ed860da0667
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Mon Oct 22 21:00:30 2018 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Thu Oct 25 17:39:44 2018 +0200

    Return bool from InitFont and try to init the font
    
    InitFont() is always called after ImplNewFont(). Calling
    InitFont() without a call to ImplNewFont() doesn't make much
    sense.
    
    There are some places which don't need to set the SalGraphics
    font, but these are fine with calling ImplNewFont() as is.
    
    It now looks like Printer' and OutputDevice' InitFont() do the
    same, after commit c766a05ae035 ("Antialias drawing is part of
    the font selection") moved Antialias handling into the common
    ImplNewFont() function.
    
    Change-Id: I77b9a5b6dbed186a2b0868537930d6bf3fccd9d5
    Reviewed-on: https://gerrit.libreoffice.org/62202
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index fe7507213256..8970fe0e3788 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -1292,7 +1292,7 @@ protected:
     SAL_DLLPRIVATE long GetEmphasisAscent() const { return mnEmphasisAscent; }
     SAL_DLLPRIVATE long GetEmphasisDescent() const { return mnEmphasisDescent; 
}
 
-    virtual void                InitFont() const;
+    SAL_DLLPRIVATE bool InitFont() const;
     virtual void                SetFontOrientation( LogicalFontInstance* const 
pFontInstance ) const;
     virtual long                GetFontExtLeading() const;
 
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index ae3c773cf934..631c38a5ab42 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -261,7 +261,6 @@ protected:
     virtual void                EmulateDrawTransparent( const 
tools::PolyPolygon& rPolyPoly,
                                     sal_uInt16 nTransparencePercent ) override;
 
-    virtual void                InitFont() const override;
     virtual void                SetFontOrientation( LogicalFontInstance* const 
pFontInstance ) const override;
 
 public:
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 2c9a58dec73d..06774a99cbcf 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -1677,21 +1677,6 @@ void Printer::ClipAndDrawGradientMetafile ( const 
Gradient &rGradient, const too
     Pop();
 }
 
-void Printer::InitFont() const
-{
-    DBG_TESTSOLARMUTEX();
-
-    if (!mpFontInstance)
-        return;
-
-    if ( mbInitFont )
-    {
-        // select font in the device layers
-        mpGraphics->SetFont(mpFontInstance.get(), 0);
-        mbInitFont = false;
-    }
-}
-
 void Printer::SetFontOrientation( LogicalFontInstance* const pFontEntry ) const
 {
     pFontEntry->mnOrientation = pFontEntry->mxFontMetric->GetOrientation();
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 7868b9ba0b3d..b11d97b0deb8 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -167,27 +167,18 @@ bool OutputDevice::AddTempDevFont( const OUString& 
rFileURL, const OUString& rFo
 
 bool OutputDevice::GetFontFeatures(std::vector<vcl::font::Feature>& 
rFontFeatures) const
 {
-    if (mbNewFont)
-        ImplNewFont();
-
-    if (mbInitFont)
-        InitFont();
-
-    if (!mpFontInstance)
+    if (!ImplNewFont())
         return false;
 
     LogicalFontInstance* pFontInstance = mpFontInstance.get();
-
     if (!pFontInstance)
         return false;
 
     hb_font_t* pHbFont = pFontInstance->GetHbFont();
-
     if (!pHbFont)
         return false;
 
     hb_face_t* pHbFace = hb_font_get_face(pHbFont);
-
     if (!pHbFace)
         return false;
 
@@ -202,7 +193,7 @@ bool 
OutputDevice::GetFontFeatures(std::vector<vcl::font::Feature>& rFontFeature
 FontMetric OutputDevice::GetFontMetric() const
 {
     FontMetric aMetric;
-    if( mbNewFont && !ImplNewFont() )
+    if (!ImplNewFont())
         return aMetric;
 
     LogicalFontInstance* pFontInstance = mpFontInstance.get();
@@ -261,15 +252,7 @@ FontMetric OutputDevice::GetFontMetric( const vcl::Font& 
rFont ) const
 
 bool OutputDevice::GetFontCharMap( FontCharMapRef& rxFontCharMap ) const
 {
-    // we need a graphics
-    if( !mpGraphics && !AcquireGraphics() )
-        return false;
-
-    if( mbNewFont )
-        ImplNewFont();
-    if( mbInitFont )
-        InitFont();
-    if( !mpFontInstance )
+    if (!InitFont())
         return false;
 
     FontCharMapRef xFontCharMap ( mpGraphics->GetFontCharMap() );
@@ -286,17 +269,8 @@ bool OutputDevice::GetFontCharMap( FontCharMapRef& 
rxFontCharMap ) const
 
 bool OutputDevice::GetFontCapabilities( vcl::FontCapabilities& 
rFontCapabilities ) const
 {
-    // we need a graphics
-    if( !mpGraphics && !AcquireGraphics() )
-        return false;
-
-    if( mbNewFont )
-        ImplNewFont();
-    if( mbInitFont )
-        InitFont();
-    if( !mpFontInstance )
+    if (!InitFont())
         return false;
-
     return mpGraphics->GetFontCapabilities(rFontCapabilities);
 }
 
@@ -976,23 +950,30 @@ void OutputDevice::ImplInitFontList() const
     }
 }
 
-void OutputDevice::InitFont() const
+bool OutputDevice::InitFont() const
 {
     DBG_TESTSOLARMUTEX();
 
+    if (!ImplNewFont())
+        return false;
     if (!mpFontInstance)
-        return;
-    if (!mbInitFont)
-        return;
+        return false;
+    if (!mpGraphics)
+    {
+        if (!AcquireGraphics())
+            return false;
+    }
+    else if (!mbInitFont)
+        return true;
 
     mpGraphics->SetFont(mpFontInstance.get(), 0);
     mbInitFont = false;
+    return true;
 }
 
 const LogicalFontInstance* OutputDevice::GetFontInstance() const
 {
-    if (ImplNewFont())
-        InitFont();
+    InitFont();
     return mpFontInstance.get();
 }
 
@@ -1018,7 +999,7 @@ bool OutputDevice::ImplNewFont() const
         SAL_WARN("vcl.gdi", "OutputDevice::ImplNewFont(): no Graphics, no 
Font");
         return false;
     }
-    SalGraphics* pGraphics = mpGraphics;
+
     ImplInitFontList();
 
     // convert to pixel height
@@ -1068,26 +1049,21 @@ bool OutputDevice::ImplNewFont() const
         mbInitFont = true;
 
     // select font when it has not been initialized yet
-    if ( !pFontInstance->mbInit )
+    if (!pFontInstance->mbInit && InitFont())
     {
-        InitFont();
-
         // get metric data from device layers
-        if ( pGraphics )
-        {
-            pFontInstance->mbInit = true;
+        pFontInstance->mbInit = true;
 
-            pFontInstance->mxFontMetric->SetOrientation( 
sal::static_int_cast<short>(mpFontInstance->GetFontSelectPattern().mnOrientation)
 );
-            pGraphics->GetFontMetric( pFontInstance->mxFontMetric, 0 );
+        pFontInstance->mxFontMetric->SetOrientation( 
sal::static_int_cast<short>(mpFontInstance->GetFontSelectPattern().mnOrientation)
 );
+        mpGraphics->GetFontMetric( pFontInstance->mxFontMetric, 0 );
 
-            pFontInstance->mxFontMetric->ImplInitTextLineSize( this );
-            pFontInstance->mxFontMetric->ImplInitAboveTextLineSize();
-            pFontInstance->mxFontMetric->ImplInitFlags( this );
+        pFontInstance->mxFontMetric->ImplInitTextLineSize( this );
+        pFontInstance->mxFontMetric->ImplInitAboveTextLineSize();
+        pFontInstance->mxFontMetric->ImplInitFlags( this );
 
-            pFontInstance->mnLineHeight = 
pFontInstance->mxFontMetric->GetAscent() + 
pFontInstance->mxFontMetric->GetDescent();
+        pFontInstance->mnLineHeight = pFontInstance->mxFontMetric->GetAscent() 
+ pFontInstance->mxFontMetric->GetDescent();
 
-            SetFontOrientation( pFontInstance );
-        }
+        SetFontOrientation( pFontInstance );
     }
 
     // calculate EmphasisArea
@@ -1409,7 +1385,7 @@ std::unique_ptr<SalLayout> 
OutputDevice::ImplGlyphFallbackLayout( std::unique_pt
 
 long OutputDevice::GetMinKashida() const
 {
-    if( mbNewFont && !ImplNewFont() )
+    if (!ImplNewFont())
         return 0;
 
     return ImplDevicePixelToLogicWidth( 
mpFontInstance->mxFontMetric->GetMinKashida() );
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 8dfe957392b9..5df1082be6ac 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -896,13 +896,8 @@ long OutputDevice::GetTextWidth( const OUString& rStr, 
sal_Int32 nIndex, sal_Int
 
 long OutputDevice::GetTextHeight() const
 {
-
-    if( mbNewFont )
-        if( !ImplNewFont() )
-            return 0;
-    if( mbInitFont )
-        if( !ImplNewFont() )
-            return 0;
+    if (!InitFont())
+        return 0;
 
     long nHeight = mpFontInstance->mnLineHeight + mnEmphasisAscent + 
mnEmphasisDescent;
 
@@ -1252,17 +1247,8 @@ std::unique_ptr<SalLayout> 
OutputDevice::ImplLayout(const OUString& rOrigStr,
          vcl::TextLayoutCache const* pLayoutCache,
          const SalLayoutGlyphs* pGlyphs) const
 {
-    // we need a graphics
-    if( !mpGraphics )
-        if( !AcquireGraphics() )
-            return nullptr;
-
-    // initialize font if needed
-    if( mbNewFont )
-        if( !ImplNewFont() )
-            return nullptr;
-    if( mbInitFont )
-        InitFont();
+    if (!InitFont())
+        return nullptr;
 
     // check string index and length
     if( -1 == nLen || nMinIndex + nLen > rOrigStr.getLength() )
@@ -2411,12 +2397,7 @@ bool OutputDevice::GetTextOutlines( 
basegfx::B2DPolyPolygonVector& rVector,
                                         sal_Int32 nIndex, sal_Int32 nLen,
                                         sal_uLong nLayoutWidth, const long* 
pDXArray ) const
 {
-    // the fonts need to be initialized
-    if( mbNewFont )
-        ImplNewFont();
-    if( mbInitFont )
-        InitFont();
-    if( !mpFontInstance )
+    if (!InitFont())
         return false;
 
     bool bRet = false;
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index 550fc781f6d0..9b4f6be2a042 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -930,10 +930,6 @@ void OutputDevice::DrawTextLine( const Point& rPos, long 
nWidth,
     if ( !IsDeviceOutputNecessary() || ImplIsRecordLayout() )
         return;
 
-    // we need a graphics
-    if( !mpGraphics && !AcquireGraphics() )
-        return;
-
     if( mbInitClipRegion )
         InitClipRegion();
 
@@ -942,12 +938,9 @@ void OutputDevice::DrawTextLine( const Point& rPos, long 
nWidth,
 
     // initialize font if needed to get text offsets
     // TODO: only needed for mnTextOff!=(0,0)
-    if( mbNewFont && !ImplNewFont() )
+    if (!InitFont())
         return;
 
-    if( mbInitFont )
-        InitFont();
-
     Point aPos = ImplLogicToDevicePixel( rPos );
     DeviceCoordinate fWidth;
     fWidth = LogicWidthToDeviceCoordinate( nWidth );
@@ -975,7 +968,7 @@ void OutputDevice::DrawWaveLine( const Point& rStartPos, 
const Point& rEndPos )
     if ( mbOutputClipped )
         return;
 
-    if( mbNewFont && !ImplNewFont() )
+    if (!InitFont())
         return;
 
     Point   aStartPt = ImplLogicToDevicePixel( rStartPos );
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to