1 /***************************************************************************/ 2 /* */ 3 /* ttpost.c */ 4 /* */ 5 /* PostScript name table processing for TrueType and OpenType fonts */ 6 /* (body). */ 7 /* */ 8 /* Copyright 1996-2018 by */ 9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 10 /* */ 11 /* This file is part of the FreeType project, and may only be used, */ 12 /* modified, and distributed under the terms of the FreeType project */ 13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 14 /* this file you indicate that you have read the license and */ 15 /* understand and accept it fully. */ 16 /* */ 17 /***************************************************************************/ 18 19 /*************************************************************************/ 20 /* */ 21 /* The post table is not completely loaded by the core engine. This */ 22 /* file loads the missing PS glyph names and implements an API to access */ 23 /* them. */ 24 /* */ 25 /*************************************************************************/ 26 27 28 #include <ft2build.h> 29 #include FT_INTERNAL_DEBUG_H 30 #include FT_INTERNAL_STREAM_H 31 #include FT_TRUETYPE_TAGS_H 32 33 34 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES 35 36 #include "ttpost.h" 37 38 #include "sferrors.h" 39 40 41 /*************************************************************************/ 42 /* */ 43 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 44 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 45 /* messages during execution. */ 46 /* */ 47 #undef FT_COMPONENT 48 #define FT_COMPONENT trace_ttpost 49 50 51 /* If this configuration macro is defined, we rely on the `PSNames' */ 52 /* module to grab the glyph names. */ 53 54 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES 55 56 57 #include FT_SERVICE_POSTSCRIPT_CMAPS_H 58 59 #define MAC_NAME( x ) (FT_String*)psnames->macintosh_name( (FT_UInt)(x) ) 60 61 62 #else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ 63 64 65 /* Otherwise, we ignore the `PSNames' module, and provide our own */ 66 /* table of Mac names. Thus, it is possible to build a version of */ 67 /* FreeType without the Type 1 driver & PSNames module. */ 68 69 #define MAC_NAME( x ) (FT_String*)tt_post_default_names[x] 70 71 /* the 258 default Mac PS glyph names; see file `tools/glnames.py' */ 72 73 static const FT_String* const tt_post_default_names[258] = 74 { 75 /* 0 */ 76 ".notdef", ".null", "nonmarkingreturn", "space", "exclam", 77 "quotedbl", "numbersign", "dollar", "percent", "ampersand", 78 /* 10 */ 79 "quotesingle", "parenleft", "parenright", "asterisk", "plus", 80 "comma", "hyphen", "period", "slash", "zero", 81 /* 20 */ 82 "one", "two", "three", "four", "five", 83 "six", "seven", "eight", "nine", "colon", 84 /* 30 */ 85 "semicolon", "less", "equal", "greater", "question", 86 "at", "A", "B", "C", "D", 87 /* 40 */ 442 443 for ( n = 0; n < table->num_names; n++ ) 444 FT_FREE( table->glyph_names[n] ); 445 446 FT_FREE( table->glyph_names ); 447 table->num_names = 0; 448 } 449 else if ( format == 0x00025000L ) 450 { 451 TT_Post_25 table = &names->names.format_25; 452 453 454 FT_FREE( table->offsets ); 455 table->num_glyphs = 0; 456 } 457 } 458 names->loaded = 0; 459 } 460 461 462 /*************************************************************************/ 463 /* */ 464 /* <Function> */ 465 /* tt_face_get_ps_name */ 466 /* */ 467 /* <Description> */ 468 /* Get the PostScript glyph name of a glyph. */ 469 /* */ 470 /* <Input> */ 471 /* face :: A handle to the parent face. */ 472 /* */ 473 /* idx :: The glyph index. */ 474 /* */ 475 /* <InOut> */ 476 /* PSname :: The address of a string pointer. Undefined in case of */ 477 /* error, otherwise it is a pointer to the glyph name. */ 478 /* */ 479 /* You must not modify the returned string! */ 480 /* */ 481 /* <Output> */ 482 /* FreeType error code. 0 means success. */ 483 /* */ 484 FT_LOCAL_DEF( FT_Error ) 485 tt_face_get_ps_name( TT_Face face, 486 FT_UInt idx, 487 FT_String** PSname ) 488 { 489 FT_Error error; 490 TT_Post_Names names; 491 FT_Fixed format; 492 493 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES 494 FT_Service_PsCMaps psnames; 495 #endif 496 497 498 if ( !face ) 499 return FT_THROW( Invalid_Face_Handle ); 500 501 if ( idx >= (FT_UInt)face->max_profile.numGlyphs ) 502 return FT_THROW( Invalid_Glyph_Index ); 503 | 1 /**************************************************************************** 2 * 3 * ttpost.c 4 * 5 * PostScript name table processing for TrueType and OpenType fonts 6 * (body). 7 * 8 * Copyright (C) 1996-2019 by 9 * David Turner, Robert Wilhelm, and Werner Lemberg. 10 * 11 * This file is part of the FreeType project, and may only be used, 12 * modified, and distributed under the terms of the FreeType project 13 * license, LICENSE.TXT. By continuing to use, modify, or distribute 14 * this file you indicate that you have read the license and 15 * understand and accept it fully. 16 * 17 */ 18 19 /************************************************************************** 20 * 21 * The post table is not completely loaded by the core engine. This 22 * file loads the missing PS glyph names and implements an API to access 23 * them. 24 * 25 */ 26 27 28 #include <ft2build.h> 29 #include FT_INTERNAL_DEBUG_H 30 #include FT_INTERNAL_STREAM_H 31 #include FT_TRUETYPE_TAGS_H 32 33 34 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES 35 36 #include "ttpost.h" 37 38 #include "sferrors.h" 39 40 41 /************************************************************************** 42 * 43 * The macro FT_COMPONENT is used in trace mode. It is an implicit 44 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log 45 * messages during execution. 46 */ 47 #undef FT_COMPONENT 48 #define FT_COMPONENT ttpost 49 50 51 /* If this configuration macro is defined, we rely on the `psnames' */ 52 /* module to grab the glyph names. */ 53 54 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES 55 56 57 #include FT_SERVICE_POSTSCRIPT_CMAPS_H 58 59 #define MAC_NAME( x ) (FT_String*)psnames->macintosh_name( (FT_UInt)(x) ) 60 61 62 #else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ 63 64 65 /* Otherwise, we ignore the `psnames' module, and provide our own */ 66 /* table of Mac names. Thus, it is possible to build a version of */ 67 /* FreeType without the Type 1 driver & psnames module. */ 68 69 #define MAC_NAME( x ) (FT_String*)tt_post_default_names[x] 70 71 /* the 258 default Mac PS glyph names; see file `tools/glnames.py' */ 72 73 static const FT_String* const tt_post_default_names[258] = 74 { 75 /* 0 */ 76 ".notdef", ".null", "nonmarkingreturn", "space", "exclam", 77 "quotedbl", "numbersign", "dollar", "percent", "ampersand", 78 /* 10 */ 79 "quotesingle", "parenleft", "parenright", "asterisk", "plus", 80 "comma", "hyphen", "period", "slash", "zero", 81 /* 20 */ 82 "one", "two", "three", "four", "five", 83 "six", "seven", "eight", "nine", "colon", 84 /* 30 */ 85 "semicolon", "less", "equal", "greater", "question", 86 "at", "A", "B", "C", "D", 87 /* 40 */ 442 443 for ( n = 0; n < table->num_names; n++ ) 444 FT_FREE( table->glyph_names[n] ); 445 446 FT_FREE( table->glyph_names ); 447 table->num_names = 0; 448 } 449 else if ( format == 0x00025000L ) 450 { 451 TT_Post_25 table = &names->names.format_25; 452 453 454 FT_FREE( table->offsets ); 455 table->num_glyphs = 0; 456 } 457 } 458 names->loaded = 0; 459 } 460 461 462 /************************************************************************** 463 * 464 * @Function: 465 * tt_face_get_ps_name 466 * 467 * @Description: 468 * Get the PostScript glyph name of a glyph. 469 * 470 * @Input: 471 * face :: 472 * A handle to the parent face. 473 * 474 * idx :: 475 * The glyph index. 476 * 477 * @InOut: 478 * PSname :: 479 * The address of a string pointer. Undefined in case of 480 * error, otherwise it is a pointer to the glyph name. 481 * 482 * You must not modify the returned string! 483 * 484 * @Output: 485 * FreeType error code. 0 means success. 486 */ 487 FT_LOCAL_DEF( FT_Error ) 488 tt_face_get_ps_name( TT_Face face, 489 FT_UInt idx, 490 FT_String** PSname ) 491 { 492 FT_Error error; 493 TT_Post_Names names; 494 FT_Fixed format; 495 496 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES 497 FT_Service_PsCMaps psnames; 498 #endif 499 500 501 if ( !face ) 502 return FT_THROW( Invalid_Face_Handle ); 503 504 if ( idx >= (FT_UInt)face->max_profile.numGlyphs ) 505 return FT_THROW( Invalid_Glyph_Index ); 506 |