84b3833
From d83bc4d9921afd31f1afddc52f39951bb686e60a Mon Sep 17 00:00:00 2001
84b3833
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
84b3833
Date: Thu, 10 Mar 2011 15:59:44 +0000
84b3833
Subject: [PATCH] Related: rhbz#680460 reorganize this to make it inheritable
84b3833
84b3833
---
84b3833
 vcl/inc/vcl/fontmanager.hxx               |    2 +-
84b3833
 vcl/inc/vcl/glyphcache.hxx                |    5 +--
84b3833
 vcl/inc/vcl/impfont.hxx                   |   25 ++++++++++-----------
84b3833
 vcl/source/glyphs/gcach_ftyp.cxx          |   18 ++++++++++-----
84b3833
 vcl/source/glyphs/gcach_ftyp.hxx          |    4 ++-
84b3833
 vcl/source/glyphs/glyphcache.cxx          |    3 +-
84b3833
 vcl/unx/source/fontmanager/fontconfig.cxx |   32 ++++++++++++++--------------
84b3833
 vcl/unx/source/gdi/salgdi3.cxx            |   17 ++++++---------
84b3833
 8 files changed, 55 insertions(+), 51 deletions(-)
84b3833
84b3833
diff --git a/vcl/inc/vcl/fontmanager.hxx b/vcl/inc/vcl/fontmanager.hxx
84b3833
index 6c76eea..103cd92 100644
84b3833
--- a/vcl/inc/vcl/fontmanager.hxx
84b3833
+++ b/vcl/inc/vcl/fontmanager.hxx
84b3833
@@ -733,7 +733,7 @@ public:
84b3833
     false else
84b3833
      */
84b3833
     bool matchFont( FastPrintFontInfo& rInfo, const com::sun::star::lang::Locale& rLocale );
84b3833
-    bool getFontOptions( const FastPrintFontInfo&, int nSize, void (*subcallback)(void*), ImplFontOptions& rResult ) const;
84b3833
+    ImplFontOptions* getFontOptions( const FastPrintFontInfo&, int nSize, void (*subcallback)(void*)) const;
84b3833
 
84b3833
     rtl::OUString Substitute( const rtl::OUString& rFontName, rtl::OUString& rMissingCodes,
84b3833
         const rtl::OString& rLangAttrib, italic::type& rItalic, weight::type& rWeight,
84b3833
diff --git a/vcl/inc/vcl/glyphcache.hxx b/vcl/inc/vcl/glyphcache.hxx
84b3833
index 8714697..1c03759 100644
84b3833
--- a/vcl/inc/vcl/glyphcache.hxx
84b3833
+++ b/vcl/inc/vcl/glyphcache.hxx
84b3833
@@ -187,7 +187,7 @@ public:
84b3833
     virtual bool                TestFont() const            { return true; }
84b3833
     virtual void*               GetFtFace() const { return 0; }
84b3833
     virtual int                 GetLoadFlags() const { return 0; }
84b3833
-    virtual void                SetFontOptions( const ImplFontOptions&) {}
84b3833
+    virtual void                SetFontOptions( const ImplFontOptions*) {}
84b3833
     virtual bool                NeedsArtificialBold() const { return false; }
84b3833
     virtual bool                NeedsArtificialItalic() const { return false; }
84b3833
 
84b3833
@@ -266,9 +266,8 @@ class VCL_DLLPUBLIC ImplServerFontEntry : public ImplFontEntry
84b3833
 {
84b3833
 private:
84b3833
     ServerFont*    mpServerFont;
84b3833
-    ImplFontOptions maFontOptions;
84b3833
+    ImplFontOptions* mpFontOptions;
84b3833
     bool           mbGotFontOptions;
84b3833
-    bool           mbValidFontOptions;
84b3833
 
84b3833
 public:
84b3833
                    ImplServerFontEntry( ImplFontSelectData& );
84b3833
diff --git a/vcl/inc/vcl/impfont.hxx b/vcl/inc/vcl/impfont.hxx
84b3833
index b7a0368..fa8a837 100644
84b3833
--- a/vcl/inc/vcl/impfont.hxx
84b3833
+++ b/vcl/inc/vcl/impfont.hxx
84b3833
@@ -135,7 +135,7 @@ public:
84b3833
 };
84b3833
 
84b3833
 // ------------------
84b3833
-// - ImplFontHints -
84b3833
+// - ImplFontOptions -
84b3833
 // ------------------
84b3833
 
84b3833
 class ImplFontOptions
84b3833
@@ -154,19 +154,18 @@ public:
84b3833
         meHinting(HINTING_DONTKNOW), 
84b3833
         meHintStyle(HINT_SLIGHT)
84b3833
     {}
84b3833
-    ImplFontOptions( FontEmbeddedBitmap eEmbeddedBitmap, FontAntiAlias eAntiAlias, 
84b3833
-        FontAutoHint eAutoHint, FontHinting eHinting, FontHintStyle eHintStyle) :
84b3833
-        meEmbeddedBitmap(eEmbeddedBitmap), 
84b3833
-        meAntiAlias(eAntiAlias), 
84b3833
-        meAutoHint(eAutoHint), 
84b3833
-        meHinting(eHinting), 
84b3833
-        meHintStyle(eHintStyle)
84b3833
+    virtual ~ImplFontOptions()
84b3833
     {}
84b3833
-    FontAutoHint GetUseAutoHint() const { return meAutoHint; }
84b3833
-    FontHintStyle GetHintStyle() const { return meHintStyle; }
84b3833
-    bool DontUseEmbeddedBitmaps() const { return meEmbeddedBitmap == EMBEDDEDBITMAP_FALSE; }
84b3833
-    bool DontUseAntiAlias() const { return meAntiAlias == ANTIALIAS_FALSE; }
84b3833
-    bool DontUseHinting() const { return (meHinting == HINTING_FALSE) || (GetHintStyle() == HINT_NONE); }
84b3833
+    FontAutoHint GetUseAutoHint() const
84b3833
+        { return meAutoHint; }
84b3833
+    FontHintStyle GetHintStyle() const
84b3833
+        { return meHintStyle; }
84b3833
+    bool DontUseEmbeddedBitmaps() const
84b3833
+        { return meEmbeddedBitmap == EMBEDDEDBITMAP_FALSE; }
84b3833
+    bool DontUseAntiAlias() const
84b3833
+        { return meAntiAlias == ANTIALIAS_FALSE; }
84b3833
+    bool DontUseHinting() const
84b3833
+        { return (meHinting == HINTING_FALSE) || (GetHintStyle() == HINT_NONE); }
84b3833
 };
84b3833
 
84b3833
 // -------------------
84b3833
diff --git a/vcl/source/glyphs/gcach_ftyp.cxx b/vcl/source/glyphs/gcach_ftyp.cxx
84b3833
index 2db53a5..2236bad 100644
84b3833
--- a/vcl/source/glyphs/gcach_ftyp.cxx
84b3833
+++ b/vcl/source/glyphs/gcach_ftyp.cxx
84b3833
@@ -768,6 +768,7 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, FtFontIn
84b3833
     mpFontInfo( pFI ),
84b3833
     maFaceFT( NULL ),
84b3833
     maSizeFT( NULL ),
84b3833
+    mpFontOptions( NULL ),
84b3833
     mbFaceOk( false ),
84b3833
     maRecodeConverter( NULL ),
84b3833
     mpLayoutEngine( NULL )
84b3833
@@ -913,9 +914,14 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, FtFontIn
84b3833
         mnLoadFlags |= FT_LOAD_NO_BITMAP;
84b3833
 }
84b3833
 
84b3833
-void FreetypeServerFont::SetFontOptions( const ImplFontOptions& rFontOptions)
84b3833
+void FreetypeServerFont::SetFontOptions( const ImplFontOptions* pFontOptions)
84b3833
 {
84b3833
-    FontAutoHint eHint = rFontOptions.GetUseAutoHint();
84b3833
+    mpFontOptions = pFontOptions;
84b3833
+
84b3833
+    if (!mpFontOptions)
84b3833
+        return;
84b3833
+
84b3833
+    FontAutoHint eHint = mpFontOptions->GetUseAutoHint();
84b3833
     if( eHint == AUTOHINT_DONTKNOW )
84b3833
         eHint = mbUseGamma ? AUTOHINT_TRUE : AUTOHINT_FALSE;
84b3833
 
84b3833
@@ -926,11 +932,11 @@ void FreetypeServerFont::SetFontOptions( const ImplFontOptions& rFontOptions)
84b3833
         mnLoadFlags |= FT_LOAD_NO_HINTING;
84b3833
     mnLoadFlags |= FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH; //#88334#
84b3833
 
84b3833
-    if( rFontOptions.DontUseAntiAlias() )
84b3833
+    if( mpFontOptions->DontUseAntiAlias() )
84b3833
       mnPrioAntiAlias = 0;
84b3833
-    if( rFontOptions.DontUseEmbeddedBitmaps() )
84b3833
+    if( mpFontOptions->DontUseEmbeddedBitmaps() )
84b3833
       mnPrioEmbedded = 0;
84b3833
-    if( rFontOptions.DontUseHinting() )
84b3833
+    if( mpFontOptions->DontUseHinting() )
84b3833
       mnPrioAutoHint = 0;
84b3833
 
84b3833
 #if (FTVERSION >= 2005) || defined(TT_CONFIG_OPTION_BYTECODE_INTERPRETER)
84b3833
@@ -942,7 +948,7 @@ void FreetypeServerFont::SetFontOptions( const ImplFontOptions& rFontOptions)
84b3833
     if( !(mnLoadFlags & FT_LOAD_NO_HINTING) && (nFTVERSION >= 2103))
84b3833
     {
84b3833
        mnLoadFlags |= FT_LOAD_TARGET_NORMAL;
84b3833
-       switch( rFontOptions.GetHintStyle() )
84b3833
+       switch( mpFontOptions->GetHintStyle() )
84b3833
        {
84b3833
            case HINT_NONE:
84b3833
                 mnLoadFlags |= FT_LOAD_NO_HINTING;
84b3833
diff --git a/vcl/source/glyphs/gcach_ftyp.hxx b/vcl/source/glyphs/gcach_ftyp.hxx
84b3833
index cf2284c..6069388 100644
84b3833
--- a/vcl/source/glyphs/gcach_ftyp.hxx
84b3833
+++ b/vcl/source/glyphs/gcach_ftyp.hxx
84b3833
@@ -186,7 +186,7 @@ public:
84b3833
     virtual int                 GetFontFaceNum() const { return mpFontInfo->GetFaceNum(); }
84b3833
     virtual bool                TestFont() const;
84b3833
     virtual void*               GetFtFace() const;
84b3833
-    virtual void                SetFontOptions( const ImplFontOptions&);
84b3833
+    virtual void                SetFontOptions( const ImplFontOptions*);
84b3833
     virtual int                 GetLoadFlags() const { return (mnLoadFlags & ~FT_LOAD_IGNORE_TRANSFORM); }
84b3833
     virtual bool                NeedsArtificialBold() const { return mbArtBold; }
84b3833
     virtual bool                NeedsArtificialItalic() const { return mbArtItalic; }
84b3833
@@ -233,6 +233,8 @@ private:
84b3833
     FT_FaceRec_*                maFaceFT;
84b3833
     FT_SizeRec_*                maSizeFT;
84b3833
 
84b3833
+    const ImplFontOptions*      mpFontOptions;
84b3833
+
84b3833
     bool                        mbFaceOk;
84b3833
     bool			mbArtItalic;
84b3833
     bool			mbArtBold;
84b3833
diff --git a/vcl/source/glyphs/glyphcache.cxx b/vcl/source/glyphs/glyphcache.cxx
84b3833
index 8ad5a87..9668a50 100644
84b3833
--- a/vcl/source/glyphs/glyphcache.cxx
84b3833
+++ b/vcl/source/glyphs/glyphcache.cxx
84b3833
@@ -522,8 +522,8 @@ bool ServerFont::IsGlyphInvisible( int nGlyphIndex )
84b3833
 ImplServerFontEntry::ImplServerFontEntry( ImplFontSelectData& rFSD )
84b3833
 :   ImplFontEntry( rFSD )
84b3833
 ,   mpServerFont( NULL )
84b3833
+,   mpFontOptions( NULL )
84b3833
 ,   mbGotFontOptions( false )
84b3833
-,   mbValidFontOptions( false )
84b3833
 {}
84b3833
 
84b3833
 // -----------------------------------------------------------------------
84b3833
@@ -531,6 +531,7 @@ ImplServerFontEntry::ImplServerFontEntry( ImplFontSelectData& rFSD )
84b3833
 ImplServerFontEntry::~ImplServerFontEntry()
84b3833
 {
84b3833
     // TODO: remove the ServerFont here instead of in the GlyphCache
84b3833
+    delete mpFontOptions;
84b3833
 }
84b3833
 
84b3833
 // =======================================================================
84b3833
diff --git a/vcl/unx/source/fontmanager/fontconfig.cxx b/vcl/unx/source/fontmanager/fontconfig.cxx
84b3833
index 0dd5260..3c2f636 100644
84b3833
--- a/vcl/unx/source/fontmanager/fontconfig.cxx
84b3833
+++ b/vcl/unx/source/fontmanager/fontconfig.cxx
84b3833
@@ -1093,17 +1093,17 @@ rtl::OUString PrintFontManager::Substitute(const rtl::OUString& rFontName,
84b3833
     return aName;
84b3833
 }
84b3833
 
84b3833
-bool PrintFontManager::getFontOptions( 
84b3833
-    const FastPrintFontInfo& rInfo, int nSize, void (*subcallback)(void*),
84b3833
-    ImplFontOptions& rOptions) const
84b3833
+ImplFontOptions* PrintFontManager::getFontOptions(
84b3833
+    const FastPrintFontInfo& rInfo, int nSize, void (*subcallback)(void*)) const
84b3833
 {
84b3833
 #ifndef ENABLE_FONTCONFIG
84b3833
-    return false;
84b3833
+    return NULL;
84b3833
 #else // ENABLE_FONTCONFIG
84b3833
     FontCfgWrapper& rWrapper = FontCfgWrapper::get();
84b3833
     if( ! rWrapper.isValid() )
84b3833
-        return false;
84b3833
+        return NULL;
84b3833
 
84b3833
+    ImplFontOptions *pOptions = NULL;
84b3833
     FcConfig* pConfig = rWrapper.FcConfigGetCurrent();
84b3833
     FcPattern* pPattern = rWrapper.FcPatternCreate();
84b3833
 
84b3833
@@ -1144,22 +1144,24 @@ bool PrintFontManager::getFontOptions(
84b3833
                 FC_HINTING, 0, &hinting);
84b3833
             /*FcResult eHintStyle =*/ rWrapper.FcPatternGetInteger( pSet->fonts[0],
84b3833
                 FC_HINT_STYLE, 0, &hintstyle);
84b3833
+
84b3833
+            pOptions = new ImplFontOptions;
84b3833
          
84b3833
             if( eEmbeddedBitmap == FcResultMatch )
84b3833
-                rOptions.meEmbeddedBitmap = embitmap ? EMBEDDEDBITMAP_TRUE : EMBEDDEDBITMAP_FALSE;
84b3833
+                pOptions->meEmbeddedBitmap = embitmap ? EMBEDDEDBITMAP_TRUE : EMBEDDEDBITMAP_FALSE;
84b3833
             if( eAntialias == FcResultMatch )
84b3833
-                rOptions.meAntiAlias = antialias ? ANTIALIAS_TRUE : ANTIALIAS_FALSE;
84b3833
+                pOptions->meAntiAlias = antialias ? ANTIALIAS_TRUE : ANTIALIAS_FALSE;
84b3833
             if( eAutoHint == FcResultMatch )
84b3833
-                rOptions.meAutoHint = autohint ? AUTOHINT_TRUE : AUTOHINT_FALSE;
84b3833
+                pOptions->meAutoHint = autohint ? AUTOHINT_TRUE : AUTOHINT_FALSE;
84b3833
             if( eHinting == FcResultMatch )
84b3833
-                rOptions.meHinting = hinting ? HINTING_TRUE : HINTING_FALSE;
84b3833
+                pOptions->meHinting = hinting ? HINTING_TRUE : HINTING_FALSE;
84b3833
             switch (hintstyle)
84b3833
             {
84b3833
-                case FC_HINT_NONE:   rOptions.meHintStyle = HINT_NONE; break;
84b3833
-                case FC_HINT_SLIGHT: rOptions.meHintStyle = HINT_SLIGHT; break;
84b3833
-                case FC_HINT_MEDIUM: rOptions.meHintStyle = HINT_MEDIUM; break;
84b3833
+                case FC_HINT_NONE:   pOptions->meHintStyle = HINT_NONE; break;
84b3833
+                case FC_HINT_SLIGHT: pOptions->meHintStyle = HINT_SLIGHT; break;
84b3833
+                case FC_HINT_MEDIUM: pOptions->meHintStyle = HINT_MEDIUM; break;
84b3833
                 default: // fall through
84b3833
-                case FC_HINT_FULL:   rOptions.meHintStyle = HINT_FULL; break;
84b3833
+                case FC_HINT_FULL:   pOptions->meHintStyle = HINT_FULL; break;
84b3833
             }
84b3833
         }
84b3833
         // info: destroying the pSet destroys pResult implicitly
84b3833
@@ -1170,9 +1172,7 @@ bool PrintFontManager::getFontOptions(
84b3833
     // cleanup
84b3833
     rWrapper.FcPatternDestroy( pPattern );
84b3833
 
84b3833
-    // TODO: return true only if non-default font options are set
84b3833
-    const bool bOK = (pResult != NULL);
84b3833
-    return bOK;
84b3833
+    return pOptions;
84b3833
 #endif
84b3833
 }
84b3833
 
84b3833
diff --git a/vcl/unx/source/gdi/salgdi3.cxx b/vcl/unx/source/gdi/salgdi3.cxx
84b3833
index 9834028..6de93fe 100644
84b3833
--- a/vcl/unx/source/gdi/salgdi3.cxx
84b3833
+++ b/vcl/unx/source/gdi/salgdi3.cxx
84b3833
@@ -632,22 +632,21 @@ bool X11SalGraphics::setFont( const ImplFontSelectData *pEntry, int nFallbackLev
84b3833
     return false;
84b3833
 }
84b3833
 
84b3833
+ImplFontOptions* GetFCFontOptions( const ImplFontAttributes& rFontAttributes, int nSize);
84b3833
+
84b3833
 void ImplServerFontEntry::HandleFontOptions( void )
84b3833
 {
84b3833
-    bool GetFCFontOptions( const ImplFontAttributes&, int nSize, ImplFontOptions& );
84b3833
-
84b3833
     if( !mpServerFont )
84b3833
         return;
84b3833
     if( !mbGotFontOptions )
84b3833
     {
84b3833
         // get and cache the font options
84b3833
         mbGotFontOptions = true;
84b3833
-        mbValidFontOptions = GetFCFontOptions( *maFontSelData.mpFontData,
84b3833
-            maFontSelData.mnHeight, maFontOptions );
84b3833
+        mpFontOptions = GetFCFontOptions( *maFontSelData.mpFontData,
84b3833
+            maFontSelData.mnHeight );
84b3833
     }
84b3833
     // apply the font options
84b3833
-    if( mbValidFontOptions )
84b3833
-        mpServerFont->SetFontOptions( maFontOptions );
84b3833
+    mpServerFont->SetFontOptions( mpFontOptions );
84b3833
 }
84b3833
 
84b3833
 //--------------------------------------------------------------------------
84b3833
@@ -1636,8 +1635,7 @@ void cairosubcallback( void* pPattern )
84b3833
     rCairo.ft_font_options_substitute( pFontOptions, pPattern );
84b3833
 }
84b3833
 
84b3833
-bool GetFCFontOptions( const ImplFontAttributes& rFontAttributes, int nSize,
84b3833
-    ImplFontOptions& rFontOptions)
84b3833
+ImplFontOptions* GetFCFontOptions( const ImplFontAttributes& rFontAttributes, int nSize)
84b3833
 {
84b3833
     // TODO: get rid of these insane enum-conversions
84b3833
     // e.g. by using the classic vclenum values inside VCL
84b3833
@@ -1734,8 +1732,7 @@ bool GetFCFontOptions( const ImplFontAttributes& rFontAttributes, int nSize,
84b3833
     }
84b3833
 
84b3833
     const psp::PrintFontManager& rPFM = psp::PrintFontManager::get();
84b3833
-    bool bOK = rPFM.getFontOptions( aInfo, nSize, cairosubcallback, rFontOptions);
84b3833
-    return bOK;
84b3833
+    return rPFM.getFontOptions(aInfo, nSize, cairosubcallback);
84b3833
 }
84b3833
 
84b3833
 // ----------------------------------------------------------------------------
84b3833
-- 
84b3833
1.7.4.1
84b3833