Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* cidobjs.c */ |
| 4 | /* */ |
| 5 | /* CID objects manager (body). */ |
| 6 | /* */ |
Werner Lemberg | f1c2b91 | 2006-01-13 14:53:28 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006 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_INTERNAL_STREAM_H |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 22 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 23 | #include "cidgload.h" |
| 24 | #include "cidload.h" |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 25 | |
David Turner | 7760595 | 2003-10-29 21:43:52 +0000 | [diff] [blame] | 26 | #include FT_SERVICE_POSTSCRIPT_CMAPS_H |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 27 | #include FT_INTERNAL_POSTSCRIPT_AUX_H |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 28 | #include FT_INTERNAL_POSTSCRIPT_HINTS_H |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 29 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 30 | #include "ciderrs.h" |
| 31 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 32 | |
| 33 | /*************************************************************************/ |
| 34 | /* */ |
| 35 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 36 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 37 | /* messages during execution. */ |
| 38 | /* */ |
Werner Lemberg | 63408a1 | 2000-12-13 23:44:37 +0000 | [diff] [blame] | 39 | #undef FT_COMPONENT |
| 40 | #define FT_COMPONENT trace_cidobjs |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 41 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 42 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 43 | /*************************************************************************/ |
| 44 | /* */ |
| 45 | /* SLOT FUNCTIONS */ |
| 46 | /* */ |
| 47 | /*************************************************************************/ |
| 48 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 49 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 50 | cid_slot_done( FT_GlyphSlot slot ) |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 51 | { |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 52 | slot->internal->glyph_hints = 0; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 56 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 57 | cid_slot_init( FT_GlyphSlot slot ) |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 58 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 59 | CID_Face face; |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 60 | PSHinter_Service pshinter; |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 61 | |
| 62 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 63 | face = (CID_Face)slot->face; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 64 | pshinter = (PSHinter_Service)face->pshinter; |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 65 | |
| 66 | if ( pshinter ) |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 67 | { |
| 68 | FT_Module module; |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 69 | |
| 70 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 71 | module = FT_Get_Module( slot->face->driver->root.library, |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 72 | "pshinter" ); |
| 73 | if ( module ) |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 74 | { |
| 75 | T1_Hints_Funcs funcs; |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 76 | |
| 77 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 78 | funcs = pshinter->get_t1_funcs( module ); |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 79 | slot->internal->glyph_hints = (void*)funcs; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 82 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 83 | return 0; |
| 84 | } |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 85 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 86 | |
| 87 | /*************************************************************************/ |
| 88 | /* */ |
| 89 | /* SIZE FUNCTIONS */ |
| 90 | /* */ |
| 91 | /*************************************************************************/ |
| 92 | |
| 93 | |
| 94 | static PSH_Globals_Funcs |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 95 | cid_size_get_globals_funcs( CID_Size size ) |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 96 | { |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 97 | CID_Face face = (CID_Face)size->root.face; |
| 98 | PSHinter_Service pshinter = (PSHinter_Service)face->pshinter; |
| 99 | FT_Module module; |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 100 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 101 | |
| 102 | module = FT_Get_Module( size->root.face->driver->root.library, |
| 103 | "pshinter" ); |
| 104 | return ( module && pshinter && pshinter->get_globals_funcs ) |
| 105 | ? pshinter->get_globals_funcs( module ) |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 106 | : 0; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 110 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 111 | cid_size_done( FT_Size cidsize ) /* CID_Size */ |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 112 | { |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 113 | CID_Size size = (CID_Size)cidsize; |
| 114 | |
| 115 | |
| 116 | if ( cidsize->internal ) |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 117 | { |
| 118 | PSH_Globals_Funcs funcs; |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 119 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 120 | |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 121 | funcs = cid_size_get_globals_funcs( size ); |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 122 | if ( funcs ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 123 | funcs->destroy( (PSH_Globals)cidsize->internal ); |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 124 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 125 | cidsize->internal = 0; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 130 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 131 | cid_size_init( FT_Size cidsize ) /* CID_Size */ |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 132 | { |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 133 | CID_Size size = (CID_Size)cidsize; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 134 | FT_Error error = 0; |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 135 | PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size ); |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 136 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 137 | |
| 138 | if ( funcs ) |
| 139 | { |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 140 | PSH_Globals globals; |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 141 | CID_Face face = (CID_Face)cidsize->face; |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 142 | CID_FaceDict dict = face->cid.font_dicts + face->root.face_index; |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 143 | PS_Private priv = &dict->private_dict; |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 144 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 145 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 146 | error = funcs->create( cidsize->face->memory, priv, &globals ); |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 147 | if ( !error ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 148 | cidsize->internal = (FT_Size_Internal)(void*)globals; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 149 | } |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 150 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 151 | return error; |
| 152 | } |
| 153 | |
| 154 | |
Wu, Chia-I (吳佳一) | fa7d6ab | 2006-01-13 12:21:31 +0000 | [diff] [blame] | 155 | FT_LOCAL( FT_Error ) |
| 156 | cid_size_request( FT_Size size, |
| 157 | FT_Size_Request req ) |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 158 | { |
Wu, Chia-I (吳佳一) | fa7d6ab | 2006-01-13 12:21:31 +0000 | [diff] [blame] | 159 | PSH_Globals_Funcs funcs; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 160 | |
Wu, Chia-I (吳佳一) | fa7d6ab | 2006-01-13 12:21:31 +0000 | [diff] [blame] | 161 | |
Wu, Chia-I (吳佳一) | bcc438b | 2006-01-23 14:12:40 +0000 | [diff] [blame] | 162 | FT_Request_Metrics( size->face, req ); |
Werner Lemberg | f1c2b91 | 2006-01-13 14:53:28 +0000 | [diff] [blame] | 163 | |
Wu, Chia-I (吳佳一) | fa7d6ab | 2006-01-13 12:21:31 +0000 | [diff] [blame] | 164 | funcs = cid_size_get_globals_funcs( (CID_Size)size ); |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 165 | |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 166 | if ( funcs ) |
Wu, Chia-I (吳佳一) | fa7d6ab | 2006-01-13 12:21:31 +0000 | [diff] [blame] | 167 | funcs->set_scale( (PSH_Globals)size->internal, |
| 168 | size->metrics.x_scale, |
| 169 | size->metrics.y_scale, |
| 170 | 0, 0 ); |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 171 | |
Wu, Chia-I (吳佳一) | fa7d6ab | 2006-01-13 12:21:31 +0000 | [diff] [blame] | 172 | return CID_Err_Ok; |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 176 | /*************************************************************************/ |
| 177 | /* */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 178 | /* FACE FUNCTIONS */ |
| 179 | /* */ |
| 180 | /*************************************************************************/ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 181 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 182 | /*************************************************************************/ |
| 183 | /* */ |
| 184 | /* <Function> */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 185 | /* cid_face_done */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 186 | /* */ |
| 187 | /* <Description> */ |
| 188 | /* Finalizes a given face object. */ |
| 189 | /* */ |
| 190 | /* <Input> */ |
| 191 | /* face :: A pointer to the face object to destroy. */ |
| 192 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 193 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 194 | cid_face_done( FT_Face cidface ) /* CID_Face */ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 195 | { |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 196 | CID_Face face = (CID_Face)cidface; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 197 | FT_Memory memory; |
| 198 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 199 | |
| 200 | if ( face ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 201 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 202 | CID_FaceInfo cid = &face->cid; |
| 203 | PS_FontInfo info = &cid->font_info; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 204 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 205 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 206 | memory = cidface->memory; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 207 | |
David Turner | 3a664fc | 2001-12-21 15:26:19 +0000 | [diff] [blame] | 208 | /* release subrs */ |
| 209 | if ( face->subrs ) |
| 210 | { |
Werner Lemberg | 44be4d5 | 2002-03-30 17:08:04 +0000 | [diff] [blame] | 211 | FT_Int n; |
David Turner | 17dd063 | 2003-09-21 16:04:05 +0000 | [diff] [blame] | 212 | |
Werner Lemberg | af594e6 | 2001-12-22 14:38:40 +0000 | [diff] [blame] | 213 | |
David Turner | 3a664fc | 2001-12-21 15:26:19 +0000 | [diff] [blame] | 214 | for ( n = 0; n < cid->num_dicts; n++ ) |
| 215 | { |
David Turner | 2964417 | 2002-02-28 18:59:37 +0000 | [diff] [blame] | 216 | CID_Subrs subr = face->subrs + n; |
David Turner | 17dd063 | 2003-09-21 16:04:05 +0000 | [diff] [blame] | 217 | |
Werner Lemberg | af594e6 | 2001-12-22 14:38:40 +0000 | [diff] [blame] | 218 | |
David Turner | 3a664fc | 2001-12-21 15:26:19 +0000 | [diff] [blame] | 219 | if ( subr->code ) |
| 220 | { |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 221 | FT_FREE( subr->code[0] ); |
| 222 | FT_FREE( subr->code ); |
David Turner | 3a664fc | 2001-12-21 15:26:19 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 226 | FT_FREE( face->subrs ); |
David Turner | 3a664fc | 2001-12-21 15:26:19 +0000 | [diff] [blame] | 227 | } |
| 228 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 229 | /* release FontInfo strings */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 230 | FT_FREE( info->version ); |
| 231 | FT_FREE( info->notice ); |
| 232 | FT_FREE( info->full_name ); |
| 233 | FT_FREE( info->family_name ); |
| 234 | FT_FREE( info->weight ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 235 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 236 | /* release font dictionaries */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 237 | FT_FREE( cid->font_dicts ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 238 | cid->num_dicts = 0; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 239 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 240 | /* release other strings */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 241 | FT_FREE( cid->cid_font_name ); |
| 242 | FT_FREE( cid->registry ); |
| 243 | FT_FREE( cid->ordering ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 244 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 245 | cidface->family_name = 0; |
| 246 | cidface->style_name = 0; |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 247 | |
| 248 | FT_FREE( face->binary_data ); |
| 249 | FT_FREE( face->cid_stream ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 253 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 254 | /*************************************************************************/ |
| 255 | /* */ |
| 256 | /* <Function> */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 257 | /* cid_face_init */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 258 | /* */ |
| 259 | /* <Description> */ |
| 260 | /* Initializes a given CID face object. */ |
| 261 | /* */ |
| 262 | /* <Input> */ |
| 263 | /* stream :: The source font stream. */ |
| 264 | /* */ |
| 265 | /* face_index :: The index of the font face in the resource. */ |
| 266 | /* */ |
| 267 | /* num_params :: Number of additional generic parameters. Ignored. */ |
| 268 | /* */ |
| 269 | /* params :: Additional generic parameters. Ignored. */ |
| 270 | /* */ |
| 271 | /* <InOut> */ |
| 272 | /* face :: The newly built face object. */ |
| 273 | /* */ |
| 274 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 275 | /* FreeType error code. 0 means success. */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 276 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 277 | FT_LOCAL_DEF( FT_Error ) |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 278 | cid_face_init( FT_Stream stream, |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 279 | FT_Face cidface, /* CID_Face */ |
Werner Lemberg | 93616ec | 2001-06-27 19:46:12 +0000 | [diff] [blame] | 280 | FT_Int face_index, |
| 281 | FT_Int num_params, |
| 282 | FT_Parameter* params ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 283 | { |
Werner Lemberg | f814f68 | 2005-05-22 20:33:09 +0000 | [diff] [blame] | 284 | CID_Face face = (CID_Face)cidface; |
| 285 | FT_Error error; |
| 286 | PSAux_Service psaux; |
| 287 | PSHinter_Service pshinter; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 288 | |
David Turner | c6a9220 | 2000-07-04 18:12:13 +0000 | [diff] [blame] | 289 | FT_UNUSED( num_params ); |
| 290 | FT_UNUSED( params ); |
David Turner | c6a9220 | 2000-07-04 18:12:13 +0000 | [diff] [blame] | 291 | FT_UNUSED( stream ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 292 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 293 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 294 | cidface->num_faces = 1; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 295 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 296 | psaux = (PSAux_Service)face->psaux; |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 297 | if ( !psaux ) |
| 298 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 299 | psaux = (PSAux_Service)FT_Get_Module_Interface( |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 300 | FT_FACE_LIBRARY( face ), "psaux" ); |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 301 | |
David Turner | 34f1c2f | 2000-08-23 22:47:44 +0000 | [diff] [blame] | 302 | face->psaux = psaux; |
| 303 | } |
| 304 | |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 305 | pshinter = (PSHinter_Service)face->pshinter; |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 306 | if ( !pshinter ) |
| 307 | { |
David Turner | 4e7eeee | 2002-02-28 16:10:29 +0000 | [diff] [blame] | 308 | pshinter = (PSHinter_Service)FT_Get_Module_Interface( |
Werner Lemberg | f41e71a | 2001-12-20 21:22:02 +0000 | [diff] [blame] | 309 | FT_FACE_LIBRARY( face ), "pshinter" ); |
David Turner | 85eb669 | 2001-12-20 09:36:21 +0000 | [diff] [blame] | 310 | |
| 311 | face->pshinter = pshinter; |
| 312 | } |
| 313 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 314 | /* open the tokenizer; this will also check the font format */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 315 | if ( FT_STREAM_SEEK( 0 ) ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 316 | goto Exit; |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 317 | |
Werner Lemberg | ef512e3 | 2004-01-23 19:52:40 +0000 | [diff] [blame] | 318 | error = cid_face_open( face, face_index ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 319 | if ( error ) |
| 320 | goto Exit; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 321 | |
| 322 | /* if we just wanted to check the format, leave successfully now */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 323 | if ( face_index < 0 ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 324 | goto Exit; |
| 325 | |
| 326 | /* check the face index */ |
| 327 | if ( face_index != 0 ) |
| 328 | { |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 329 | FT_ERROR(( "cid_face_init: invalid face index\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 330 | error = CID_Err_Invalid_Argument; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 331 | goto Exit; |
| 332 | } |
| 333 | |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 334 | /* now load the font program into the face object */ |
| 335 | |
| 336 | /* initialize the face object fields */ |
| 337 | |
| 338 | /* set up root face fields */ |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 339 | { |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 340 | CID_FaceInfo cid = &face->cid; |
| 341 | PS_FontInfo info = &cid->font_info; |
| 342 | |
| 343 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 344 | cidface->num_glyphs = cid->cid_count; |
| 345 | cidface->num_charmaps = 0; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 346 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 347 | cidface->face_index = face_index; |
Werner Lemberg | 7734a1f | 2005-10-05 15:18:29 +0000 | [diff] [blame] | 348 | cidface->face_flags = FT_FACE_FLAG_SCALABLE | /* scalable outlines */ |
| 349 | FT_FACE_FLAG_HORIZONTAL | /* horizontal data */ |
| 350 | FT_FACE_FLAG_HINTER; /* has native hinter */ |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 351 | |
Werner Lemberg | 64f1ba9 | 2003-07-25 22:09:53 +0000 | [diff] [blame] | 352 | if ( info->is_fixed_pitch ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 353 | cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 354 | |
| 355 | /* XXX: TODO: add kerning with .afm support */ |
| 356 | |
| 357 | /* get style name -- be careful, some broken fonts only */ |
| 358 | /* have a /FontName dictionary entry! */ |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 359 | cidface->family_name = info->family_name; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 360 | /* assume "Regular" style if we don't know better */ |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 361 | cidface->style_name = (char *)"Regular"; |
| 362 | if ( cidface->family_name ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 363 | { |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 364 | char* full = info->full_name; |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 365 | char* family = cidface->family_name; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 366 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 367 | |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 368 | if ( full ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 369 | { |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 370 | while ( *full ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 371 | { |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 372 | if ( *full == *family ) |
| 373 | { |
| 374 | family++; |
| 375 | full++; |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | if ( *full == ' ' || *full == '-' ) |
| 380 | full++; |
| 381 | else if ( *family == ' ' || *family == '-' ) |
| 382 | family++; |
| 383 | else |
| 384 | { |
| 385 | if ( !*family ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 386 | cidface->style_name = full; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 387 | break; |
| 388 | } |
| 389 | } |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 390 | } |
| 391 | } |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 392 | } |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 393 | else |
| 394 | { |
| 395 | /* do we have a `/FontName'? */ |
| 396 | if ( cid->cid_font_name ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 397 | cidface->family_name = cid->cid_font_name; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /* compute style flags */ |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 401 | cidface->style_flags = 0; |
Werner Lemberg | 64f1ba9 | 2003-07-25 22:09:53 +0000 | [diff] [blame] | 402 | if ( info->italic_angle ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 403 | cidface->style_flags |= FT_STYLE_FLAG_ITALIC; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 404 | if ( info->weight ) |
| 405 | { |
| 406 | if ( !ft_strcmp( info->weight, "Bold" ) || |
| 407 | !ft_strcmp( info->weight, "Black" ) ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 408 | cidface->style_flags |= FT_STYLE_FLAG_BOLD; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /* no embedded bitmap support */ |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 412 | cidface->num_fixed_sizes = 0; |
| 413 | cidface->available_sizes = 0; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 414 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 415 | cidface->bbox.xMin = cid->font_bbox.xMin >> 16; |
| 416 | cidface->bbox.yMin = cid->font_bbox.yMin >> 16; |
| 417 | cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFFU ) >> 16; |
| 418 | cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFFU ) >> 16; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 419 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 420 | if ( !cidface->units_per_EM ) |
| 421 | cidface->units_per_EM = 1000; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 422 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 423 | cidface->ascender = (FT_Short)( cidface->bbox.yMax ); |
| 424 | cidface->descender = (FT_Short)( cidface->bbox.yMin ); |
Wu, Chia-I (吳佳一) | 5d14685 | 2006-01-31 10:29:44 +0000 | [diff] [blame] | 425 | |
| 426 | cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 ); |
| 427 | if ( cidface->height < cidface->ascender - cidface->descender ) |
| 428 | cidface->height = cidface->ascender - cidface->descender; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 429 | |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 430 | cidface->underline_position = (FT_Short)info->underline_position; |
| 431 | cidface->underline_thickness = (FT_Short)info->underline_thickness; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 432 | } |
| 433 | |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 434 | Exit: |
| 435 | return error; |
| 436 | } |
| 437 | |
| 438 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 439 | /*************************************************************************/ |
| 440 | /* */ |
| 441 | /* <Function> */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 442 | /* cid_driver_init */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 443 | /* */ |
| 444 | /* <Description> */ |
| 445 | /* Initializes a given CID driver object. */ |
| 446 | /* */ |
| 447 | /* <Input> */ |
| 448 | /* driver :: A handle to the target driver object. */ |
| 449 | /* */ |
| 450 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 451 | /* FreeType error code. 0 means success. */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 452 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 453 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 454 | cid_driver_init( FT_Module driver ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 455 | { |
David Turner | c6a9220 | 2000-07-04 18:12:13 +0000 | [diff] [blame] | 456 | FT_UNUSED( driver ); |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 457 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 458 | return CID_Err_Ok; |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 462 | /*************************************************************************/ |
| 463 | /* */ |
| 464 | /* <Function> */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 465 | /* cid_driver_done */ |
Werner Lemberg | e3c11d7 | 2000-06-16 06:49:56 +0000 | [diff] [blame] | 466 | /* */ |
| 467 | /* <Description> */ |
| 468 | /* Finalizes a given CID driver. */ |
| 469 | /* */ |
| 470 | /* <Input> */ |
| 471 | /* driver :: A handle to the target CID driver. */ |
| 472 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 473 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 3bcad43 | 2004-05-06 11:48:35 +0000 | [diff] [blame] | 474 | cid_driver_done( FT_Module driver ) |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 475 | { |
David Turner | c6a9220 | 2000-07-04 18:12:13 +0000 | [diff] [blame] | 476 | FT_UNUSED( driver ); |
David Turner | 04aa800 | 2000-06-01 03:27:48 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
| 480 | /* END */ |