Hello all,

the internal function name PODOFO_Base14FontDef_FindBuiltinData looks
like it should be in a namespace and a class IMHO, therefore I've
converted it to a private method with access only from PdfFontFactory.
I've also implemented a wrapper method IsBase14Font() to give the
class PdfFontCache access on a need-to-know basis (that is, a boolean
return value instead of a pointer to, possibly even writable, metrics).
Should someone desire access to any of this info outside PoDoFo, some
workaround is possible: e.g. create the font, query its metrics and
check if they can be converted (dynamic_cast) to PdfFontMetricsBase14.

The only not backward-compatible change (by Debian Policy 4.1.2 clause
8.6.2 Shared library ABI changes) is IIUC the removal of the function
named above, which really is internal, right?
I build-tested the change with Debian sbuild into a Debian sid chroot.
No new warnings were produced (build log available on request, not
attached because it's > 100KiB large).
So please (@committers) accept this change, which is attached as a
diff -up format patch to this e-mail (applies the same to 0.9.5 and the
trunk) before the next (candidate) release.

Best regards, mabri
diff -rup libpodofo-0.9.5.orig/src/doc/PdfFontCache.cpp libpodofo-0.9.5/src/doc/PdfFontCache.cpp
--- libpodofo-0.9.5.orig/src/doc/PdfFontCache.cpp
+++ libpodofo-0.9.5/src/doc/PdfFontCache.cpp
@@ -396,7 +396,7 @@ PdfFont* PdfFontCache::GetFont( const ch
     if( it.first == it.second )
     {
         if ( (eFontCreationFlags & eFontCreationFlags_AutoSelectBase14) 
-             && PODOFO_Base14FontDef_FindBuiltinData(pszFontName) )
+             && PdfFontFactory::FontTypes::IsBase14Font(pszFontName) )
         {
             EPdfFontFlags eFlags = ePdfFont_Normal;
             if( bBold )
diff -rup libpodofo-0.9.5.orig/src/doc/PdfFontFactory.cpp libpodofo-0.9.5/src/doc/PdfFontFactory.cpp
--- libpodofo-0.9.5.orig/src/doc/PdfFontFactory.cpp
+++ libpodofo-0.9.5/src/doc/PdfFontFactory.cpp
@@ -241,7 +241,8 @@ PdfFont* PdfFontFactory::CreateFont( FT_
            PdfObject* pBaseFont = NULL;
            pBaseFont = pObject->GetIndirectKey( "BaseFont" );
            const char* pszBaseFontName = pBaseFont->GetName().GetName().c_str();
-           PdfFontMetricsBase14* pMetrics = PODOFO_Base14FontDef_FindBuiltinData(pszBaseFontName);
+           PdfFontMetricsBase14* pMetrics = dynamic_cast<PdfFontMetricsBase14*>
+                                  ( Builtin::FindMetrics(pszBaseFontName) );
            if ( pMetrics != NULL )
            {
                // pEncoding may be undefined, found a valid pdf with
@@ -348,9 +349,13 @@ EPdfFontType PdfFontFactory::GetFontType
     return eFontType;
 }
 
+bool PdfFontFactory::FontTypes::IsBase14Font(const char * pszFontName)
+{
+    return Builtin::FindMetrics(pszFontName);
+}
 
-PdfFontMetricsBase14*
-PODOFO_Base14FontDef_FindBuiltinData(const char  *font_name)
+PdfFontMetrics*
+PdfFontFactory::Builtin::FindMetrics(const char *font_name)
 {
     unsigned int i = 0;
 	bool found = false;
@@ -371,8 +376,9 @@ PdfFont *PdfFontFactory::CreateBase14Fon
                     EPdfFontFlags eFlags, const PdfEncoding * const pEncoding,
                     PdfVecObjects *pParent)
 {
-    PdfFont *pFont = new PdfFontType1Base14(
-        PODOFO_Base14FontDef_FindBuiltinData(pszFontName), pEncoding, pParent);
+    PdfFont *pFont = new PdfFontType1Base14(dynamic_cast<PdfFontMetricsBase14*>
+                        ( Builtin::FindMetrics(pszFontName) ),
+                        pEncoding, pParent );
     if (pFont) {
         pFont->SetBold( eFlags & ePdfFont_Bold ? true : false );
         pFont->SetItalic( eFlags & ePdfFont_Italic ? true : false );
diff -rup libpodofo-0.9.5.orig/src/doc/PdfFontFactory.h libpodofo-0.9.5/src/doc/PdfFontFactory.h
--- libpodofo-0.9.5.orig/src/doc/PdfFontFactory.h
+++ libpodofo-0.9.5/src/doc/PdfFontFactory.h
@@ -104,6 +104,25 @@ class PODOFO_DOC_API PdfFontFactory {
      */
     static EPdfFontType GetFontType( const char* pszFilename );
 
+    /** Nested class to restrict access for the font cache to the necessary.
+     */
+    class FontTypes {
+      private:
+        friend class PdfFontCache;
+        static bool IsBase14Font(const char * pszFontName);
+        FontTypes(); // prohibit instatiation
+    };
+
+    /** Nested class to restrict access to PdfFontMetricsBase14's private
+     *  members to the former's method.
+     */
+    class Builtin {
+      private:
+        friend class PdfFontFactory;
+        static PdfFontMetrics* FindMetrics(const char *font_name);
+        Builtin(); // prohibit instatiation
+    };
+
  private:
     // prohibit instantiation of all-methods-static factory from outside 
     PdfFontFactory();
diff -rup libpodofo-0.9.5.orig/src/doc/PdfFontMetricsBase14.h libpodofo-0.9.5/src/doc/PdfFontMetricsBase14.h
--- libpodofo-0.9.5.orig/src/doc/PdfFontMetricsBase14.h
+++ libpodofo-0.9.5/src/doc/PdfFontMetricsBase14.h
@@ -39,6 +39,7 @@
 #include "podofo/base/PdfVariant.h"
 
 #include "PdfFontMetrics.h"
+#include "PdfFontFactory.h"
 
 #include <string.h>
 
@@ -81,8 +82,7 @@ public:
 
     ~PdfFontMetricsBase14();
 
-	friend  PdfFontMetricsBase14*
-		PODOFO_Base14FontDef_FindBuiltinData  (const char  *font_name);
+    friend class PdfFontFactory::Builtin;
 
     /** Create a width array for this font which is a required part
      *  of every font dictionary.
@@ -277,10 +277,6 @@ private :
 
 };
 
-
-PdfFontMetricsBase14*
-PODOFO_Base14FontDef_FindBuiltinData  (const char  *font_name);
-
 // -----------------------------------------------------
 // 
 // -----------------------------------------------------
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to