[Libreoffice-commits] core.git: vcl/generic vcl/inc vcl/quartz vcl/source vcl/win

Chris Sherlock chris.sherlock79 at gmail.com
Fri Jan 1 10:52:00 PST 2016


 vcl/generic/glyphs/gcach_ftyp.cxx    |    2 +-
 vcl/generic/glyphs/gcach_ftyp.hxx    |    1 -
 vcl/generic/print/genpspgraphics.cxx |    3 +--
 vcl/inc/PhysicalFontFace.hxx         |   12 ++++--------
 vcl/quartz/salgdi.cxx                |    2 +-
 vcl/source/font/PhysicalFontFace.cxx |    3 +--
 vcl/source/gdi/pdffontcache.cxx      |    6 ++++--
 vcl/source/gdi/pdffontcache.hxx      |   14 ++++++++++----
 vcl/source/gdi/pdfwriter_impl.cxx    |   28 ++--------------------------
 vcl/source/gdi/pdfwriter_impl.hxx    |   19 ++++++++++++++++++-
 vcl/win/gdi/salgdi3.cxx              |    2 +-
 11 files changed, 43 insertions(+), 49 deletions(-)

New commits:
commit 264e6c04afaff96dda6cd510c1da90bb519a1f66
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date:   Fri Jan 1 17:52:50 2016 +1100

    vcl: remove poor-man's RTTI in PhysicalFontFace
    
    The *only* things relying on the in-built magic number are PDFFontCache
    and PDFWriterImpl. PDFWriterImpl::emitBuiltinFont has as its first
    parameter a const PhysicalFontFace*, but this is only called upon by
    PDFWriterImpl::emitFonts, which instantiates an ImplPdfBuiltinFontData
    object from a built-in font map... so basically it is always guaranteed
    to get a ImplPdfBuiltinFontData object. ImplPdfBuiltinFontData derives
    from PhysicalFontFace, so to prevent the need to check the class being
    used is a ImplPdfBuiltinFontData, just make emitBuiltinFont require as
    it's first parameter ImplPdfBuiltinFontData!
    
    Unfortunately, we can't get around RTTI completely, because
    PDFFontCache::FontIdentifier requires a way of distinguishing between
    two different PhysicalFontFaces...
    
    Change-Id: I74c8cd294580bbecd12dd2427ac405f97a7e7f7e
    Reviewed-on: https://gerrit.libreoffice.org/21030
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Chris Sherlock <chris.sherlock79 at gmail.com>

diff --git a/vcl/generic/glyphs/gcach_ftyp.cxx b/vcl/generic/glyphs/gcach_ftyp.cxx
index f5b4a0d..a570548 100644
--- a/vcl/generic/glyphs/gcach_ftyp.cxx
+++ b/vcl/generic/glyphs/gcach_ftyp.cxx
@@ -420,7 +420,7 @@ ServerFont* FreetypeManager::CreateFont( const FontSelectPattern& rFSD )
 }
 
 ImplFTSFontData::ImplFTSFontData( FtFontInfo* pFI, const ImplFontAttributes& rDFA )
-:   PhysicalFontFace( rDFA, IFTSFONT_MAGIC ),
+:   PhysicalFontFace( rDFA ),
     mpFtFontInfo( pFI )
 {
     SetBuiltInFontFlag( false );
diff --git a/vcl/generic/glyphs/gcach_ftyp.hxx b/vcl/generic/glyphs/gcach_ftyp.hxx
index 1fe995a..3277777 100644
--- a/vcl/generic/glyphs/gcach_ftyp.hxx
+++ b/vcl/generic/glyphs/gcach_ftyp.hxx
@@ -150,7 +150,6 @@ class ImplFTSFontData : public PhysicalFontFace
 {
 private:
     FtFontInfo*             mpFtFontInfo;
-    enum { IFTSFONT_MAGIC = 0x1F150A1C };
 
 public:
                             ImplFTSFontData( FtFontInfo*, const ImplFontAttributes& );
diff --git a/vcl/generic/print/genpspgraphics.cxx b/vcl/generic/print/genpspgraphics.cxx
index 207e414..f687ba28 100644
--- a/vcl/generic/print/genpspgraphics.cxx
+++ b/vcl/generic/print/genpspgraphics.cxx
@@ -542,7 +542,6 @@ void GenPspGraphics::invert(long,long,long,long,SalInvert)
 class ImplPspFontData : public PhysicalFontFace
 {
 private:
-    enum { PSPFD_MAGIC = 0xb5bf01f0 };
     sal_IntPtr              mnFontId;
 
 public:
@@ -553,7 +552,7 @@ public:
 };
 
 ImplPspFontData::ImplPspFontData( const psp::FastPrintFontInfo& rInfo )
-:   PhysicalFontFace( GenPspGraphics::Info2FontAttributes(rInfo), PSPFD_MAGIC ),
+:   PhysicalFontFace( GenPspGraphics::Info2FontAttributes(rInfo) ),
     mnFontId( rInfo.m_nID )
 {}
 
diff --git a/vcl/inc/PhysicalFontFace.hxx b/vcl/inc/PhysicalFontFace.hxx
index bb0b900..06a8fe2 100644
--- a/vcl/inc/PhysicalFontFace.hxx
+++ b/vcl/inc/PhysicalFontFace.hxx
@@ -66,33 +66,29 @@ public:
 class VCL_PLUGIN_PUBLIC PhysicalFontFace : public ImplFontAttributes
 {
 public:
+    virtual                ~PhysicalFontFace() {}
+
     // by using an PhysicalFontFace object as a factory for its corresponding
     // ImplFontEntry an ImplFontEntry can be extended to cache device and
     // font instance specific data
     virtual ImplFontEntry*  CreateFontInstance( FontSelectPattern& ) const = 0;
+    virtual PhysicalFontFace* Clone() const = 0;
 
     int                     GetHeight() const           { return mnHeight; }
     int                     GetWidth() const            { return mnWidth; }
     virtual sal_IntPtr      GetFontId() const = 0;
-    int                     GetFontMagic() const        { return mnMagic; }
     bool                    IsScalable() const          { return (mnHeight == 0); }
-    bool                    CheckMagic( int n ) const   { return (n == mnMagic); }
 
     bool                    IsBetterMatch( const FontSelectPattern&, FontMatchStatus& ) const;
     sal_Int32               CompareWithSize( const PhysicalFontFace& ) const;
     sal_Int32               CompareIgnoreSize( const PhysicalFontFace& ) const;
-    virtual                ~PhysicalFontFace() {}
-    virtual PhysicalFontFace* Clone() const = 0;
 
 protected:
-    explicit                PhysicalFontFace( const ImplFontAttributes&, int nMagic );
+    explicit                PhysicalFontFace( const ImplFontAttributes& );
     void                    SetBitmapSize( int nW, int nH ) { mnWidth=nW; mnHeight=nH; }
 
     long                    mnWidth;    // Width (in pixels)
     long                    mnHeight;   // Height (in pixels)
-
-private:
-    const int               mnMagic;    // poor man's RTTI
 };
 
 #endif // INCLUDED_VCL_INC_PHYSICALFONTFACE_HXX
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 0619b54..bfff1fd 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -64,7 +64,7 @@ CoreTextFontData::CoreTextFontData( const CoreTextFontData& rSrc )
 }
 
 CoreTextFontData::CoreTextFontData( const ImplFontAttributes& rDFA, sal_IntPtr nFontId )
-  : PhysicalFontFace( rDFA, 0 )
+  : PhysicalFontFace( rDFA )
   , mnFontId( nFontId )
   , mbOs2Read( false )
   , mbHasOs2Table( false )
diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx
index c7c7ee2..7bebc99 100644
--- a/vcl/source/font/PhysicalFontFace.cxx
+++ b/vcl/source/font/PhysicalFontFace.cxx
@@ -25,11 +25,10 @@
 
 #include "PhysicalFontFace.hxx"
 
-PhysicalFontFace::PhysicalFontFace( const ImplFontAttributes& rDFA, int nMagic )
+PhysicalFontFace::PhysicalFontFace( const ImplFontAttributes& rDFA )
     : ImplFontAttributes( rDFA )
     , mnWidth(0)
     , mnHeight(0)
-    , mnMagic( nMagic )
 {
     // StarSymbol is a unicode font, but it still deserves the symbol flag
     if( !IsSymbolFont() )
diff --git a/vcl/source/gdi/pdffontcache.cxx b/vcl/source/gdi/pdffontcache.cxx
index ccb131d..68ede0b 100644
--- a/vcl/source/gdi/pdffontcache.cxx
+++ b/vcl/source/gdi/pdffontcache.cxx
@@ -17,6 +17,8 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <typeinfo>
+
 #include <sal/types.h>
 
 #include "outfont.hxx"
@@ -30,8 +32,8 @@ using namespace vcl;
 
 PDFFontCache::FontIdentifier::FontIdentifier( const PhysicalFontFace* pFont, bool bVertical ) :
     m_nFontId( pFont->GetFontId() ),
-    m_nMagic( pFont->GetFontMagic() ),
-    m_bVertical( bVertical )
+    m_bVertical( bVertical ),
+    m_typeFontFace( const_cast<std::type_info*>(&typeid(pFont)) )
 {
 }
 
diff --git a/vcl/source/gdi/pdffontcache.hxx b/vcl/source/gdi/pdffontcache.hxx
index 88229e2..8192bf1 100644
--- a/vcl/source/gdi/pdffontcache.hxx
+++ b/vcl/source/gdi/pdffontcache.hxx
@@ -20,6 +20,8 @@
 #ifndef INCLUDED_VCL_SOURCE_GDI_PDFFONTCACHE_HXX
 #define INCLUDED_VCL_SOURCE_GDI_PDFFONTCACHE_HXX
 
+#include <typeinfo>
+
 #include <sal/types.h>
 
 #include <sallayout.hxx>
@@ -32,22 +34,26 @@ namespace vcl
         struct FontIdentifier
         {
             sal_IntPtr      m_nFontId;
-            int             m_nMagic;
             bool            m_bVertical;
+            std::type_info* m_typeFontFace;
 
             FontIdentifier( const PhysicalFontFace*, bool bVertical );
-            FontIdentifier() : m_nFontId(0), m_nMagic(0), m_bVertical( false ) {}
+            FontIdentifier() : m_nFontId(0), m_bVertical( false ) {}
 
             bool operator==( const FontIdentifier& rRight ) const
             {
                 return m_nFontId == rRight.m_nFontId &&
-                       m_nMagic == rRight.m_nMagic &&
+                       m_typeFontFace == rRight.m_typeFontFace &&
                        m_bVertical == rRight.m_bVertical;
             }
+
+            // Less than needed for std::set and std::map
             bool operator<( const FontIdentifier& rRight ) const
             {
+                std::type_info *pType = rRight.m_typeFontFace;
+
                 return m_nFontId < rRight.m_nFontId ||
-                       m_nMagic < rRight.m_nMagic ||
+                       m_typeFontFace->before( *pType ) ||
                        m_bVertical < rRight.m_bVertical;
             }
         };
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 9e8428f..9ccdbd0 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -2239,29 +2239,6 @@ OutputDevice* PDFWriterImpl::getReferenceDevice()
     return m_pReferenceDevice;
 }
 
-class ImplPdfBuiltinFontData : public PhysicalFontFace
-{
-private:
-    const PDFWriterImpl::BuiltinFont& mrBuiltin;
-
-public:
-    static int const PDF_FONT_MAGIC = int(0xBDFF0A1C);
-    explicit                            ImplPdfBuiltinFontData( const PDFWriterImpl::BuiltinFont& );
-    const PDFWriterImpl::BuiltinFont&   GetBuiltinFont() const  { return mrBuiltin; }
-
-    virtual PhysicalFontFace*           Clone() const override { return new ImplPdfBuiltinFontData(*this); }
-    virtual ImplFontEntry*              CreateFontInstance( FontSelectPattern& ) const override;
-    virtual sal_IntPtr                  GetFontId() const override { return reinterpret_cast<sal_IntPtr>(&mrBuiltin); }
-};
-
-inline const ImplPdfBuiltinFontData* GetPdfFontData( const PhysicalFontFace* pFontData )
-{
-    const ImplPdfBuiltinFontData* pFD = nullptr;
-    if( pFontData && pFontData->CheckMagic( ImplPdfBuiltinFontData::PDF_FONT_MAGIC ) )
-        pFD = static_cast<const ImplPdfBuiltinFontData*>( pFontData );
-    return pFD;
-}
-
 static ImplFontAttributes GetDevFontAttributes( const PDFWriterImpl::BuiltinFont& rBuiltin )
 {
     ImplFontAttributes aDFA;
@@ -2283,7 +2260,7 @@ static ImplFontAttributes GetDevFontAttributes( const PDFWriterImpl::BuiltinFont
 }
 
 ImplPdfBuiltinFontData::ImplPdfBuiltinFontData( const PDFWriterImpl::BuiltinFont& rBuiltin )
-:   PhysicalFontFace( GetDevFontAttributes(rBuiltin), PDF_FONT_MAGIC ),
+:   PhysicalFontFace( GetDevFontAttributes(rBuiltin) ),
     mrBuiltin( rBuiltin )
 {}
 
@@ -2938,9 +2915,8 @@ bool PDFWriterImpl::emitTilings()
     return true;
 }
 
-sal_Int32 PDFWriterImpl::emitBuiltinFont( const PhysicalFontFace* pFont, sal_Int32 nFontObject )
+sal_Int32 PDFWriterImpl::emitBuiltinFont( const ImplPdfBuiltinFontData* pFD, sal_Int32 nFontObject )
 {
-    const ImplPdfBuiltinFontData* pFD = GetPdfFontData( pFont );
     if( !pFD )
         return 0;
     const BuiltinFont& rBuiltinFont = pFD->GetBuiltinFont();
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 542b2b5..7d81df8 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -43,6 +43,7 @@
 #include "sallayout.hxx"
 #include "outdata.hxx"
 #include "pdffontcache.hxx"
+#include "PhysicalFontFace.hxx"
 
 class StyleSettings;
 class FontSelectPattern;
@@ -70,6 +71,7 @@ namespace vcl
 
 class PDFStreamIf;
 class Matrix3;
+class ImplPdfBuiltinFontData;
 
 class PDFWriterImpl
 {
@@ -833,7 +835,7 @@ i12626
     /* writes all gradient patterns */
     bool emitGradients();
     /* writes a builtin font object and returns its objectid (or 0 in case of failure ) */
-    sal_Int32 emitBuiltinFont( const PhysicalFontFace*, sal_Int32 nObject = -1 );
+    sal_Int32 emitBuiltinFont( const ImplPdfBuiltinFontData*, sal_Int32 nObject = -1 );
     /* writes a type1 embedded font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
     std::map< sal_Int32, sal_Int32 > emitEmbeddedFont( const PhysicalFontFace*, EmbedFont& );
     /* writes a type1 system font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
@@ -1254,6 +1256,21 @@ public:
     }
 };
 
+class ImplPdfBuiltinFontData : public PhysicalFontFace
+{
+private:
+    const PDFWriterImpl::BuiltinFont& mrBuiltin;
+
+public:
+    explicit                            ImplPdfBuiltinFontData( const PDFWriterImpl::BuiltinFont& );
+    const PDFWriterImpl::BuiltinFont&   GetBuiltinFont() const  { return mrBuiltin; }
+
+    virtual PhysicalFontFace*           Clone() const override { return new ImplPdfBuiltinFontData(*this); }
+    virtual ImplFontEntry*              CreateFontInstance( FontSelectPattern& ) const override;
+    virtual sal_IntPtr                  GetFontId() const override { return reinterpret_cast<sal_IntPtr>(&mrBuiltin); }
+};
+
+
 }
 
 #endif //_VCL_PDFEXPORT_HXX
diff --git a/vcl/win/gdi/salgdi3.cxx b/vcl/win/gdi/salgdi3.cxx
index 9e290be..8d69c60 100644
--- a/vcl/win/gdi/salgdi3.cxx
+++ b/vcl/win/gdi/salgdi3.cxx
@@ -995,7 +995,7 @@ const void * GrFontData::getTable(unsigned int name, size_t *len) const
 
 ImplWinFontData::ImplWinFontData( const ImplFontAttributes& rDFS,
     int nHeight, BYTE eWinCharSet, BYTE nPitchAndFamily )
-:   PhysicalFontFace( rDFS, 0 ),
+:   PhysicalFontFace( rDFS ),
     mnId( 0 ),
     mbHasKoreanRange( false ),
     mbHasCJKSupport( false ),


More information about the Libreoffice-commits mailing list