freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft-devel] Obtaining CID-specific info from an FT_Face?


From: Derek Clegg
Subject: Re: [ft-devel] Obtaining CID-specific info from an FT_Face?
Date: Fri, 13 Jul 2007 16:45:57 -0700


On Jul 13, 2007, at 2:32 PM, Werner LEMBERG wrote:

I've gone the path you suggested and added a "CID" service.  At
present, it provides access only the Registry/ Ordering/Supplement
for CFF CID fonts.

Maybe some day we need more, so please design something extensible...

I hope this is extensible — I'll probably need to add more myself soon.

Here's the patch:

diff -x CVS -urN freetype2/include/freetype/config/ftheader.h freetype2-working/include/freetype/config/ftheader.h --- freetype2/include/freetype/config/ftheader.h 2007-01-09 02:37:36.00 -0800 +++ freetype2-working/include/freetype/config/ftheader.h 2007-07-11 13:53:00.00 -0700
@@ -386,6 +386,20 @@
/ ************************************************************************ *
    *
    * @macro:
+   *   FT_CID_H
+   *
+   * @description:
+ * A macro used in #include statements to name the file containing the
+   *   definitions of an API which access CID font information from a
+   *   face.
+   *
+   */
+#define FT_CID_H  <freetype/ftcid.h>
+
+
+ / ************************************************************************ *
+   *
+   * @macro:
    *   FT_GZIP_H
    *
    * @description:
diff -x CVS -urN freetype2/include/freetype/ftcid.h freetype2-working/ include/freetype/ftcid.h
--- freetype2/include/freetype/ftcid.h  1969-12-31 16:00:00.00 -0800
+++ freetype2-working/include/freetype/ftcid.h 2007-07-11 13:51:51.00 -0700
@@ -0,0 +1,92 @@
+/ ************************************************************************ ***/ +/ * */ +/* ftcid.h * / +/ * */ +/* FreeType API for accessing CID font information (specification). */ +/ * */ +/* 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 __FTCID_H__
+#define __FTCID_H__
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#ifdef FREETYPE_H
+#error "freetype.h of FreeType 1 has been loaded!"
+#error "Please fix the directory search order for header files"
+#error "so that freetype.h of FreeType 2 is found first."
+#endif
+
+
+FT_BEGIN_HEADER
+
+
+ / ************************************************************************ */ + / * */ + /* <Section> */ + /* cid_fonts */ + / * */ + /* <Title> */ + /* CID Fonts */ + / * */ + /* <Abstract> */ + /* CID-font specific API. */ + / * */ + /* <Description> */ + /* This section contains the declaration of CID-font specific */ + /* functions. */ + / * */ + / ************************************************************************ */
+
+
+ / **********************************************************************
+  *
+  * @function:
+  *    FT_Get_CID_Registry_Ordering_Supplement
+  *
+  * @description:
+ * Retrieves the Registry/Ordering/Supplement triple (also known as the
+  *    "R/O/S") from a CID font.
+  *
+  * @input:
+  *    face ::
+  *       A handle to the input face.
+  *
+  * @output:
+  *    registry ::
+  *       The registry, as a C string, owned by the face.
+  *
+  *    ordering ::
+  *       The ordering, as a C string, owned by the face.
+  *
+  *    supplement ::
+  *       The supplement.
+  *
+  * @return:
+  *   FreeType error code.  0 means success.
+  *
+  * @note:
+ * This function only works with CID faces, returning an error otherwise.
+  */
+  FT_EXPORT( FT_Error )
+  FT_Get_CID_Registry_Ordering_Supplement( FT_Face       face,
+                                           const char*  *registry,
+                                           const char*  *ordering,
+                                           FT_Int       *supplement);
+
+ /* */
+
+FT_END_HEADER
+
+#endif /* __FTCID_H__ */
+
+
+/* END */
diff -x CVS -urN freetype2/include/freetype/internal/ftserv.h freetype2-working/include/freetype/internal/ftserv.h --- freetype2/include/freetype/internal/ftserv.h 2007-06-10 21:55:57.00 -0700 +++ freetype2-working/include/freetype/internal/ftserv.h 2007-07-11 13:36:15.00 -0700
@@ -301,6 +301,7 @@
    */
#define FT_SERVICE_BDF_H <freetype/internal/services/ svbdf.h> +#define FT_SERVICE_CID_H <freetype/internal/services/ svcid.h> #define FT_SERVICE_GLYPH_DICT_H <freetype/internal/services/ svgldict.h> #define FT_SERVICE_GX_VALIDATE_H <freetype/internal/services/ svgxval.h> #define FT_SERVICE_KERNING_H <freetype/internal/services/ svkern.h> diff -x CVS -urN freetype2/include/freetype/internal/services/svcid.h freetype2-working/include/freetype/internal/services/svcid.h --- freetype2/include/freetype/internal/services/svcid.h 1969-12-31 16:00:00.00 -0800 +++ freetype2-working/include/freetype/internal/services/svcid.h 2007-07-11 13:45:22.00 -0700
@@ -0,0 +1,47 @@
+/ ************************************************************************ ***/ +/ * */ +/* svcid.h * / +/ * */ +/* The FreeType CID font services (specification). */ +/ * */ +/* 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 __SVCID_H__
+#define __SVCID_H__
+
+#include FT_INTERNAL_SERVICE_H
+
+
+FT_BEGIN_HEADER
+
+
+#define FT_SERVICE_ID_CID  "CID"
+
+  typedef FT_Error
+  (*FT_CID_GetRegistryOrderingSupplementFunc)( FT_Face       face,
+                                               const char*  *registry,
+                                               const char*  *ordering,
+ FT_Int *supplement );
+
+  FT_DEFINE_SERVICE( CID )
+  {
+    FT_CID_GetRegistryOrderingSupplementFunc  get_ros;
+  };
+
+  /* */
+
+
+FT_END_HEADER
+
+
+#endif /* __SVCID_H__ */
+
+
+/* END */
diff -x CVS -urN freetype2/modules.cfg freetype2-working/modules.cfg
--- freetype2/modules.cfg       2007-06-10 21:55:56.00 -0700
+++ freetype2-working/modules.cfg       2007-07-11 13:39:13.00 -0700
@@ -152,6 +152,11 @@
# See include/freetype/ftbdf.h for the API.
BASE_EXTENSIONS += ftbdf.c
+# Access CID font information.
+#
+# See include/freetype/ftcid.h for the API.
+BASE_EXTENSIONS += ftcid.c
+
# Utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp bitmaps into
# 8bpp format, and for emboldening of bitmap glyphs.
#
diff -x CVS -urN freetype2/src/base/ftcid.c freetype2-working/src/ base/ftcid.c
--- freetype2/src/base/ftcid.c  1969-12-31 16:00:00.00 -0800
+++ freetype2-working/src/base/ftcid.c  2007-07-11 13:44:06.00 -0700
@@ -0,0 +1,61 @@
+/ ************************************************************************ ***/ +/ * */ +/* ftcid.c * / +/ * */ +/* FreeType API for accessing CID font information. */ +/ * */ +/* 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. */ +/ * */ +/ ************************************************************************ ***/
+
+
+#include <ft2build.h>
+#include FT_INTERNAL_OBJECTS_H
+#include FT_SERVICE_CID_H
+
+
+  /* documentation is in ftcid.h */
+
+  FT_EXPORT_DEF( FT_Error )
+  FT_Get_CID_Registry_Ordering_Supplement( FT_Face       face,
+                                           const char*  *registry,
+                                           const char*  *ordering,
+                                           FT_Int       *supplement)
+  {
+    FT_Error     error;
+    const char*  r = NULL;
+    const char*  o = NULL;
+    FT_Int       s = 0;
+
+
+    error = FT_Err_Invalid_Argument;
+
+    if ( face )
+    {
+      FT_Service_CID  service;
+
+
+      FT_FACE_FIND_SERVICE( face, service, CID );
+
+      if ( service && service->get_ros )
+         error = service->get_ros( face, &r, &o, &s );
+    }
+
+    if ( registry )
+      *registry = r;
+
+    if ( ordering )
+      *ordering = o;
+
+    if ( supplement )
+      *supplement = s;
+
+    return error;
+  }
+
+
+/* END */
diff -x CVS -urN freetype2/src/cff/cffdrivr.c freetype2-working/src/ cff/cffdrivr.c
--- freetype2/src/cff/cffdrivr.c        2007-07-10 22:32:00.00 -0700
+++ freetype2-working/src/cff/cffdrivr.c        2007-07-13 15:03:56.00 -0700
@@ -22,6 +22,7 @@
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_SFNT_H
#include FT_TRUETYPE_IDS_H
+#include FT_SERVICE_CID_H
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
#include FT_SERVICE_POSTSCRIPT_INFO_H
#include FT_SERVICE_POSTSCRIPT_NAME_H
@@ -420,6 +421,64 @@
   };
+  /*
+   * CID INFO SERVICE
+   *
+   */
+  static FT_Error
+  cff_get_ros( CFF_Face      face,
+               const char*  *registry,
+               const char*  *ordering,
+               FT_Int       *supplement )
+  {
+    FT_Error            error = CFF_Err_Ok;
+    CFF_Font            cff   = (CFF_Font)face->extra.data;
+
+
+    if ( cff )
+    {
+      CFF_FontRecDict     dict    = &cff->top_font.font_dict;
+      FT_Service_PsCMaps  psnames = (FT_Service_PsCMaps)cff->psnames;
+
+      if (dict->cid_registry == 0xFFFFU) {
+       error = CFF_Err_Invalid_Argument;
+       goto Fail;
+      }
+
+      if ( registry )
+      {
+       if ( cff->registry == NULL )
+         cff->registry   = cff_index_get_sid_string( &cff->string_index,
+ dict- >cid_registry,
+                                                      psnames );
+       *registry = cff->registry;
+      }
+
+      if ( ordering )
+      {
+       if ( cff->ordering == NULL )
+ cff->ordering = cff_index_get_sid_string( &cff- >string_index, + dict- >cid_ordering,
+                                                      psnames );
+        *ordering = cff->ordering;
+      }
+
+      if ( supplement )
+        *supplement = dict->cid_supplement;
+
+    }
+
+    Fail:
+      return error;
+  }
+
+
+  static const FT_Service_CIDRec  cff_service_cid_info =
+  {
+    (FT_CID_GetRegistryOrderingSupplementFunc)cff_get_ros
+  };
+
+
/ ************************************************************************ */ / ************************************************************************ */ / ************************************************************************ */
@@ -441,6 +500,7 @@
     { FT_SERVICE_ID_GLYPH_DICT,           &cff_service_glyph_dict },
#endif
{ FT_SERVICE_ID_TT_CMAP, &cff_service_get_cmap_info },
+    { FT_SERVICE_ID_CID,                  &cff_service_cid_info },
     { NULL, NULL }
   };
diff -x CVS -urN freetype2/src/cff/cffload.c freetype2-working/src/ cff/cffload.c
--- freetype2/src/cff/cffload.c 2007-02-12 06:55:03.00 -0800
+++ freetype2-working/src/cff/cffload.c 2007-07-13 14:59:15.00 -0700
@@ -1590,6 +1590,9 @@
       FT_FREE( font->font_info );
     }
+    FT_FREE( font->registry );
+    FT_FREE( font->ordering );
+
     FT_FREE( font->global_subrs );
     FT_FREE( font->font_name );
   }
diff -x CVS -urN freetype2/src/cff/cfftypes.h freetype2-working/src/ cff/cfftypes.h
--- freetype2/src/cff/cfftypes.h        2007-01-13 06:01:36.00 -0800
+++ freetype2-working/src/cff/cfftypes.h        2007-07-13 15:00:04.00 -0700
@@ -259,6 +259,9 @@
     /* since version 2.3.0 */
     PS_FontInfoRec*  font_info;   /* font info dictionary */
+    FT_String*       registry;
+    FT_String*       ordering;
+
   } CFF_FontRec, *CFF_Font;







reply via email to

[Prev in Thread] Current Thread [Next in Thread]