38#define DEFINE_PS_TABLES
39#define DEFINE_PS_TABLES_DATA
45#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES
48#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
51#define VARIANT_BIT 0x80000000UL
52#define BASE_GLYPH( code ) ( (FT_UInt32)( (code) & ~VARIANT_BIT ) )
60 FT_CALLBACK_DEF( FT_UInt32 )
61 ps_unicode_value(
const char* glyph_name )
65 if ( glyph_name[0] ==
'u' &&
66 glyph_name[1] ==
'n' &&
67 glyph_name[2] ==
'i' )
77 const char* p = glyph_name + 3;
80 for ( count = 4; count > 0; count--, p++ )
86 d = (
unsigned char)c -
'0';
89 d = (
unsigned char)c -
'A';
102 value = ( value << 4 ) + d;
111 return (FT_UInt32)( value | VARIANT_BIT );
117 if ( glyph_name[0] ==
'u' )
121 const char* p = glyph_name + 1;
124 for ( count = 6; count > 0; count--, p++ )
130 d = (
unsigned char)c -
'0';
133 d = (
unsigned char)c -
'A';
143 value = ( value << 4 ) + d;
151 return (FT_UInt32)( value | VARIANT_BIT );
159 const char* p = glyph_name;
162 for ( ; *p && *p !=
'.'; p++ )
167 if ( p > glyph_name )
169 value = (FT_UInt32)ft_get_adobe_glyph_index( glyph_name, p );
172 value |= (FT_UInt32)VARIANT_BIT;
181 FT_COMPARE_DEF(
int )
182 compare_uni_maps(
const void* a,
185 PS_UniMap* map1 = (PS_UniMap*)a;
186 PS_UniMap* map2 = (PS_UniMap*)b;
187 FT_UInt32 unicode1 = BASE_GLYPH( map1->unicode );
188 FT_UInt32 unicode2 = BASE_GLYPH( map2->unicode );
192 if ( unicode1 == unicode2 )
194 if ( map1->unicode > map2->unicode )
196 else if ( map1->unicode < map2->unicode )
203 if ( unicode1 > unicode2 )
205 else if ( unicode1 < unicode2 )
216#define EXTRA_GLYPH_LIST_SIZE 10
218 static const FT_UInt32 ft_extra_glyph_unicodes[EXTRA_GLYPH_LIST_SIZE] =
234 static const char ft_extra_glyph_names[] =
236 'D',
'e',
'l',
't',
'a',0,
237 'O',
'm',
'e',
'g',
'a',0,
238 'f',
'r',
'a',
'c',
't',
'i',
'o',
'n',0,
239 'h',
'y',
'p',
'h',
'e',
'n',0,
240 'm',
'a',
'c',
'r',
'o',
'n',0,
242 'p',
'e',
'r',
'i',
'o',
'd',
'c',
'e',
'n',
't',
'e',
'r',
'e',
'd',0,
243 's',
'p',
'a',
'c',
'e',0,
244 'T',
'c',
'o',
'm',
'm',
'a',
'a',
'c',
'c',
'e',
'n',
't',0,
245 't',
'c',
'o',
'm',
'm',
'a',
'a',
'c',
'c',
'e',
'n',
't',0
249 ft_extra_glyph_name_offsets[EXTRA_GLYPH_LIST_SIZE] =
265 ps_check_extra_glyph_name(
const char* gname,
267 FT_UInt* extra_glyphs,
273 for ( n = 0; n < EXTRA_GLYPH_LIST_SIZE; n++ )
275 if ( ft_strcmp( ft_extra_glyph_names +
276 ft_extra_glyph_name_offsets[n], gname ) == 0 )
278 if ( states[n] == 0 )
282 extra_glyphs[n] = glyph;
292 ps_check_extra_glyph_unicode( FT_UInt32 uni_char,
298 for ( n = 0; n < EXTRA_GLYPH_LIST_SIZE; n++ )
300 if ( uni_char == ft_extra_glyph_unicodes[n] )
312 FT_CALLBACK_DEF( FT_Error )
313 ps_unicodes_init( FT_Memory memory,
316 PS_GetGlyphNameFunc get_glyph_name,
317 PS_FreeGlyphNameFunc free_glyph_name,
318 FT_Pointer glyph_data )
322 FT_UInt extra_glyph_list_states[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
323 FT_UInt extra_glyphs[EXTRA_GLYPH_LIST_SIZE];
329 if ( !FT_QNEW_ARRAY( table->maps, num_glyphs + EXTRA_GLYPH_LIST_SIZE ) )
339 for ( n = 0; n < num_glyphs; n++ )
341 const char* gname = get_glyph_name( glyph_data, n );
344 if ( gname && *gname )
346 ps_check_extra_glyph_name( gname, n,
347 extra_glyphs, extra_glyph_list_states );
348 uni_char = ps_unicode_value( gname );
350 if ( BASE_GLYPH( uni_char ) != 0 )
352 ps_check_extra_glyph_unicode( uni_char,
353 extra_glyph_list_states );
354 map->unicode = uni_char;
355 map->glyph_index = n;
359 if ( free_glyph_name )
360 free_glyph_name( glyph_data, gname );
364 for ( n = 0; n < EXTRA_GLYPH_LIST_SIZE; n++ )
366 if ( extra_glyph_list_states[n] == 1 )
371 map->unicode = ft_extra_glyph_unicodes[n];
372 map->glyph_index = extra_glyphs[n];
378 count = (FT_UInt)( map - table->maps );
383 FT_FREE( table->maps );
385 error = FT_THROW( No_Unicode_Glyph_Name );
390 if ( count < num_glyphs / 2 )
392 FT_MEM_QRENEW_ARRAY( table->maps,
393 num_glyphs + EXTRA_GLYPH_LIST_SIZE,
400 ft_qsort( table->maps, count, sizeof ( PS_UniMap ),
404 table->num_maps = count;
411 FT_CALLBACK_DEF( FT_UInt )
412 ps_unicodes_char_index( PS_Unicodes table,
415 PS_UniMap *result = NULL;
416 PS_UniMap *min = table->maps;
417 PS_UniMap *max = min + table->num_maps;
418 PS_UniMap *mid = min + ( ( max - min ) >> 1 );
424 FT_UInt32 base_glyph;
427 if ( mid->unicode == unicode )
433 base_glyph = BASE_GLYPH( mid->unicode );
435 if ( base_glyph == unicode )
438 if ( base_glyph < unicode )
444 mid += unicode - base_glyph;
445 if ( mid >= max || mid < min )
446 mid = min + ( ( max - min ) >> 1 );
450 return result->glyph_index;
456 FT_CALLBACK_DEF( FT_UInt )
457 ps_unicodes_char_next( PS_Unicodes table,
461 FT_UInt32 char_code = *unicode + 1;
466 FT_UInt max = table->num_maps;
467 FT_UInt mid = min + ( ( max - min ) >> 1 );
469 FT_UInt32 base_glyph;
474 map = table->maps + mid;
476 if ( map->unicode == char_code )
478 result = map->glyph_index;
482 base_glyph = BASE_GLYPH( map->unicode );
484 if ( base_glyph == char_code )
485 result = map->glyph_index;
487 if ( base_glyph < char_code )
493 mid += char_code - base_glyph;
494 if ( mid >= max || mid < min )
495 mid = min + ( max - min ) / 2;
504 if ( min < table->num_maps )
506 map = table->maps + min;
507 result = map->glyph_index;
508 char_code = BASE_GLYPH( map->unicode );
513 *unicode = char_code;
521 FT_CALLBACK_DEF(
const char* )
522 ps_get_macintosh_name( FT_UInt name_index )
524 if ( name_index >= FT_NUM_MAC_NAMES )
527 return ft_standard_glyph_names + ft_mac_names[name_index];
531 FT_CALLBACK_DEF(
const char* )
532 ps_get_standard_strings( FT_UInt sid )
534 if ( sid >= FT_NUM_SID_NAMES )
537 return ft_standard_glyph_names + ft_sid_names[sid];
541#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
543 FT_DEFINE_SERVICE_PSCMAPSREC(
548 ps_unicodes_char_index,
549 ps_unicodes_char_next,
551 ps_get_macintosh_name,
552 ps_get_standard_strings,
554 t1_standard_encoding,
560 FT_DEFINE_SERVICE_PSCMAPSREC(
568 ps_get_macintosh_name,
569 ps_get_standard_strings,
571 t1_standard_encoding,
578 FT_DEFINE_SERVICEDESCREC1(
581 FT_SERVICE_ID_POSTSCRIPT_CMAPS, &pscmaps_interface )
585 psnames_get_service( FT_Module module,
586 const char* service_id )
590 return ft_service_list_lookup( pscmaps_services, service_id );
596#ifndef FT_CONFIG_OPTION_POSTSCRIPT_NAMES
597#define PUT_PS_NAMES_SERVICE( a ) NULL
599#define PUT_PS_NAMES_SERVICE( a ) a
603 psnames_module_class,
606 sizeof ( FT_ModuleRec ),
612 PUT_PS_NAMES_SERVICE(
613 (
void*)&pscmaps_interface ),
617 PUT_PS_NAMES_SERVICE( psnames_get_service )