Fixing glyph name typos in glnames.py; more formatting.

This commit is contained in:
Werner Lemberg 2000-06-17 20:15:06 +00:00
parent f9b8dec437
commit 100d6d47d8
5 changed files with 729 additions and 448 deletions

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
#define T2TYPES_H #define T2TYPES_H
#include <freetype/internal/tttypes.h> #include <freetype/freetype.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,44 +1,77 @@
/***************************************************************************/
/* */
/* psdriver.c */
/* */
/* PSNames driver implementation (body). */
/* */
/* Copyright 1996-2000 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. */
/* */
/***************************************************************************/
#include <freetype/internal/psnames.h> #include <freetype/internal/psnames.h>
#include <freetype/internal/ftobjs.h> #include <freetype/internal/ftobjs.h>
#include <psdriver.h> #include <psdriver.h>
#include <stdlib.h>
#include <stdlib.h> /* for qsort() */
#include <string.h> /* for strncpy() */
#ifndef FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES #ifndef FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES
/* see the python script "freetype2/docs/glnames.py" which is used */
/* to generate the following tables... */ /* see the Python script `freetype2/docs/glnames.py' which is used */
/* to generate the following file. */
#include <pstables.h> #include <pstables.h>
#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST #ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
/* return the Unicode value corresponding to a given glyph. Note that */
/* we do deal with glyph variants by detecting a non-initial dot */
/* in the name, as in "A.swash" or "e.final", etc.. */ /* return the Unicode value corresponding to a given glyph. Note that */
/* */ /* we do deal with glyph variants by detecting a non-initial dot in */
/* in the name, as in `A.swash' or `e.final', etc. */
/* */
static static
FT_ULong PS_Unicode_Value( const char* glyph_name ) FT_ULong PS_Unicode_Value( const char* glyph_name )
{ {
FT_Int n; FT_Int n;
char first = glyph_name[0]; char first = glyph_name[0];
char temp[64]; char temp[64];
/* if the name begins with "uni", then the glyph name may be a */
/* hard-coded unicode character code.. */ /* if the name begins with `uni', then the glyph name may be a */
/* hard-coded unicode character code. */
if ( glyph_name[0] == 'u' && if ( glyph_name[0] == 'u' &&
glyph_name[1] == 'n' && glyph_name[1] == 'n' &&
glyph_name[2] == 'i' ) glyph_name[2] == 'i' )
{ {
/* determine wether the following characters are hexadecimal */ /* determine whether the next four characters following are */
FT_Int count; /* hexadecimal. */
FT_ULong value = 0;
const char* p = glyph_name + 4;
for ( count = 4;count > 0; count--, p++ ) /* XXX: Add code to deal with ligatures, i.e. glyph names like */
/* uniXXXXYYYYZZZZ.... */
FT_Int count;
FT_ULong value = 0;
const char* p = glyph_name + 4;
for ( count = 4; count > 0; count--, p++ )
{ {
char c = *p; char c = *p;
unsigned char d; unsigned char d;
d = (unsigned char)c-'0';
if (d >= 10) d = (unsigned char)c - '0';
if ( d >= 10 )
{ {
d = (unsigned char)c - 'A'; d = (unsigned char)c - 'A';
if ( d >= 6 ) if ( d >= 6 )
@ -46,25 +79,31 @@
else else
d += 10; d += 10;
} }
/* exit if one non-uppercase-hexadecimal character was found */
if (d >= 16) /* exit if a non-uppercase hexadecimal character was found */
if ( d >= 16 )
break; break;
value = (value << 4) + d; value = ( value << 4 ) + d;
if (count == 0)
if ( count == 0 )
return value; return value;
} }
} }
/* look for a non-initial dot in the glyph name in order to */ /* look for a non-initial dot in the glyph name in order to */
/* sort-out variants like "A.swash", "e.final", etc.. */ /* sort-out variants like `A.swash', `e.final', etc. */
{ {
const char* p; const char* p;
int len; int len;
p = glyph_name; p = glyph_name;
while ( *p && *p != '.' ) p++;
len = p-glyph_name; while ( *p && *p != '.' )
p++;
len = p - glyph_name;
if ( *p && len < 64 ) if ( *p && len < 64 )
{ {
@ -74,40 +113,45 @@
} }
} }
/* now, lookup the glyph in the Adobe Glyph List */ /* now, look up the glyph in the Adobe Glyph List */
for ( n = 0; n < NUM_ADOBE_GLYPHS; n++ ) for ( n = 0; n < NUM_ADOBE_GLYPHS; n++ )
{ {
const char* name = t1_standard_glyphs[n]; const char* name = t1_standard_glyphs[n];
if ( first == name[0] && strcmp( glyph_name, name ) == 0 ) if ( first == name[0] && strcmp( glyph_name, name ) == 0 )
return names_to_unicode[n]; return names_to_unicode[n];
} }
/* not found, there is probably no Unicode value for this glyph name */ /* not found, there is probably no Unicode value for this glyph name */
return 0; return 0;
} }
/* qsort callback to sort the unicode map */ /* qsort callback to sort the unicode map */
static static
int compare_uni_maps( const void* a, const void* b ) int compare_uni_maps( const void* a,
const void* b )
{ {
PS_UniMap* map1 = (PS_UniMap*)a; PS_UniMap* map1 = (PS_UniMap*)a;
PS_UniMap* map2 = (PS_UniMap*)b; PS_UniMap* map2 = (PS_UniMap*)b;
return ( map1->unicode < map2->unicode ? -1 : return ( map1->unicode < map2->unicode ? -1 :
map1->unicode > map2->unicode ? 1 : 0 ); map1->unicode > map2->unicode ? 1 : 0 );
} }
/* Builds a table that maps Unicode values to glyph indices */ /* Builds a table that maps Unicode values to glyph indices */
static static
FT_Error PS_Build_Unicode_Table( FT_Memory memory, FT_Error PS_Build_Unicode_Table( FT_Memory memory,
FT_UInt num_glyphs, FT_UInt num_glyphs,
const char** glyph_names, const char** glyph_names,
PS_Unicodes *table ) PS_Unicodes* table )
{ {
FT_Error error; FT_Error error;
/* we first allocate the table */ /* we first allocate the table */
table->num_maps = 0; table->num_maps = 0;
table->maps = 0; table->maps = 0;
@ -119,14 +163,19 @@
PS_UniMap* map; PS_UniMap* map;
FT_ULong uni_char; FT_ULong uni_char;
map = table->maps; map = table->maps;
for ( n = 0; n < num_glyphs; n++ ) for ( n = 0; n < num_glyphs; n++ )
{ {
const char* gname = glyph_names[n]; const char* gname = glyph_names[n];
if (gname)
if ( gname )
{ {
uni_char = PS_Unicode_Value(gname); uni_char = PS_Unicode_Value( gname );
if (uni_char && uni_char != 0xFFFF)
if ( uni_char && uni_char != 0xFFFF )
{ {
map->unicode = uni_char; map->unicode = uni_char;
map->glyph_index = n; map->glyph_index = n;
@ -137,85 +186,100 @@
/* now, compress the table a bit */ /* now, compress the table a bit */
count = map - table->maps; count = map - table->maps;
if ( count > 0 && REALLOC( table->maps, if ( count > 0 && REALLOC( table->maps,
num_glyphs*sizeof(PS_UniMap), num_glyphs * sizeof ( PS_UniMap ),
count*sizeof(PS_UniMap) ) ) count * sizeof ( PS_UniMap ) ) )
{ {
count = 0; count = 0;
} }
if (count == 0) if ( count == 0 )
{ {
FREE( table->maps ); FREE( table->maps );
if (!error) if ( !error )
error = FT_Err_Invalid_Argument; /* no unicode chars here !! */ error = FT_Err_Invalid_Argument; /* no unicode chars here! */
} }
else else
/* sort the table in increasing order of unicode values */ /* sort the table in increasing order of unicode values */
qsort( table->maps, count, sizeof(PS_UniMap), compare_uni_maps ); qsort( table->maps, count, sizeof ( PS_UniMap ), compare_uni_maps );
table->num_maps = count; table->num_maps = count;
} }
return error; return error;
} }
static static
FT_UInt PS_Lookup_Unicode( PS_Unicodes* table, FT_UInt PS_Lookup_Unicode( PS_Unicodes* table,
FT_ULong unicode ) FT_ULong unicode )
{ {
PS_UniMap *min, *max, *mid; PS_UniMap *min, *max, *mid;
/* perform a binary search on the table */ /* perform a binary search on the table */
min = table->maps; min = table->maps;
max = min + table->num_maps - 1; max = min + table->num_maps - 1;
while (min <= max) while ( min <= max )
{ {
mid = min + (max-min)/2; mid = min + ( max - min ) / 2;
if ( mid->unicode == unicode ) if ( mid->unicode == unicode )
return mid->glyph_index; return mid->glyph_index;
if (min == max) if ( min == max )
break; break;
if ( mid->unicode < unicode ) min = mid+1; if ( mid->unicode < unicode )
else max = mid-1; min = mid + 1;
else
max = mid - 1;
} }
return 0xFFFF; return 0xFFFF;
} }
#endif
#endif /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */
static static
const char* PS_Macintosh_Name( FT_UInt name_index ) const char* PS_Macintosh_Name( FT_UInt name_index )
{ {
if (name_index >= 258) if ( name_index >= 258 )
name_index = 0; name_index = 0;
return standard_glyph_names[ mac_standard_names[name_index] ]; return standard_glyph_names[mac_standard_names[name_index]];
} }
static static
const char* PS_Standard_Strings( FT_UInt sid ) const char* PS_Standard_Strings( FT_UInt sid )
{ {
return (sid < NUM_STD_GLYPHS ? t1_standard_glyphs[sid] : 0); return ( sid < NUM_STD_GLYPHS ? t1_standard_glyphs[sid] : 0 );
} }
static const PSNames_Interface psnames_interface = static const PSNames_Interface psnames_interface =
{ {
#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST #ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
(PS_Unicode_Value_Func) PS_Unicode_Value,
(PS_Build_Unicodes_Func) PS_Build_Unicode_Table,
(PS_Lookup_Unicode_Func) PS_Lookup_Unicode,
#else
0,
0,
0,
#endif
(PS_Macintosh_Name_Func) PS_Macintosh_Name, (PS_Unicode_Value_Func) PS_Unicode_Value,
(PS_Adobe_Std_Strings_Func) PS_Standard_Strings, (PS_Build_Unicodes_Func) PS_Build_Unicode_Table,
(PS_Lookup_Unicode_Func) PS_Lookup_Unicode,
#else
0,
0,
0,
#endif /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */
(PS_Macintosh_Name_Func) PS_Macintosh_Name,
(PS_Adobe_Std_Strings_Func)PS_Standard_Strings,
t1_standard_encoding, t1_standard_encoding,
t1_expert_encoding t1_expert_encoding
@ -224,7 +288,7 @@
const FT_DriverInterface psnames_driver_interface = const FT_DriverInterface psnames_driver_interface =
{ {
sizeof(FT_DriverRec), sizeof( FT_DriverRec ),
0, 0,
0, 0,
0, 0,
@ -240,7 +304,7 @@
0, 0, 0, 0,
}; };
#else #else /* FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES */
const FT_DriverInterface psnames_driver_interface = const FT_DriverInterface psnames_driver_interface =
{ {
@ -258,3 +322,5 @@
#endif /* !FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES */ #endif /* !FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES */
/* END */

View File

@ -4,7 +4,7 @@
/* */ /* */
/* High-level PSNames driver interface (specification). */ /* High-level PSNames driver interface (specification). */
/* */ /* */
/* Copyright 1996-1999 by */ /* Copyright 1996-2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -19,9 +19,11 @@
#ifndef PSDRIVER_H #ifndef PSDRIVER_H
#define PSDRIVER_H #define PSDRIVER_H
#include <freetype/internal/ftdriver.h> #include <freetype/internal/ftdriver.h>
FT_EXPORT_VAR(const FT_DriverInterface) psnames_driver_interface; FT_EXPORT_VAR( const FT_DriverInterface ) psnames_driver_interface;
#endif /* PSDRIVER_H */ #endif /* PSDRIVER_H */

View File

@ -1,2 +1,23 @@
/***************************************************************************/
/* */
/* psnames.c */
/* */
/* FreeType PSNames driver component (body only). */
/* */
/* Copyright 1996-2000 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. */
/* */
/***************************************************************************/
#define FT_MAKE_OPTION_SINGLE_OBJECT #define FT_MAKE_OPTION_SINGLE_OBJECT
#include <psdriver.c> #include <psdriver.c>
/* END */