Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* cidload.c */ |
| 4 | /* */ |
| 5 | /* CID-keyed Type1 font loader (body). */ |
| 6 | /* */ |
Werner Lemberg | 22ad9ef | 2005-05-09 22:11:36 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001, 2002, 2003, 2004, 2005 by */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
| 10 | /* This file is part of the FreeType project, and may only be used, */ |
| 11 | /* modified, and distributed under the terms of the FreeType project */ |
| 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 | /* this file you indicate that you have read the license and */ |
| 14 | /* understand and accept it fully. */ |
| 15 | /* */ |
| 16 | /***************************************************************************/ |
| 17 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 18 | |
| 19 | #include <ft2build.h> |
| 20 | #include FT_INTERNAL_DEBUG_H |
| 21 | #include FT_CONFIG_CONFIG_H |
| 22 | #include FT_MULTIPLE_MASTERS_H |
| 23 | #include FT_INTERNAL_TYPE1_TYPES_H |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 24 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 25 | #include "cidload.h" |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 26 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 27 | #include "ciderrs.h" |
| 28 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 29 | |
| 30 | /*************************************************************************/ |
| 31 | /* */ |
| 32 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 33 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 34 | /* messages during execution. */ |
| 35 | /* */ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 36 | #undef FT_COMPONENT |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 37 | #define FT_COMPONENT trace_cidload |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 38 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 39 | |
Werner Lemberg | ac39ecd | 2000-06-30 22:24:36 +0000 | [diff] [blame] | 40 | /* read a single offset */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 41 | FT_LOCAL_DEF( FT_Long ) |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 42 | cid_get_offset( FT_Byte* *start, |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 43 | FT_Byte offsize ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 44 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 45 | FT_Long result; |
| 46 | FT_Byte* p = *start; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 47 | |
| 48 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 49 | for ( result = 0; offsize > 0; offsize-- ) |
Werner Lemberg | ac39ecd | 2000-06-30 22:24:36 +0000 | [diff] [blame] | 50 | { |
| 51 | result <<= 8; |
| 52 | result |= *p++; |
| 53 | } |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 54 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 55 | *start = p; |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 60 | /*************************************************************************/ |
| 61 | /*************************************************************************/ |
| 62 | /***** *****/ |
| 63 | /***** TYPE 1 SYMBOL PARSING *****/ |
| 64 | /***** *****/ |
| 65 | /*************************************************************************/ |
| 66 | /*************************************************************************/ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 67 | |
| 68 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 69 | static FT_Error |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 70 | cid_load_keyword( CID_Face face, |
| 71 | CID_Loader* loader, |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 72 | const T1_Field keyword ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 73 | { |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 74 | FT_Error error; |
| 75 | CID_Parser* parser = &loader->parser; |
| 76 | FT_Byte* object; |
| 77 | void* dummy_object; |
| 78 | CID_FaceInfo cid = &face->cid; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 79 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 80 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 81 | /* if the keyword has a dedicated callback, call it */ |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 82 | if ( keyword->type == T1_FIELD_TYPE_CALLBACK ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 83 | { |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 84 | keyword->reader( (FT_Face)face, parser ); |
| 85 | error = parser->root.error; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 86 | goto Exit; |
| 87 | } |
| 88 | |
| 89 | /* we must now compute the address of our target object */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 90 | switch ( keyword->location ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 91 | { |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 92 | case T1_FIELD_LOCATION_CID_INFO: |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 93 | object = (FT_Byte*)cid; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 94 | break; |
| 95 | |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 96 | case T1_FIELD_LOCATION_FONT_INFO: |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 97 | object = (FT_Byte*)&cid->font_info; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 98 | break; |
| 99 | |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 100 | case T1_FIELD_LOCATION_BBOX: |
| 101 | object = (FT_Byte*)&cid->font_bbox; |
| 102 | break; |
| 103 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 104 | default: |
| 105 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 106 | CID_FaceDict dict; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 107 | |
| 108 | |
| 109 | if ( parser->num_dict < 0 ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 110 | { |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 111 | FT_ERROR(( "cid_load_keyword: invalid use of `%s'!\n", |
| 112 | keyword->ident )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 113 | error = CID_Err_Syntax_Error; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 114 | goto Exit; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 115 | } |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 116 | |
| 117 | dict = cid->font_dicts + parser->num_dict; |
| 118 | switch ( keyword->location ) |
| 119 | { |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 120 | case T1_FIELD_LOCATION_PRIVATE: |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 121 | object = (FT_Byte*)&dict->private_dict; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 122 | break; |
| 123 | |
| 124 | default: |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 125 | object = (FT_Byte*)dict; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 128 | } |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 129 | |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 130 | dummy_object = object; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 131 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 132 | /* now, load the keyword data in the object's field(s) */ |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 133 | if ( keyword->type == T1_FIELD_TYPE_INTEGER_ARRAY || |
| 134 | keyword->type == T1_FIELD_TYPE_FIXED_ARRAY ) |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 135 | error = cid_parser_load_field_table( &loader->parser, keyword, |
Werner Lemberg | bf7c832 | 2003-06-06 05:07:53 +0000 | [diff] [blame] | 136 | &dummy_object ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 137 | else |
Werner Lemberg | bf7c832 | 2003-06-06 05:07:53 +0000 | [diff] [blame] | 138 | error = cid_parser_load_field( &loader->parser, |
| 139 | keyword, &dummy_object ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 140 | Exit: |
| 141 | return error; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 142 | } |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 143 | |
| 144 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 145 | FT_CALLBACK_DEF( FT_Error ) |
David Turner | dee7813 | 2001-06-27 09:26:46 +0000 | [diff] [blame] | 146 | parse_font_matrix( CID_Face face, |
| 147 | CID_Parser* parser ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 148 | { |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 149 | FT_Matrix* matrix; |
| 150 | FT_Vector* offset; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 151 | CID_FaceDict dict; |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 152 | FT_Face root = (FT_Face)&face->root; |
| 153 | FT_Fixed temp[6]; |
| 154 | FT_Fixed temp_scale; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 155 | |
Werner Lemberg | 29bac13 | 2001-03-11 11:28:39 +0000 | [diff] [blame] | 156 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 157 | if ( parser->num_dict >= 0 ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 158 | { |
| 159 | dict = face->cid.font_dicts + parser->num_dict; |
| 160 | matrix = &dict->font_matrix; |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 161 | offset = &dict->font_offset; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 162 | |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 163 | (void)cid_parser_to_fixed_array( parser, 6, temp, 3 ); |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 164 | |
Werner Lemberg | dfa4619 | 2004-03-05 09:26:24 +0000 | [diff] [blame] | 165 | temp_scale = FT_ABS( temp[3] ); |
Tom Kacvinsky | 025c2f3 | 2001-03-10 19:04:41 +0000 | [diff] [blame] | 166 | |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 167 | /* Set units per EM based on FontMatrix values. We set the value to */ |
Werner Lemberg | 29bac13 | 2001-03-11 11:28:39 +0000 | [diff] [blame] | 168 | /* `1000/temp_scale', because temp_scale was already multiplied by */ |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 169 | /* 1000 (in `t1_tofixed', from psobjs.c). */ |
David Turner | 3798110 | 2001-03-19 11:34:49 +0000 | [diff] [blame] | 170 | root->units_per_EM = (FT_UShort)( FT_DivFix( 0x10000L, |
David Turner | 09d55ce | 2001-05-11 18:08:58 +0000 | [diff] [blame] | 171 | FT_DivFix( temp_scale, 1000 ) ) ); |
Tom Kacvinsky | 025c2f3 | 2001-03-10 19:04:41 +0000 | [diff] [blame] | 172 | |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 173 | /* we need to scale the values by 1.0/temp[3] */ |
Tom Kacvinsky | 025c2f3 | 2001-03-10 19:04:41 +0000 | [diff] [blame] | 174 | if ( temp_scale != 0x10000L ) |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 175 | { |
Tom Kacvinsky | 025c2f3 | 2001-03-10 19:04:41 +0000 | [diff] [blame] | 176 | temp[0] = FT_DivFix( temp[0], temp_scale ); |
| 177 | temp[1] = FT_DivFix( temp[1], temp_scale ); |
| 178 | temp[2] = FT_DivFix( temp[2], temp_scale ); |
| 179 | temp[4] = FT_DivFix( temp[4], temp_scale ); |
| 180 | temp[5] = FT_DivFix( temp[5], temp_scale ); |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 181 | temp[3] = 0x10000L; |
| 182 | } |
| 183 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 184 | matrix->xx = temp[0]; |
| 185 | matrix->yx = temp[1]; |
| 186 | matrix->xy = temp[2]; |
| 187 | matrix->yy = temp[3]; |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 188 | |
Werner Lemberg | 6fbe4db | 2000-10-05 04:53:31 +0000 | [diff] [blame] | 189 | /* note that the font offsets are expressed in integer font units */ |
David Turner | f00a4de | 2000-10-03 22:03:09 +0000 | [diff] [blame] | 190 | offset->x = temp[4] >> 16; |
| 191 | offset->y = temp[5] >> 16; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 192 | } |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 193 | |
Werner Lemberg | 3864f4e | 2003-09-30 06:43:54 +0000 | [diff] [blame] | 194 | return CID_Err_Ok; /* this is a callback function; */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 195 | /* we must return an error code */ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 198 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 199 | FT_CALLBACK_DEF( FT_Error ) |
David Turner | dee7813 | 2001-06-27 09:26:46 +0000 | [diff] [blame] | 200 | parse_fd_array( CID_Face face, |
| 201 | CID_Parser* parser ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 202 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 203 | CID_FaceInfo cid = &face->cid; |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 204 | FT_Memory memory = face->root.memory; |
| 205 | FT_Error error = CID_Err_Ok; |
| 206 | FT_Long num_dicts; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 207 | |
| 208 | |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 209 | num_dicts = cid_parser_to_int( parser ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 210 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 211 | if ( !cid->font_dicts ) |
| 212 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 213 | FT_Int n; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 214 | |
| 215 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 216 | if ( FT_NEW_ARRAY( cid->font_dicts, num_dicts ) ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 217 | goto Exit; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 218 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 219 | cid->num_dicts = (FT_UInt)num_dicts; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 220 | |
| 221 | /* don't forget to set a few defaults */ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 222 | for ( n = 0; n < cid->num_dicts; n++ ) |
| 223 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 224 | CID_FaceDict dict = cid->font_dicts + n; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 225 | |
| 226 | |
| 227 | /* default value for lenIV */ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 228 | dict->private_dict.lenIV = 4; |
| 229 | } |
| 230 | } |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 231 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 232 | Exit: |
| 233 | return error; |
| 234 | } |
| 235 | |
| 236 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 237 | static |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 238 | const T1_FieldRec cid_field_records[] = |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 239 | { |
Werner Lemberg | 7fa51b5 | 2000-07-08 19:51:42 +0000 | [diff] [blame] | 240 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 241 | #include "cidtoken.h" |
Werner Lemberg | 7fa51b5 | 2000-07-08 19:51:42 +0000 | [diff] [blame] | 242 | |
Werner Lemberg | a959c3c | 2003-06-14 07:40:09 +0000 | [diff] [blame] | 243 | T1_FIELD_CALLBACK( "FDArray", parse_fd_array ) |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 244 | T1_FIELD_CALLBACK( "FontMatrix", parse_font_matrix ) |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 245 | |
David Turner | 429978b | 2002-03-14 10:09:35 +0000 | [diff] [blame] | 246 | { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0 } |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 250 | static FT_Error |
| 251 | cid_parse_dict( CID_Face face, |
| 252 | CID_Loader* loader, |
| 253 | FT_Byte* base, |
| 254 | FT_Long size ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 255 | { |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 256 | CID_Parser* parser = &loader->parser; |
| 257 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 258 | |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 259 | parser->root.cursor = base; |
| 260 | parser->root.limit = base + size; |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 261 | parser->root.error = CID_Err_Ok; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 262 | |
| 263 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 264 | FT_Byte* cur = base; |
| 265 | FT_Byte* limit = cur + size; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 266 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 267 | |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 268 | for (;;) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 269 | { |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 270 | FT_Byte* newlimit; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 271 | |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 272 | |
| 273 | parser->root.cursor = cur; |
| 274 | cid_parser_skip_spaces( parser ); |
| 275 | |
| 276 | if ( parser->root.cursor >= limit ) |
| 277 | newlimit = limit - 1 - 17; |
| 278 | else |
| 279 | newlimit = parser->root.cursor - 17; |
| 280 | |
| 281 | /* look for `%ADOBeginFontDict' */ |
| 282 | for ( ; cur < newlimit; cur++ ) |
| 283 | { |
| 284 | if ( *cur == '%' && |
| 285 | ft_strncmp( (char*)cur, "%ADOBeginFontDict", 17 ) == 0 ) |
| 286 | { |
| 287 | /* if /FDArray was found, then cid->num_dicts is > 0, and */ |
| 288 | /* we can start increasing parser->num_dict */ |
| 289 | if ( face->cid.num_dicts > 0 ) |
| 290 | parser->num_dict++; |
| 291 | } |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 292 | } |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 293 | |
| 294 | cur = parser->root.cursor; |
| 295 | /* no error can occur in cid_parser_skip_spaces */ |
| 296 | if ( cur >= limit ) |
| 297 | break; |
| 298 | |
| 299 | cid_parser_skip_PS_token( parser ); |
| 300 | if ( parser->root.cursor >= limit || parser->root.error ) |
| 301 | break; |
| 302 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 303 | /* look for immediates */ |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 304 | if ( *cur == '/' && cur + 2 < limit ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 305 | { |
Werner Lemberg | 3864f4e | 2003-09-30 06:43:54 +0000 | [diff] [blame] | 306 | FT_PtrDist len; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 307 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 308 | |
| 309 | cur++; |
Werner Lemberg | 3864f4e | 2003-09-30 06:43:54 +0000 | [diff] [blame] | 310 | len = parser->root.cursor - cur; |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 311 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 312 | if ( len > 0 && len < 22 ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 313 | { |
Werner Lemberg | ac39ecd | 2000-06-30 22:24:36 +0000 | [diff] [blame] | 314 | /* now compare the immediate name to the keyword table */ |
Werner Lemberg | 3864f4e | 2003-09-30 06:43:54 +0000 | [diff] [blame] | 315 | T1_Field keyword = (T1_Field)cid_field_records; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 316 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 317 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 318 | for (;;) |
| 319 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 320 | FT_Byte* name; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 321 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 322 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 323 | name = (FT_Byte*)keyword->ident; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 324 | if ( !name ) |
Werner Lemberg | 3864f4e | 2003-09-30 06:43:54 +0000 | [diff] [blame] | 325 | break; |
Werner Lemberg | 3864f4e | 2003-09-30 06:43:54 +0000 | [diff] [blame] | 326 | |
Werner Lemberg | 023a4bf | 2004-10-14 11:33:04 +0000 | [diff] [blame] | 327 | if ( cur[0] == name[0] && |
| 328 | len == (FT_PtrDist)ft_strlen( (const char*)name ) ) |
Werner Lemberg | 3864f4e | 2003-09-30 06:43:54 +0000 | [diff] [blame] | 329 | { |
| 330 | FT_PtrDist n; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 331 | |
| 332 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 333 | for ( n = 1; n < len; n++ ) |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 334 | if ( cur[n] != name[n] ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 335 | break; |
| 336 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 337 | if ( n >= len ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 338 | { |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 339 | /* we found it - run the parsing callback */ |
Werner Lemberg | d1b7475 | 2000-08-24 16:29:15 +0000 | [diff] [blame] | 340 | parser->root.error = cid_load_keyword( face, |
| 341 | loader, |
| 342 | keyword ); |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 343 | if ( parser->root.error ) |
| 344 | return parser->root.error; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 345 | break; |
| 346 | } |
| 347 | } |
| 348 | keyword++; |
| 349 | } |
| 350 | } |
| 351 | } |
Werner Lemberg | 52f911a | 2003-10-07 05:49:41 +0000 | [diff] [blame] | 352 | |
| 353 | cur = parser->root.cursor; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 354 | } |
| 355 | } |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 356 | return parser->root.error; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 360 | /* read the subrmap and the subrs of each font dict */ |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 361 | static FT_Error |
| 362 | cid_read_subrs( CID_Face face ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 363 | { |
Werner Lemberg | 75aae7d | 2003-06-12 07:11:05 +0000 | [diff] [blame] | 364 | CID_FaceInfo cid = &face->cid; |
| 365 | FT_Memory memory = face->root.memory; |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 366 | FT_Stream stream = face->cid_stream; |
Werner Lemberg | 75aae7d | 2003-06-12 07:11:05 +0000 | [diff] [blame] | 367 | FT_Error error; |
| 368 | FT_Int n; |
| 369 | CID_Subrs subr; |
| 370 | FT_UInt max_offsets = 0; |
| 371 | FT_ULong* offsets = 0; |
| 372 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 373 | |
| 374 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 375 | if ( FT_NEW_ARRAY( face->subrs, cid->num_dicts ) ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 376 | goto Exit; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 377 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 378 | subr = face->subrs; |
| 379 | for ( n = 0; n < cid->num_dicts; n++, subr++ ) |
| 380 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 381 | CID_FaceDict dict = cid->font_dicts + n; |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 382 | FT_Int lenIV = dict->private_dict.lenIV; |
| 383 | FT_UInt count, num_subrs = dict->num_subrs; |
| 384 | FT_ULong data_len; |
| 385 | FT_Byte* p; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 386 | |
| 387 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 388 | /* reallocate offsets array if needed */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 389 | if ( num_subrs + 1 > max_offsets ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 390 | { |
David Turner | 87c0d30 | 2003-12-24 01:10:46 +0000 | [diff] [blame] | 391 | FT_UInt new_max = FT_PAD_CEIL( num_subrs + 1, 4 ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 392 | |
| 393 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 394 | if ( FT_RENEW_ARRAY( offsets, max_offsets, new_max ) ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 395 | goto Fail; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 396 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 397 | max_offsets = new_max; |
| 398 | } |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 399 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 400 | /* read the subrmap's offsets */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 401 | if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) || |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 402 | FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 403 | goto Fail; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 404 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 405 | p = (FT_Byte*)stream->cursor; |
| 406 | for ( count = 0; count <= num_subrs; count++ ) |
David Turner | 81bb4ad | 2000-06-28 04:19:49 +0000 | [diff] [blame] | 407 | offsets[count] = cid_get_offset( &p, (FT_Byte)dict->sd_bytes ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 408 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 409 | FT_FRAME_EXIT(); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 410 | |
| 411 | /* now, compute the size of subrs charstrings, */ |
| 412 | /* allocate, and read them */ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 413 | data_len = offsets[num_subrs] - offsets[0]; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 414 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 415 | if ( FT_NEW_ARRAY( subr->code, num_subrs + 1 ) || |
| 416 | FT_ALLOC( subr->code[0], data_len ) ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 417 | goto Fail; |
| 418 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 419 | if ( FT_STREAM_SEEK( cid->data_offset + offsets[0] ) || |
| 420 | FT_STREAM_READ( subr->code[0], data_len ) ) |
David Turner | 3a664fc | 2001-12-21 15:26:19 +0000 | [diff] [blame] | 421 | goto Fail; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 422 | |
| 423 | /* set up pointers */ |
| 424 | for ( count = 1; count <= num_subrs; count++ ) |
| 425 | { |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 426 | FT_ULong len; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 427 | |
| 428 | |
| 429 | len = offsets[count] - offsets[count - 1]; |
| 430 | subr->code[count] = subr->code[count - 1] + len; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Werner Lemberg | 9a8b536 | 2001-03-12 22:33:52 +0000 | [diff] [blame] | 433 | /* decrypt subroutines, but only if lenIV >= 0 */ |
Tom Kacvinsky | 6862113 | 2001-03-12 02:17:50 +0000 | [diff] [blame] | 434 | if ( lenIV >= 0 ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 435 | { |
Tom Kacvinsky | 6862113 | 2001-03-12 02:17:50 +0000 | [diff] [blame] | 436 | for ( count = 0; count < num_subrs; count++ ) |
| 437 | { |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 438 | FT_ULong len; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 439 | |
| 440 | |
Tom Kacvinsky | 6862113 | 2001-03-12 02:17:50 +0000 | [diff] [blame] | 441 | len = offsets[count + 1] - offsets[count]; |
Werner Lemberg | 75aae7d | 2003-06-12 07:11:05 +0000 | [diff] [blame] | 442 | psaux->t1_decrypt( subr->code[count], len, 4330 ); |
Tom Kacvinsky | 6862113 | 2001-03-12 02:17:50 +0000 | [diff] [blame] | 443 | } |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | subr->num_subrs = num_subrs; |
| 447 | } |
| 448 | |
| 449 | Exit: |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 450 | FT_FREE( offsets ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 451 | return error; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 452 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 453 | Fail: |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 454 | if ( face->subrs ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 455 | { |
| 456 | for ( n = 0; n < cid->num_dicts; n++ ) |
| 457 | { |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 458 | if ( face->subrs[n].code ) |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 459 | FT_FREE( face->subrs[n].code[0] ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 460 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 461 | FT_FREE( face->subrs[n].code ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 462 | } |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 463 | FT_FREE( face->subrs ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 464 | } |
| 465 | goto Exit; |
| 466 | } |
| 467 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 468 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 469 | static void |
| 470 | t1_init_loader( CID_Loader* loader, |
| 471 | CID_Face face ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 472 | { |
David Turner | c6a9220 | 2000-07-04 18:12:13 +0000 | [diff] [blame] | 473 | FT_UNUSED( face ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 474 | |
Werner Lemberg | b3d5e9c | 2002-07-28 05:05:24 +0000 | [diff] [blame] | 475 | FT_MEM_ZERO( loader, sizeof ( *loader ) ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 478 | |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 479 | static void |
| 480 | t1_done_loader( CID_Loader* loader ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 481 | { |
| 482 | CID_Parser* parser = &loader->parser; |
| 483 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 484 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 485 | /* finalize parser */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 486 | cid_parser_done( parser ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 489 | |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 490 | static FT_Error |
| 491 | cid_hex_to_binary( FT_Byte* data, |
| 492 | FT_Long data_len, |
| 493 | FT_ULong offset, |
| 494 | CID_Face face ) |
| 495 | { |
| 496 | FT_Stream stream = face->root.stream; |
| 497 | FT_Error error; |
| 498 | |
| 499 | FT_Byte buffer[256]; |
| 500 | FT_Byte *p, *plimit; |
| 501 | FT_Byte *d, *dlimit; |
| 502 | FT_Byte val; |
| 503 | |
| 504 | FT_Bool upper_nibble, done; |
| 505 | |
| 506 | |
| 507 | if ( FT_STREAM_SEEK( offset ) ) |
| 508 | goto Exit; |
| 509 | |
| 510 | d = data; |
| 511 | dlimit = d + data_len; |
| 512 | p = buffer; |
| 513 | plimit = p; |
| 514 | |
| 515 | upper_nibble = 1; |
| 516 | done = 0; |
| 517 | |
| 518 | while ( d < dlimit ) |
| 519 | { |
| 520 | if ( p >= plimit ) |
| 521 | { |
| 522 | FT_ULong oldpos = FT_STREAM_POS(); |
| 523 | FT_ULong size = stream->size - oldpos; |
| 524 | |
| 525 | |
| 526 | if ( size == 0 ) |
| 527 | { |
| 528 | error = CID_Err_Syntax_Error; |
| 529 | goto Exit; |
| 530 | } |
| 531 | |
| 532 | if ( FT_STREAM_READ( buffer, 256 > size ? size : 256 ) ) |
| 533 | goto Exit; |
| 534 | p = buffer; |
| 535 | plimit = p + FT_STREAM_POS() - oldpos; |
| 536 | } |
| 537 | |
| 538 | if ( ft_isdigit( *p ) ) |
Werner Lemberg | 22ad9ef | 2005-05-09 22:11:36 +0000 | [diff] [blame] | 539 | val = (FT_Byte)( *p - '0' ); |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 540 | else if ( *p >= 'a' && *p <= 'f' ) |
Werner Lemberg | 22ad9ef | 2005-05-09 22:11:36 +0000 | [diff] [blame] | 541 | val = (FT_Byte)( *p - 'a' ); |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 542 | else if ( *p >= 'A' && *p <= 'F' ) |
Werner Lemberg | 22ad9ef | 2005-05-09 22:11:36 +0000 | [diff] [blame] | 543 | val = (FT_Byte)( *p - 'A' + 10 ); |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 544 | else if ( *p == ' ' || |
| 545 | *p == '\t' || |
| 546 | *p == '\r' || |
| 547 | *p == '\n' || |
| 548 | *p == '\f' || |
| 549 | *p == '\0' ) |
| 550 | { |
| 551 | p++; |
| 552 | continue; |
| 553 | } |
| 554 | else if ( *p == '>' ) |
| 555 | { |
| 556 | val = 0; |
| 557 | done = 1; |
| 558 | } |
| 559 | else |
| 560 | { |
| 561 | error = CID_Err_Syntax_Error; |
| 562 | goto Exit; |
| 563 | } |
| 564 | |
| 565 | if ( upper_nibble ) |
Werner Lemberg | 22ad9ef | 2005-05-09 22:11:36 +0000 | [diff] [blame] | 566 | *d = (FT_Byte)( val << 4 ); |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 567 | else |
| 568 | { |
Werner Lemberg | 22ad9ef | 2005-05-09 22:11:36 +0000 | [diff] [blame] | 569 | *d = (FT_Byte)( *d + val ); |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 570 | d++; |
| 571 | } |
| 572 | |
Werner Lemberg | 22ad9ef | 2005-05-09 22:11:36 +0000 | [diff] [blame] | 573 | upper_nibble = (FT_Byte)( 1 - upper_nibble ); |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 574 | |
| 575 | if ( done ) |
| 576 | break; |
| 577 | |
| 578 | p++; |
| 579 | } |
| 580 | |
| 581 | error = CID_Err_Ok; |
| 582 | |
| 583 | Exit: |
| 584 | return error; |
| 585 | } |
| 586 | |
| 587 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 588 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 589 | cid_face_open( CID_Face face, |
| 590 | FT_Int face_index ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 591 | { |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 592 | CID_Loader loader; |
| 593 | CID_Parser* parser; |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 594 | FT_Memory memory = face->root.memory; |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 595 | FT_Error error; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 596 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 597 | |
| 598 | t1_init_loader( &loader, face ); |
| 599 | |
| 600 | parser = &loader.parser; |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 601 | error = cid_parser_new( parser, face->root.stream, face->root.memory, |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 602 | (PSAux_Service)face->psaux ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 603 | if ( error ) |
| 604 | goto Exit; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 605 | |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 606 | error = cid_parse_dict( face, &loader, |
| 607 | parser->postscript, |
| 608 | parser->postscript_len ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 609 | if ( error ) |
| 610 | goto Exit; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 611 | |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 612 | if ( face_index < 0 ) |
| 613 | goto Exit; |
| 614 | |
Werner Lemberg | 9586707 | 2004-02-12 08:33:20 +0000 | [diff] [blame] | 615 | if ( FT_NEW( face->cid_stream ) ) |
| 616 | goto Exit; |
| 617 | |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 618 | if ( parser->binary_length ) |
| 619 | { |
| 620 | /* we must convert the data section from hexadecimal to binary */ |
| 621 | if ( FT_ALLOC( face->binary_data, parser->binary_length ) || |
| 622 | cid_hex_to_binary( face->binary_data, parser->binary_length, |
| 623 | parser->data_offset, face ) ) |
| 624 | goto Exit; |
| 625 | |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 626 | FT_Stream_OpenMemory( face->cid_stream, |
| 627 | face->binary_data, parser->binary_length ); |
| 628 | face->cid.data_offset = 0; |
| 629 | } |
| 630 | else |
| 631 | { |
Werner Lemberg | 9586707 | 2004-02-12 08:33:20 +0000 | [diff] [blame] | 632 | *face->cid_stream = *face->root.stream; |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 633 | face->cid.data_offset = loader.parser.data_offset; |
| 634 | } |
| 635 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 636 | error = cid_read_subrs( face ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 637 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 638 | Exit: |
| 639 | t1_done_loader( &loader ); |
| 640 | return error; |
| 641 | } |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 642 | |
| 643 | |
| 644 | /* END */ |