shithub: freetype+ttf2subf

Download patch

ref: 91a67478ec4a8ef0a7363f4728dd6c06be1ca92f
parent: efe527520a5f35be7a72bf4f7d97d02533b1705b
author: Werner Lemberg <[email protected]>
date: Wed Dec 17 09:28:22 EST 2003

Add new function FT_Get_CMap_Language_ID to extract the language ID
for TrueType/sfnt fonts.

* include/freetype/internal/services/svttcmap.h: New file.
* include/freetype/internal/ftserv.h (FT_SERVICE_TT_CMAP_H): Add
svttcmap.h.

* src/sfnt/sfdriver.c: Include ttcmap0.h.
(tt_service_get_cmap_info): New service.
(sfnt_services): Updated.

* src/sfnt/ttcmap0.c (tt_cmap*_get_info): New functions.
(tt_cmap*_class_rec): Add tt_cmap*_get_info members.
(tt_get_cmap_info): New function.
* src/sfnt/ttcmap0.h: Include FT_SERVICE_TT_CMAP_H.
(TT_CMap_ClassRec): New field `get_cmap_info'.
(tt_get_cmap_info): New declaration.

* src/base/ftobjs.c: Include FT_SERVICE_TT_CMAP_H.
(FT_Get_CMap_Language_ID): New function implementation.
* include/freetype/tttables.h (FT_Get_CMap_Language_ID): New
function declaration.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2003-12-17  Masatake YAMATO  <[email protected]>
+
+	Add new function FT_Get_CMap_Language_ID to extract the language ID
+	for TrueType/sfnt fonts.
+
+	* include/freetype/internal/services/svttcmap.h: New file.
+	* include/freetype/internal/ftserv.h (FT_SERVICE_TT_CMAP_H): Add
+	svttcmap.h.
+
+	* src/sfnt/sfdriver.c: Include ttcmap0.h.
+	(tt_service_get_cmap_info): New service.
+	(sfnt_services): Updated.
+
+	* src/sfnt/ttcmap0.c (tt_cmap*_get_info): New functions.
+	(tt_cmap*_class_rec): Add tt_cmap*_get_info members.
+	(tt_get_cmap_info): New function.
+	* src/sfnt/ttcmap0.h: Include FT_SERVICE_TT_CMAP_H.
+	(TT_CMap_ClassRec): New field `get_cmap_info'.
+	(tt_get_cmap_info): New declaration.
+
+	* src/base/ftobjs.c: Include FT_SERVICE_TT_CMAP_H.
+	(FT_Get_CMap_Language_ID): New function implementation.
+	* include/freetype/tttables.h (FT_Get_CMap_Language_ID): New
+	function declaration.
+
 2003-12-16  Werner Lemberg  <[email protected]>
 
 	* src/sfnt/ttcmap.c, src/sfnt/ttcmap.h: Removed.  Obsolete.
@@ -15,7 +40,7 @@
 	TT_CMapDirRec, TT_CMapDirEntryRec, TT_CMap0, TT_CMap2SubHeaderRec,
 	TT_CMap2Rec, TT_CMap4Segment, TT_CMap4Rec, TT_CMap6,
 	TT_CMapGroupRec, TT_CMap8_12Rec, TT_CMap10Rec, TT_CharMap_Func,
-	TT_CharNext_Func, TT_CMapTableRec, TT_CharMapRec): Removed. 
+	TT_CharNext_Func, TT_CMapTableRec, TT_CharMapRec): Removed.
 	Obsolete.
 	* src/cff/cffobjs.h (CFF_CharMapRec): Removed.  Obsolete.
 
@@ -6038,7 +6063,7 @@
 	(html_format): Replaced with ...
 	(html_quote): New function.
 	(html_quote0): New function.
-	(DocCode::dump_html: Small improvement.
+	(DocCode::dump_html): Small improvement.
 	(DocParagraph::dump, DocBlock::html): Use html_quote0 and html_quote.
 
 	* include/freetype/config/ftoption.h: Setting default options for
--- a/include/freetype/internal/ftserv.h
+++ b/include/freetype/internal/ftserv.h
@@ -248,6 +248,7 @@
 #define FT_SERVICE_SFNT_H              <freetype/internal/services/svsfnt.h>
 #define FT_SERVICE_PFR_H               <freetype/internal/services/svpfr.h>
 #define FT_SERVICE_WINFNT_H            <freetype/internal/services/svwinfnt.h>
+#define FT_SERVICE_TT_CMAP_H           <freetype/internal/services/svttcmap.h>
 
  /* */
 
--- /dev/null
+++ b/include/freetype/internal/services/svttcmap.h
@@ -1,0 +1,77 @@
+/***************************************************************************/
+/*                                                                         */
+/*  svsttcmap.h                                                            */
+/*                                                                         */
+/*    The FreeType TrueType/sfnt cmap extra information service.           */
+/*                                                                         */
+/*  Copyright 2003 by                                                      */
+/*  Masatake YAMATO, Redhat K.K.                                           */
+/*                                                                         */
+/*  Copyright 2003 by                                                      */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  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.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+/* Development of this service is support of 
+   Information-technology Promotion Agency, Japan. */
+
+#ifndef __SVTTCMAP_H__
+#define __SVTTCMAP_H__ 
+
+#include FT_INTERNAL_SERVICE_H
+#include FT_TRUETYPE_TABLES_H
+
+
+FT_BEGIN_HEADER
+
+
+#define FT_SERVICE_ID_TT_CMAP "tt-cmaps"
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    TT_CMapInfo                                                        */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A structure used to store TrueType/sfnt specific cmap information  */
+  /*    which is not covered by the generic @FT_CharMap structure.  This   */
+  /*    structure can be accessed with the @FT_Get_TT_CMap_Info function.  */
+  /*                                                                       */
+  /* <Fields>                                                              */
+  /*    language ::                                                        */
+  /*      The language ID used in Mac fonts.  Definitions of values are in */
+  /*      freetype/ttnameid.h.                                             */
+  /*                                                                       */
+  typedef struct  TT_CMapInfo_
+  {
+    FT_ULong language;
+
+  } TT_CMapInfo;
+
+
+  typedef FT_Error
+  (*TT_CMap_Info_GetFunc)( FT_CharMap    charmap,
+                           TT_CMapInfo  *cmap_info );
+
+
+  FT_DEFINE_SERVICE( TTCMaps )
+  {
+    TT_CMap_Info_GetFunc  get_cmap_info;
+  }; 
+  
+  /* */
+
+
+FT_END_HEADER
+
+#endif /* __SVTTCMAP_H__ */
+
+
+/* END */
--- a/include/freetype/tttables.h
+++ b/include/freetype/tttables.h
@@ -663,6 +663,27 @@
                       FT_Byte*   buffer,
                       FT_ULong*  length );
 
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_Get_CMap_Language_ID                                            */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Return TrueType/sfnt specific cmap language ID.  Definitions of    */
+  /*    language ID values are in freetype/ttnameid.h.                     */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    charmap ::                                                         */
+  /*      The target charmap.                                              */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    The language ID of `charmap'.  If `charmap' doesn't belong to a    */
+  /*    TrueType/sfnt face, just return 0 as the default value.            */
+  /*                                                                       */
+  FT_EXPORT( FT_ULong )
+  FT_Get_CMap_Language_ID( FT_CharMap  charmap );
+
   /* */
 
 
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -30,6 +30,7 @@
 #include FT_SERVICE_SFNT_H
 #include FT_SERVICE_POSTSCRIPT_NAME_H
 #include FT_SERVICE_GLYPH_DICT_H
+#include FT_SERVICE_TT_CMAP_H
 
 
   FT_BASE_DEF( FT_Pointer )
@@ -2505,6 +2506,28 @@
       return FT_Err_Unimplemented_Feature;
 
     return service->load_table( face, tag, offset, buffer, length );
+  }
+
+
+  FT_EXPORT_DEF( FT_ULong )
+  FT_Get_CMap_Language_ID( FT_CharMap  charmap )
+  {
+    FT_Service_TTCMaps  service;
+    FT_Face             face;
+    TT_CMapInfo         cmap_info;
+
+    
+    if ( !charmap || !charmap->face )
+      return 0;
+
+    face = charmap->face;
+    FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
+    if ( service == NULL )
+      return 0;
+    if ( service->get_cmap_info( charmap, &cmap_info ))
+      return 0;
+
+    return cmap_info.language;
   }
 
 
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -34,9 +34,12 @@
 #include "ttpost.h"
 #endif
 
+#include "ttcmap0.h"
+
 #include FT_SERVICE_GLYPH_DICT_H
 #include FT_SERVICE_POSTSCRIPT_NAME_H
 #include FT_SERVICE_SFNT_H
+#include FT_SERVICE_TT_CMAP_H
 
 
  /*
@@ -260,7 +263,16 @@
   };
 
 
+ /*
+  *  TT CMAP INFO
+  *
+  */
+  static const FT_Service_TTCMapsRec  tt_service_get_cmap_info =
+  {
+    (TT_CMap_Info_GetFunc)tt_get_cmap_info
+  };
 
+
  /*
   *  SERVICE LIST
   *
@@ -273,6 +285,7 @@
 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
     { FT_SERVICE_ID_GLYPH_DICT,           &sfnt_service_glyph_dict },
 #endif
+    { FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info },
 
     { NULL, NULL }
   };
--- a/src/sfnt/ttcmap0.c
+++ b/src/sfnt/ttcmap0.c
@@ -144,6 +144,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap0_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap0_class_rec =
   {
@@ -156,7 +169,8 @@
       (FT_CMap_CharNextFunc) tt_cmap0_char_next
     },
     0,
-    (TT_CMap_ValidateFunc)   tt_cmap0_validate
+    (TT_CMap_ValidateFunc)   tt_cmap0_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap0_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_0 */
@@ -497,6 +511,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap2_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap2_class_rec =
   {
@@ -509,7 +536,8 @@
       (FT_CMap_CharNextFunc) tt_cmap2_char_next
     },
     2,
-    (TT_CMap_ValidateFunc)   tt_cmap2_validate
+    (TT_CMap_ValidateFunc)   tt_cmap2_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap2_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_2 */
@@ -1058,6 +1086,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap4_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap4_class_rec =
   {
@@ -1070,7 +1111,8 @@
       (FT_CMap_CharNextFunc) tt_cmap4_char_next
     },
     4,
-    (TT_CMap_ValidateFunc)   tt_cmap4_validate
+    (TT_CMap_ValidateFunc)   tt_cmap4_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap4_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_4 */
@@ -1202,6 +1244,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap6_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 4;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap6_class_rec =
   {
@@ -1214,7 +1269,8 @@
       (FT_CMap_CharNextFunc) tt_cmap6_char_next
     },
     6,
-    (TT_CMap_ValidateFunc)   tt_cmap6_validate
+    (TT_CMap_ValidateFunc)   tt_cmap6_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap6_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_6 */
@@ -1439,6 +1495,18 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap8_get_info( TT_CMap       cmap,
+                     TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 8;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap8_class_rec =
   {
@@ -1451,7 +1519,8 @@
       (FT_CMap_CharNextFunc) tt_cmap8_char_next
     },
     8,
-    (TT_CMap_ValidateFunc)   tt_cmap8_validate
+    (TT_CMap_ValidateFunc)   tt_cmap8_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap8_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_8 */
@@ -1571,6 +1640,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap10_get_info( TT_CMap       cmap,
+                      TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 8;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap10_class_rec =
   {
@@ -1583,7 +1665,8 @@
       (FT_CMap_CharNextFunc) tt_cmap10_char_next
     },
     10,
-    (TT_CMap_ValidateFunc)   tt_cmap10_validate
+    (TT_CMap_ValidateFunc)   tt_cmap10_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap10_get_info
   };
 
 #endif /* TT_CONFIG_CMAP_FORMAT_10 */
@@ -1741,6 +1824,19 @@
   }
 
 
+  FT_CALLBACK_DEF( FT_Error )
+  tt_cmap12_get_info( TT_CMap       cmap,
+                      TT_CMapInfo  *cmap_info )
+  {
+    FT_Byte*  p = cmap->data + 8;
+
+
+    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
+
+    return FT_Err_Ok;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const TT_CMap_ClassRec  tt_cmap12_class_rec =
   {
@@ -1753,7 +1849,8 @@
       (FT_CMap_CharNextFunc) tt_cmap12_char_next
     },
     12,
-    (TT_CMap_ValidateFunc)   tt_cmap12_validate
+    (TT_CMap_ValidateFunc)   tt_cmap12_validate,
+    (TT_CMap_Info_GetFunc)   tt_cmap12_get_info
   };
 
 
@@ -1872,6 +1969,18 @@
     }
 
     return 0;
+  }
+
+
+  FT_LOCAL( FT_Error )
+  tt_get_cmap_info( FT_CharMap    charmap,
+                    TT_CMapInfo  *cmap_info )
+  {
+    FT_CMap        cmap  = (FT_CMap)charmap;
+    TT_CMap_Class  clazz = (TT_CMap_Class)cmap->clazz;
+
+
+    return clazz->get_cmap_info( charmap, cmap_info );
   }
 
 
--- a/src/sfnt/ttcmap0.h
+++ b/src/sfnt/ttcmap0.h
@@ -23,8 +23,8 @@
 #include <ft2build.h>
 #include FT_INTERNAL_TRUETYPE_TYPES_H
 #include FT_INTERNAL_OBJECTS_H
+#include FT_SERVICE_TT_CMAP_H
 
-
 FT_BEGIN_HEADER
 
   typedef struct  TT_CMapRec_
@@ -46,6 +46,7 @@
     FT_CMap_ClassRec      clazz;
     FT_UInt               format;
     TT_CMap_ValidateFunc  validate;
+    TT_CMap_Info_GetFunc  get_cmap_info;
 
   } TT_CMap_ClassRec;
 
@@ -64,6 +65,11 @@
 
   FT_LOCAL( FT_Error )
   tt_face_build_cmaps( TT_Face  face );
+
+  /* used in tt-cmaps service */
+  FT_LOCAL( FT_Error )
+  tt_get_cmap_info( FT_CharMap    charmap,
+                    TT_CMapInfo  *cmap_info );
 
 
 FT_END_HEADER