Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 3 | /* t1afm.c */ |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 4 | /* */ |
| 5 | /* AFM support for Type 1 fonts (body). */ |
| 6 | /* */ |
Werner Lemberg | c8f5b98 | 2010-07-12 21:13:22 +0200 | [diff] [blame] | 7 | /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ |
| 8 | /* 2010 by */ |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 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 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 19 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 20 | #include <ft2build.h> |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 21 | #include "t1afm.h" |
Werner Lemberg | 645af08 | 2004-09-06 07:06:56 +0000 | [diff] [blame] | 22 | #include "t1errors.h" |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 23 | #include FT_INTERNAL_STREAM_H |
David Turner | 6a681fa | 2006-01-27 12:11:22 +0000 | [diff] [blame] | 24 | #include FT_INTERNAL_POSTSCRIPT_AUX_H |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | /*************************************************************************/ |
| 28 | /* */ |
| 29 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 30 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 31 | /* messages during execution. */ |
| 32 | /* */ |
| 33 | #undef FT_COMPONENT |
Werner Lemberg | b5084e1 | 2000-10-28 17:10:06 +0000 | [diff] [blame] | 34 | #define FT_COMPONENT trace_t1afm |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 35 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 36 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 37 | FT_LOCAL_DEF( void ) |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 38 | T1_Done_Metrics( FT_Memory memory, |
| 39 | AFM_FontInfo fi ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 40 | { |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 41 | FT_FREE( fi->KernPairs ); |
| 42 | fi->NumKernPair = 0; |
| 43 | |
| 44 | FT_FREE( fi->TrackKerns ); |
| 45 | fi->NumTrackKern = 0; |
| 46 | |
| 47 | FT_FREE( fi ); |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 50 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 51 | /* read a glyph name and return the equivalent glyph index */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 52 | static FT_Int |
| 53 | t1_get_index( const char* name, |
suzuki toshiya | d1ee378 | 2009-08-01 00:30:16 +0900 | [diff] [blame] | 54 | FT_Offset len, |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 55 | void* user_data ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 56 | { |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 57 | T1_Font type1 = (T1_Font)user_data; |
| 58 | FT_Int n; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 59 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 60 | |
suzuki toshiya | f7ecdbc | 2009-08-01 00:30:12 +0900 | [diff] [blame] | 61 | /* PS string/name length must be < 16-bit */ |
Werner Lemberg | 934d054 | 2009-11-20 06:26:22 +0100 | [diff] [blame] | 62 | if ( len > 0xFFFFU ) |
suzuki toshiya | f7ecdbc | 2009-08-01 00:30:12 +0900 | [diff] [blame] | 63 | return 0; |
| 64 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 65 | for ( n = 0; n < type1->num_glyphs; n++ ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 66 | { |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 67 | char* gname = (char*)type1->glyph_names[n]; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 68 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 69 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 70 | if ( gname && gname[0] == name[0] && |
| 71 | ft_strlen( gname ) == len && |
| 72 | ft_strncmp( gname, name, len ) == 0 ) |
| 73 | return n; |
David Turner | 9c84887 | 2000-02-28 11:32:54 +0000 | [diff] [blame] | 74 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 75 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 76 | return 0; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
| 80 | #undef KERN_INDEX |
David Turner | 5f1f750 | 2006-06-07 05:11:50 +0000 | [diff] [blame] | 81 | #define KERN_INDEX( g1, g2 ) ( ( (FT_ULong)(g1) << 16 ) | (g2) ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 82 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 83 | |
| 84 | /* compare two kerning pairs */ |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 85 | FT_CALLBACK_DEF( int ) |
David Turner | dee7813 | 2001-06-27 09:26:46 +0000 | [diff] [blame] | 86 | compare_kern_pairs( const void* a, |
| 87 | const void* b ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 88 | { |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 89 | AFM_KernPair pair1 = (AFM_KernPair)a; |
| 90 | AFM_KernPair pair2 = (AFM_KernPair)b; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 91 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 92 | FT_ULong index1 = KERN_INDEX( pair1->index1, pair1->index2 ); |
| 93 | FT_ULong index2 = KERN_INDEX( pair2->index1, pair2->index2 ); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 94 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 95 | |
Werner Lemberg | a4cb0d9 | 2008-08-23 19:54:06 +0000 | [diff] [blame] | 96 | if ( index1 > index2 ) |
| 97 | return 1; |
| 98 | else if ( index1 < index2 ) |
| 99 | return -1; |
| 100 | else |
| 101 | return 0; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 105 | /* parse a PFM file -- for now, only read the kerning pairs */ |
| 106 | static FT_Error |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 107 | T1_Read_PFM( FT_Face t1_face, |
| 108 | FT_Stream stream, |
| 109 | AFM_FontInfo fi ) |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 110 | { |
Werner Lemberg | ce94c7a | 2006-01-16 22:35:33 +0000 | [diff] [blame] | 111 | FT_Error error = T1_Err_Ok; |
| 112 | FT_Memory memory = stream->memory; |
| 113 | FT_Byte* start; |
| 114 | FT_Byte* limit; |
| 115 | FT_Byte* p; |
| 116 | AFM_KernPair kp; |
| 117 | FT_Int width_table_length; |
| 118 | FT_CharMap oldcharmap; |
| 119 | FT_CharMap charmap; |
| 120 | FT_Int n; |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 121 | |
| 122 | |
| 123 | start = (FT_Byte*)stream->cursor; |
| 124 | limit = (FT_Byte*)stream->limit; |
| 125 | p = start; |
| 126 | |
| 127 | /* Figure out how long the width table is. */ |
| 128 | /* This info is a little-endian short at offset 99. */ |
| 129 | p = start + 99; |
| 130 | if ( p + 2 > limit ) |
| 131 | { |
| 132 | error = T1_Err_Unknown_File_Format; |
| 133 | goto Exit; |
| 134 | } |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 135 | width_table_length = FT_PEEK_USHORT_LE( p ); |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 136 | |
| 137 | p += 18 + width_table_length; |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 138 | if ( p + 0x12 > limit || FT_PEEK_USHORT_LE( p ) < 0x12 ) |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 139 | /* extension table is probably optional */ |
| 140 | goto Exit; |
| 141 | |
| 142 | /* Kerning offset is 14 bytes from start of extensions table. */ |
| 143 | p += 14; |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 144 | p = start + FT_PEEK_ULONG_LE( p ); |
Werner Lemberg | ea4c3dc | 2005-11-08 09:10:16 +0000 | [diff] [blame] | 145 | |
| 146 | if ( p == start ) |
| 147 | /* zero offset means no table */ |
| 148 | goto Exit; |
| 149 | |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 150 | if ( p + 2 > limit ) |
| 151 | { |
| 152 | error = T1_Err_Unknown_File_Format; |
| 153 | goto Exit; |
| 154 | } |
| 155 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 156 | fi->NumKernPair = FT_PEEK_USHORT_LE( p ); |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 157 | p += 2; |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 158 | if ( p + 4 * fi->NumKernPair > limit ) |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 159 | { |
| 160 | error = T1_Err_Unknown_File_Format; |
| 161 | goto Exit; |
| 162 | } |
| 163 | |
| 164 | /* Actually, kerning pairs are simply optional! */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 165 | if ( fi->NumKernPair == 0 ) |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 166 | goto Exit; |
| 167 | |
| 168 | /* allocate the pairs */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 169 | if ( FT_QNEW_ARRAY( fi->KernPairs, fi->NumKernPair ) ) |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 170 | goto Exit; |
| 171 | |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 172 | /* now, read each kern pair */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 173 | kp = fi->KernPairs; |
| 174 | limit = p + 4 * fi->NumKernPair; |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 175 | |
| 176 | /* PFM kerning data are stored by encoding rather than glyph index, */ |
| 177 | /* so find the PostScript charmap of this font and install it */ |
| 178 | /* temporarily. If we find no PostScript charmap, then just use */ |
| 179 | /* the default and hope it is the right one. */ |
| 180 | oldcharmap = t1_face->charmap; |
| 181 | charmap = NULL; |
| 182 | |
| 183 | for ( n = 0; n < t1_face->num_charmaps; n++ ) |
| 184 | { |
| 185 | charmap = t1_face->charmaps[n]; |
| 186 | /* check against PostScript pseudo platform */ |
| 187 | if ( charmap->platform_id == 7 ) |
| 188 | { |
| 189 | error = FT_Set_Charmap( t1_face, charmap ); |
| 190 | if ( error ) |
| 191 | goto Exit; |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /* Kerning info is stored as: */ |
| 197 | /* */ |
| 198 | /* encoding of first glyph (1 byte) */ |
| 199 | /* encoding of second glyph (1 byte) */ |
| 200 | /* offset (little-endian short) */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 201 | for ( ; p < limit ; p += 4 ) |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 202 | { |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 203 | kp->index1 = FT_Get_Char_Index( t1_face, p[0] ); |
| 204 | kp->index2 = FT_Get_Char_Index( t1_face, p[1] ); |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 205 | |
David Turner | 085bc6e | 2007-03-05 17:40:03 +0000 | [diff] [blame] | 206 | kp->x = (FT_Int)FT_PEEK_SHORT_LE(p + 2); |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 207 | kp->y = 0; |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 208 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 209 | kp++; |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | if ( oldcharmap != NULL ) |
| 213 | error = FT_Set_Charmap( t1_face, oldcharmap ); |
| 214 | if ( error ) |
| 215 | goto Exit; |
| 216 | |
| 217 | /* now, sort the kern pairs according to their glyph indices */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 218 | ft_qsort( fi->KernPairs, fi->NumKernPair, sizeof ( AFM_KernPairRec ), |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 219 | compare_kern_pairs ); |
| 220 | |
| 221 | Exit: |
| 222 | if ( error ) |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 223 | { |
| 224 | FT_FREE( fi->KernPairs ); |
| 225 | fi->NumKernPair = 0; |
| 226 | } |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 227 | |
| 228 | return error; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /* parse a metrics file -- either AFM or PFM depending on what */ |
| 233 | /* it turns out to be */ |
| 234 | FT_LOCAL_DEF( FT_Error ) |
| 235 | T1_Read_Metrics( FT_Face t1_face, |
| 236 | FT_Stream stream ) |
| 237 | { |
Werner Lemberg | ce94c7a | 2006-01-16 22:35:33 +0000 | [diff] [blame] | 238 | PSAux_Service psaux; |
Werner Lemberg | c8f5b98 | 2010-07-12 21:13:22 +0200 | [diff] [blame] | 239 | FT_Memory memory = stream->memory; |
Werner Lemberg | ce94c7a | 2006-01-16 22:35:33 +0000 | [diff] [blame] | 240 | AFM_ParserRec parser; |
Werner Lemberg | c8f5b98 | 2010-07-12 21:13:22 +0200 | [diff] [blame] | 241 | AFM_FontInfo fi = NULL; |
| 242 | FT_Error error = T1_Err_Unknown_File_Format; |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 243 | T1_Font t1_font = &( (T1_Face)t1_face )->type1; |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 244 | |
| 245 | |
David Turner | 5f1f750 | 2006-06-07 05:11:50 +0000 | [diff] [blame] | 246 | if ( FT_NEW( fi ) || |
| 247 | FT_FRAME_ENTER( stream->size ) ) |
| 248 | goto Exit; |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 249 | |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 250 | fi->FontBBox = t1_font->font_bbox; |
| 251 | fi->Ascender = t1_font->font_bbox.yMax; |
| 252 | fi->Descender = t1_font->font_bbox.yMin; |
| 253 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 254 | psaux = (PSAux_Service)( (T1_Face)t1_face )->psaux; |
| 255 | if ( psaux && psaux->afm_parser_funcs ) |
| 256 | { |
| 257 | error = psaux->afm_parser_funcs->init( &parser, |
| 258 | stream->memory, |
| 259 | stream->cursor, |
| 260 | stream->limit ); |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 261 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 262 | if ( !error ) |
| 263 | { |
| 264 | parser.FontInfo = fi; |
| 265 | parser.get_index = t1_get_index; |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 266 | parser.user_data = t1_font; |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 267 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 268 | error = psaux->afm_parser_funcs->parse( &parser ); |
| 269 | psaux->afm_parser_funcs->done( &parser ); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if ( error == T1_Err_Unknown_File_Format ) |
| 274 | { |
| 275 | FT_Byte* start = stream->cursor; |
| 276 | |
| 277 | |
Werner Lemberg | 281c148 | 2007-01-13 22:50:51 +0000 | [diff] [blame] | 278 | /* MS Windows allows versions up to 0x3FF without complaining */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 279 | if ( stream->size > 6 && |
Werner Lemberg | 281c148 | 2007-01-13 22:50:51 +0000 | [diff] [blame] | 280 | start[1] < 4 && |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 281 | FT_PEEK_ULONG_LE( start + 2 ) == stream->size ) |
| 282 | error = T1_Read_PFM( t1_face, stream, fi ); |
| 283 | } |
| 284 | |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 285 | if ( !error ) |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 286 | { |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 287 | t1_font->font_bbox = fi->FontBBox; |
| 288 | |
Werner Lemberg | 012552f | 2009-11-04 10:06:04 +0100 | [diff] [blame] | 289 | t1_face->bbox.xMin = fi->FontBBox.xMin >> 16; |
| 290 | t1_face->bbox.yMin = fi->FontBBox.yMin >> 16; |
| 291 | /* no `U' suffix here to 0xFFFF! */ |
| 292 | t1_face->bbox.xMax = ( fi->FontBBox.xMax + 0xFFFF ) >> 16; |
| 293 | t1_face->bbox.yMax = ( fi->FontBBox.yMax + 0xFFFF ) >> 16; |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 294 | |
Werner Lemberg | 012552f | 2009-11-04 10:06:04 +0100 | [diff] [blame] | 295 | /* no `U' suffix here to 0x8000! */ |
| 296 | t1_face->ascender = (FT_Short)( ( fi->Ascender + 0x8000 ) >> 16 ); |
| 297 | t1_face->descender = (FT_Short)( ( fi->Descender + 0x8000 ) >> 16 ); |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 298 | |
| 299 | if ( fi->NumKernPair ) |
| 300 | { |
| 301 | t1_face->face_flags |= FT_FACE_FLAG_KERNING; |
| 302 | ( (T1_Face)t1_face )->afm_data = fi; |
David Turner | 5f1f750 | 2006-06-07 05:11:50 +0000 | [diff] [blame] | 303 | fi = NULL; |
Wu, Chia-I (吳佳一) | 98d802b | 2006-01-31 07:01:24 +0000 | [diff] [blame] | 304 | } |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 305 | } |
Werner Lemberg | d232f59 | 2004-08-02 05:38:33 +0000 | [diff] [blame] | 306 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 307 | FT_FRAME_EXIT(); |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 308 | |
David Turner | 5f1f750 | 2006-06-07 05:11:50 +0000 | [diff] [blame] | 309 | Exit: |
| 310 | if ( fi != NULL ) |
| 311 | T1_Done_Metrics( memory, fi ); |
| 312 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 313 | return error; |
| 314 | } |
| 315 | |
| 316 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 317 | /* find the kerning for a given glyph pair */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 318 | FT_LOCAL_DEF( void ) |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 319 | T1_Get_Kerning( AFM_FontInfo fi, |
| 320 | FT_UInt glyph1, |
| 321 | FT_UInt glyph2, |
| 322 | FT_Vector* kerning ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 323 | { |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 324 | AFM_KernPair min, mid, max; |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 325 | FT_ULong idx = KERN_INDEX( glyph1, glyph2 ); |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 326 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 327 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 328 | /* simple binary search */ |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 329 | min = fi->KernPairs; |
| 330 | max = min + fi->NumKernPair - 1; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 331 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 332 | while ( min <= max ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 333 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 334 | FT_ULong midi; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 335 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 336 | |
| 337 | mid = min + ( max - min ) / 2; |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 338 | midi = KERN_INDEX( mid->index1, mid->index2 ); |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 339 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 340 | if ( midi == idx ) |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 341 | { |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 342 | kerning->x = mid->x; |
| 343 | kerning->y = mid->y; |
| 344 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 345 | return; |
| 346 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 347 | |
Werner Lemberg | 0d9165e | 2002-03-07 21:59:59 +0000 | [diff] [blame] | 348 | if ( midi < idx ) |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 349 | min = mid + 1; |
| 350 | else |
| 351 | max = mid - 1; |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 352 | } |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 353 | |
David Turner | 95bec28 | 2000-02-15 12:55:57 +0000 | [diff] [blame] | 354 | kerning->x = 0; |
| 355 | kerning->y = 0; |
| 356 | } |
| 357 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 358 | |
Wu, Chia-I (吳佳一) | 108fdbb | 2006-01-16 15:35:56 +0000 | [diff] [blame] | 359 | FT_LOCAL_DEF( FT_Error ) |
| 360 | T1_Get_Track_Kerning( FT_Face face, |
| 361 | FT_Fixed ptsize, |
| 362 | FT_Int degree, |
| 363 | FT_Fixed* kerning ) |
| 364 | { |
| 365 | AFM_FontInfo fi = (AFM_FontInfo)( (T1_Face)face )->afm_data; |
| 366 | FT_Int i; |
| 367 | |
| 368 | |
| 369 | if ( !fi ) |
| 370 | return T1_Err_Invalid_Argument; |
| 371 | |
| 372 | for ( i = 0; i < fi->NumTrackKern; i++ ) |
| 373 | { |
| 374 | AFM_TrackKern tk = fi->TrackKerns + i; |
| 375 | |
| 376 | |
| 377 | if ( tk->degree != degree ) |
| 378 | continue; |
| 379 | |
| 380 | if ( ptsize < tk->min_ptsize ) |
| 381 | *kerning = tk->min_kern; |
| 382 | else if ( ptsize > tk->max_ptsize ) |
| 383 | *kerning = tk->max_kern; |
| 384 | else |
| 385 | { |
| 386 | *kerning = FT_MulDiv( ptsize - tk->min_ptsize, |
| 387 | tk->max_kern - tk->min_kern, |
| 388 | tk->max_ptsize - tk->min_ptsize ) + |
| 389 | tk->min_kern; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | return T1_Err_Ok; |
| 394 | } |
| 395 | |
| 396 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 397 | /* END */ |