implementing a new function named "FT_Get_Postscript_Name" to retrieve a face's "unique" Postscript name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
diff --git a/ChangeLog b/ChangeLog
index 717ecee..4a769a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,11 @@
2001-10-17 David Turner >david@freetype.org>
- Tagging files with VER-2-0-5 for upcoming 2.0.5 release
- Testing new CVS-mail script (thanks Just !)
+ * include/freetype/freetype.h, include/internal/ftobjs.h,
+ src/base/ftobjs.c, src/sfnt/sfdriver.c, type1/t1driver.c,
+ cid/cidriver.c: Adding a new function named 'FT_Get_Postscript_Name' to
+ retrieve the Postscript name of a given font. Should work with all
+ formats except pure CFF/CEF fonts (this will be added soon).
+
2001-10-08 David Turner <david@freetype.org>
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 2524f8b..41d6f60 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -2289,6 +2289,30 @@ FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Function> */
+ /* FT_Get_Postscript_Name */
+ /* */
+ /* <Description> */
+ /* Retrieves the ASCII Postscript name of a given face, when */
+ /* available. This should only work with Postscript and TrueType */
+ /* fonts.. */
+ /* */
+ /* <Input> */
+ /* face :: handle to source face object. */
+ /* */
+ /* <Return> */
+ /* pointer to face's Postscript name. NULL when un-available */
+ /* */
+ /* <Note> */
+ /* The returned pointer is owned by the face and will be destroyed */
+ /* with it. */
+ /* */
+ FT_EXPORT( const char* )
+ FT_Get_Postscript_Name( FT_Face face );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
/* FT_Select_Charmap */
/* */
/* <Description> */
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index f316efe..9608ace 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -129,14 +129,18 @@ FT_BEGIN_HEADER
/* transform_flags :: Some flags used to classify the transform. */
/* Only used by the convenience functions. */
/* */
+ /* postscript_name :: Postscript font name for this face. */
+ /* */
typedef struct FT_Face_InternalRec_
{
- FT_UShort max_points;
- FT_Short max_contours;
+ FT_UShort max_points;
+ FT_Short max_contours;
+
+ FT_Matrix transform_matrix;
+ FT_Vector transform_delta;
+ FT_Int transform_flags;
- FT_Matrix transform_matrix;
- FT_Vector transform_delta;
- FT_Int transform_flags;
+ const char* postscript_name;
} FT_Face_InternalRec;
@@ -628,6 +632,9 @@ FT_BEGIN_HEADER
FT_GlyphSlot slot,
FT_UInt render_mode );
+ typedef const char*
+ (*FT_PSName_Requester)( FT_Face face );
+
typedef FT_Error
(*FT_Glyph_Name_Requester)( FT_Face face,
FT_UInt glyph_index,
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 226a7c8..b4ec9b6 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1011,8 +1011,8 @@
if ( face->autohint.finalizer )
face->autohint.finalizer( face->autohint.data );
- /* Discard glyph slots for this face */
- /* Beware! FT_Done_GlyphSlot() changes the field `face->slot' */
+ /* Discard glyph slots for this face */
+ /* Beware! FT_Done_GlyphSlot() changes the field `face->glyph' */
while ( face->glyph )
FT_Done_GlyphSlot( face->glyph );
@@ -1037,7 +1037,11 @@
( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
/* get rid of it */
- FREE( face->internal );
+ if ( face->internal )
+ {
+ FREE( face->internal->postscript_name );
+ FREE( face->internal );
+ }
FREE( face );
}
@@ -1906,6 +1910,38 @@
}
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( const char* )
+ FT_Get_Postscript_Name( FT_Face face )
+ {
+ const char* result = NULL;
+
+ if ( !face )
+ goto Exit;
+
+ result = face->internal->postscript_name;
+ if ( !result )
+ {
+ /* now, lookup for glyph name */
+ FT_Driver driver = face->driver;
+ FT_Module_Class* clazz = FT_MODULE_CLASS( driver );
+
+ if ( clazz->get_interface )
+ {
+ FT_PSName_Requester requester;
+
+ requester = (FT_PSName_Requester)clazz->get_interface(
+ FT_MODULE( driver ), "postscript_name" );
+ if ( requester )
+ result = requester( face );
+ }
+ }
+ Exit:
+ return result;
+ }
+
+
/* documentation is in tttables.h */
FT_EXPORT_DEF( void* )
diff --git a/src/cid/cidriver.c b/src/cid/cidriver.c
index 33a39d8..8de7852 100644
--- a/src/cid/cidriver.c
+++ b/src/cid/cidriver.c
@@ -38,6 +38,14 @@
#define FT_COMPONENT trace_ciddriver
+
+ static const char*
+ cid_get_postscript_name( CID_Face face )
+ {
+ return (const char*)face->cid.cid_font_name;
+ }
+
+
static FT_Module_Interface
CID_Get_Interface( FT_Driver driver,
const FT_String* interface )
@@ -45,6 +53,9 @@
FT_UNUSED( driver );
FT_UNUSED( interface );
+ if ( strcmp( (const char*)interface, "postscript_name" ) == 0 )
+ return (FT_Module_Interface)cid_get_postscript_name;
+
return 0;
}
@@ -174,6 +185,7 @@
}
+
FT_CALLBACK_TABLE_DEF
const FT_Driver_Class t1cid_driver_class =
{
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 086bccc..3104564 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -111,6 +111,52 @@
}
+ static const char*
+ get_sfnt_postscript_name( TT_Face face )
+ {
+ FT_Int n;
+
+ /* shouldn't happen, but just in case to avoid memory leaks */
+ if ( face->root.internal->postscript_name )
+ return face->root.internal->postscript_name;
+
+ /* scan the name table to see if we have a Postscript name here, either */
+ /* in Macintosh or Windows platform encodings.. */
+ for ( n = 0; n < face->num_names; n++ )
+ {
+ TT_NameRec* name = face->name_table.names + n;
+
+ if ( name->nameID == 6 )
+ {
+ if ( ( name->platformID == 3 &&
+ name->encodingID == 1 &&
+ name->languageID == 0x409 ) ||
+
+ ( name->platformID == 1 &&
+ name->encodingID == 0 &&
+ name->languageID == 0 ) )
+ {
+ FT_UInt len = name->stringLength;
+ FT_Error error;
+ FT_Memory memory = face->root.memory;
+ FT_String* result;
+
+ if ( !ALLOC( result, len+1 ) )
+ {
+ memcpy( result, name->string, len );
+ result[len] = '\0';
+
+ face->root.internal->postscript_name = result;
+ }
+ return result;
+ }
+ }
+ }
+
+ return NULL;
+ }
+
+
#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
@@ -127,6 +173,10 @@
if ( strcmp( interface, "glyph_name" ) == 0 )
return (FT_Module_Interface)get_sfnt_glyph_name;
#endif
+
+ if ( strcmp( interface, "postscript_name" ) == 0 )
+ return (FT_Module_Interface)get_sfnt_postscript_name;
+
return 0;
}
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index 40a1d38..49be9f6 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -108,6 +108,13 @@
}
+ static const char*
+ t1_get_ps_name( T1_Face face )
+ {
+ return (const char*) face->type1.font_name;
+ }
+
+
/*************************************************************************/
/* */
/* <Function> */
@@ -148,6 +155,9 @@
if ( strcmp( (const char*)interface, "name_index" ) == 0 )
return (FT_Module_Interface)t1_get_name_index;
+ if ( strcmp( (const char*)interface, "postscript_name" ) == 0 )
+ return (FT_Module_Interface)t1_get_ps_name;
+
#ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
if ( strcmp( (const char*)interface, "get_mm" ) == 0 )
return (FT_Module_Interface)T1_Get_Multi_Master;