shithub: freetype+ttf2subf

Download patch

ref: f414702e04c103922dff335abd72c6baf7f9c5c4
parent: ce1bad0381c8ae0bff2ea54d5101808779e1b498
author: Suzuki, Toshiya (鈴木俊哉) <[email protected]>
date: Wed Oct 1 21:43:18 EDT 2008

* Merge the duplicated functions in ftmac.c with ftobjs.c

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2008-10-02  suzuki toshiya  <[email protected]>
+
+	* src/base/ftbase.h: New file to declare the private utility
+	functions shared by the sources of base modules. Currently,
+	`ft_lookup_PS_in_sfnt' and `open_face_from_buffer' are declared
+	to share between ftobjs.c and ftmac.c.
+	* src/base/rule.mk: Add ftbase.h.
+	* src/base/ftobjs.c: Include ftbase.h.
+	(memory_stream_close): Build on any platform when old MacOS
+	font support is enabled.
+	(new_memory_stream): Ditto.
+	(open_face_from_buffer): Build on any platform when old MacOS
+	font support is enabled. The counting of the face in a font
+	file is slightly different between Carbon-dependent parser and
+	Carbon-free parser. They are merged with the platform-specific
+	conditional.
+	(ft_lookup_PS_in_sfnt): Ditto.
+	* src/base/ftmac.c: Include ftbase.h.
+	(memory_stream_close): Removed.
+	(new_memory_stream): Ditto.
+	(open_face_from_buffer): Removed. Use the implementation in
+	ftobjs.c.
+	(ft_lookup_PS_in_sfnt): Ditto.
+
 2008-10-02  Werner Lemberg  <[email protected]>
 
 	* src/sfnt/sfobjs.c (sfnt_load_face): `psnames_error' is only needed
--- /dev/null
+++ b/src/base/ftbase.h
@@ -1,0 +1,54 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftbase.h                                                               */
+/*                                                                         */
+/*    The FreeType private functions used in base module (specification).  */
+/*                                                                         */
+/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by             */
+/*  David Turner, Robert Wilhelm, Werner Lemberg, and suzuki toshiya.      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#ifndef __FTBASE_H__
+#define __FTBASE_H__
+
+
+#include <ft2build.h>
+#include FT_INTERNAL_OBJECTS_H
+
+
+FT_BEGIN_HEADER
+
+
+  /* Check whether the sfnt image in the buffer is sfnt-wrapped PS Type1 */
+  /* or sfnt-wrapped CID-keyed font. */
+  FT_LOCAL_DEF( FT_Error )
+  ft_lookup_PS_in_sfnt( FT_Byte*   sfnt,
+                        FT_ULong*  offset,
+                        FT_ULong*  length,
+                        FT_Bool*   is_sfnt_cid );
+ 
+  /* Create a new FT_Face given a buffer and a driver name. */
+  /* from ftmac.c */
+  FT_LOCAL_DEF( FT_Error )
+  open_face_from_buffer( FT_Library   library,
+                         FT_Byte*     base,
+                         FT_ULong     size,
+                         FT_Long      face_index,
+                         const char*  driver_name,
+                         FT_Face     *aface );
+
+
+FT_END_HEADER
+
+#endif /* __TTDRIVER_H__ */
+
+
+/* END */
--- a/src/base/ftmac.c
+++ b/src/base/ftmac.c
@@ -68,6 +68,7 @@
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_INTERNAL_STREAM_H
+#include "ftbase.h"
 
   /* This is for Mac OS X.  Without redefinition, OS_INLINE */
   /* expands to `static inline' which doesn't survive the   */
@@ -694,109 +695,6 @@
   }
 
 
-  /* Finalizer for a memory stream; gets called by FT_Done_Face().
-     It frees the memory it uses. */
-  static void
-  memory_stream_close( FT_Stream  stream )
-  {
-    FT_Memory  memory = stream->memory;
-
-
-    FT_FREE( stream->base );
-
-    stream->size  = 0;
-    stream->base  = 0;
-    stream->close = 0;
-  }
-
-
-  /* Create a new memory stream from a buffer and a size. */
-  static FT_Error
-  new_memory_stream( FT_Library           library,
-                     FT_Byte*             base,
-                     FT_ULong             size,
-                     FT_Stream_CloseFunc  close,
-                     FT_Stream*           astream )
-  {
-    FT_Error   error;
-    FT_Memory  memory;
-    FT_Stream  stream;
-
-
-    if ( !library )
-      return FT_Err_Invalid_Library_Handle;
-
-    if ( !base )
-      return FT_Err_Invalid_Argument;
-
-    *astream = 0;
-    memory = library->memory;
-    if ( FT_NEW( stream ) )
-      goto Exit;
-
-    FT_Stream_OpenMemory( stream, base, size );
-
-    stream->close = close;
-
-    *astream = stream;
-
-  Exit:
-    return error;
-  }
-
-
-  /* Create a new FT_Face given a buffer and a driver name. */
-  static FT_Error
-  open_face_from_buffer( FT_Library   library,
-                         FT_Byte*     base,
-                         FT_ULong     size,
-                         FT_Long      face_index,
-                         const char*  driver_name,
-                         FT_Face*     aface )
-  {
-    FT_Open_Args  args;
-    FT_Error      error;
-    FT_Stream     stream;
-    FT_Memory     memory = library->memory;
-
-
-    error = new_memory_stream( library,
-                               base,
-                               size,
-                               memory_stream_close,
-                               &stream );
-    if ( error )
-    {
-      FT_FREE( base );
-      return error;
-    }
-
-    args.flags  = FT_OPEN_STREAM;
-    args.stream = stream;
-    if ( driver_name )
-    {
-      args.flags  = args.flags | FT_OPEN_DRIVER;
-      args.driver = FT_Get_Module( library, driver_name );
-    }
-
-    /* At this point, face_index has served its purpose;      */
-    /* whoever calls this function has already used it to     */
-    /* locate the correct font data.  We should not propagate */
-    /* this index to FT_Open_Face() (unless it is negative).  */
-
-    if ( face_index > 0 )
-      face_index = 0;
-
-    error = FT_Open_Face( library, &args, face_index, aface );
-    if ( error )
-      FT_Stream_Free( stream, 0 );
-    else
-      (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
-
-    return error;
-  }
-
-
   /* Create a new FT_Face from a file spec to an LWFN file. */
   static FT_Error
   FT_New_Face_From_LWFN( FT_Library    library,
@@ -826,61 +724,6 @@
                                   face_index,
                                   "type1",
                                   aface );
-  }
-
-
-  /* Look up `TYP1' or `CID ' table from sfnt table directory.       */
-  /* `offset' and `length' must exclude the binary header in tables. */
-
-  /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
-  /* format too.  Here, since we can't expect that the TrueType font */
-  /* driver is loaded unconditially, we must parse the font by       */
-  /* ourselves.  We are only interested in the name of the table and */
-  /* the offset. */
-
-  static FT_Error
-  ft_lookup_PS_in_sfnt( FT_Byte*   sfnt,
-                        FT_ULong*  offset,
-                        FT_ULong*  length,
-                        FT_Bool*   is_sfnt_cid )
-  {
-    FT_Byte*   p = sfnt + 4; /* skip version `typ1' */
-    FT_UShort  numTables = FT_NEXT_USHORT( p );
-
-
-    p += 2 * 3;              /* skip binary search header */
-
-    for ( ; numTables > 0 ; numTables -- )
-    {
-      FT_ULong  tag = FT_NEXT_ULONG( p );
-
-
-      p += 4; /* skip checkSum */
-      *offset = FT_NEXT_ULONG( p );
-      *length = FT_NEXT_ULONG( p );
-
-      /* see Adobe TN# 5180 for binary header in CID table */
-      if ( tag == FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) )
-      {
-        *offset += 22;
-        *length -= 22;
-        *is_sfnt_cid = TRUE;
-        return FT_Err_Ok;
-      }
-
-      /* see Apple's `The Type 1 GX Font Format' */
-      if ( tag == FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) )
-      {
-        *offset += 24;
-        *length -= 24;
-        *is_sfnt_cid = FALSE;
-        return FT_Err_Ok;
-      }
-    }
-
-    *offset = 0;
-    *length = 0;
-    return FT_Err_Invalid_Table;
   }
 
 
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -36,6 +36,8 @@
 #include FT_SERVICE_KERNING_H
 #include FT_SERVICE_TRUETYPE_ENGINE_H
 
+#include "ftbase.h"
+
 #define GRID_FIT_METRICS
 
   FT_BASE_DEF( FT_Pointer )
@@ -1167,7 +1169,7 @@
   }
 
 
-#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
+#if defined( FT_CONFIG_OPTION_MAC_FONTS )
 
   /* The behavior here is very similar to that in base/ftmac.c, but it     */
   /* is designed to work on non-mac systems, so no mac specific calls.     */
@@ -1251,7 +1253,7 @@
 
   /* Create a new FT_Face given a buffer and a driver name. */
   /* from ftmac.c */
-  static FT_Error
+  FT_LOCAL_DEF( FT_Error )
   open_face_from_buffer( FT_Library   library,
                          FT_Byte*     base,
                          FT_ULong     size,
@@ -1284,20 +1286,90 @@
       args.driver = FT_Get_Module( library, driver_name );
     }
 
+#if defined( FT_MACINTOSH )
+    /* At this point, face_index has served its purpose;      */
+    /* whoever calls this function has already used it to     */
+    /* locate the correct font data.  We should not propagate */
+    /* this index to FT_Open_Face() (unless it is negative).  */
+
+    if ( face_index > 0 )
+      face_index = 0;
+#endif
+
     error = FT_Open_Face( library, &args, face_index, aface );
 
-    if ( error )
+    if ( error == FT_Err_Ok )
+      (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
+    else
+#if defined( FT_MACINTOSH )
+      FT_Stream_Free( stream, 0 );
+#else
     {
       FT_Stream_Close( stream );
       FT_FREE( stream );
     }
-    else
-      (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
+#endif
 
     return error;
   }
 
 
+  /* Look up `TYP1' or `CID ' table from sfnt table directory.       */
+  /* `offset' and `length' must exclude the binary header in tables. */
+
+  /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
+  /* format too.  Here, since we can't expect that the TrueType font */
+  /* driver is loaded unconditially, we must parse the font by       */
+  /* ourselves.  We are only interested in the name of the table and */
+  /* the offset. */
+
+  FT_LOCAL_DEF( FT_Error )
+  ft_lookup_PS_in_sfnt( FT_Byte*   sfnt,
+                        FT_ULong*  offset,
+                        FT_ULong*  length,
+                        FT_Bool*   is_sfnt_cid )
+  {
+    FT_Byte*   p = sfnt + 4; /* skip version `typ1' */
+    FT_UShort  numTables = FT_NEXT_USHORT( p );
+
+
+    p += 2 * 3;              /* skip binary search header */
+
+    for ( ; numTables > 0 ; numTables -- )
+    {
+      FT_ULong  tag = FT_NEXT_ULONG( p );
+
+
+      p += 4; /* skip checkSum */
+      *offset = FT_NEXT_ULONG( p );
+      *length = FT_NEXT_ULONG( p );
+
+      /* see Adobe TN# 5180 for binary header in CID table */
+      if ( tag == FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) )
+      {
+        *offset += 22;
+        *length -= 22;
+        *is_sfnt_cid = TRUE;
+        return FT_Err_Ok;
+      }
+
+      /* see Apple's `The Type 1 GX Font Format' */
+      if ( tag == FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) )
+      {
+        *offset += 24;
+        *length -= 24;
+        *is_sfnt_cid = FALSE;
+        return FT_Err_Ok;
+      }
+    }
+
+    *offset = 0;
+    *length = 0;
+    return FT_Err_Invalid_Table;
+  }
+
+
+#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
   /* The resource header says we've got resource_cnt `POST' (type1) */
   /* resources in this file.  They all need to be coalesced into    */
   /* one lump which gets passed on to the type1 driver.             */
@@ -1415,61 +1487,6 @@
   }
 
 
-  /* Look up `TYP1' or `CID ' table from sfnt table directory.       */
-  /* `offset' and `length' must exclude the binary header in tables. */
-
-  /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
-  /* format too.  Here, since we can't expect that the TrueType font */
-  /* driver is loaded unconditially, we must parse the font by       */
-  /* ourselves.  We are only interested in the name of the table and */
-  /* the offset. */
-
-  static FT_Error
-  ft_lookup_PS_in_sfnt( FT_Byte*   sfnt,
-                        FT_ULong*  offset,
-                        FT_ULong*  length,
-                        FT_Bool*   is_sfnt_cid )
-  {
-    FT_Byte*   p = sfnt + 4; /* skip version `typ1' */
-    FT_UShort  numTables = FT_NEXT_USHORT( p );
-
-
-    p += 2 * 3;              /* skip binary search header */
-
-    for ( ; numTables > 0 ; numTables -- )
-    {
-      FT_ULong  tag = FT_NEXT_ULONG( p );
-
-
-      p += 4; /* skip checkSum */
-      *offset = FT_NEXT_ULONG( p );
-      *length = FT_NEXT_ULONG( p );
-
-      /* see Adobe TN# 5180 for binary header in CID table */
-      if ( tag == FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) )
-      {
-        *offset += 22;
-        *length -= 22;
-        *is_sfnt_cid = TRUE;
-        return FT_Err_Ok;
-      }
-
-      /* see Apple's `The Type 1 GX Font Format' */
-      if ( tag == FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) )
-      {
-        *offset += 24;
-        *length -= 24;
-        *is_sfnt_cid = FALSE;
-        return FT_Err_Ok;
-      }
-    }
-
-    *offset = 0;
-    *length = 0;
-    return FT_Err_Invalid_Table;
-  }
-
-
   /* The resource header says we've got resource_cnt `sfnt'      */
   /* (TrueType/OpenType) resources in this file.  Look through   */
   /* them for the one indicated by face_index, load it into mem, */
@@ -1749,7 +1766,7 @@
   }
 
 
-  /* Check for some macintosh formats.                             */
+  /* Check for some macintosh formats without Carbon framework.    */
   /* Is this a macbinary file?  If so look at the resource fork.   */
   /* Is this a mac dfont file?                                     */
   /* Is this an old style resource fork? (in data)                 */
@@ -1792,6 +1809,7 @@
                                            face_index, aface, args );
     return error;
   }
+#endif
 
 #endif  /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
 
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -51,6 +51,8 @@
   BASE_SRC += $(BASE_DIR)/$(ftmac_c)
 endif
 
+BASE_H := $(BASE_DIR)/ftbase.h
+
 # Base layer `extensions' sources
 #
 # An extension is added to the library file as a separate object.  It is