David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* ttload.c */ |
| 4 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 5 | /* Load the basic TrueType tables, i.e., tables that can be either in */ |
| 6 | /* TTF or OTF fonts (body). */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 7 | /* */ |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 8 | /* Copyright 1996-2001 by */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 9 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 10 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 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 */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 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 | /* */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 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> |
| 21 | #include FT_INTERNAL_DEBUG_H |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 22 | #include FT_INTERNAL_STREAM_H |
| 23 | #include FT_TRUETYPE_TAGS_H |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 24 | #include "ttload.h" |
| 25 | #include "ttcmap.h" |
David Turner | a90663f | 2000-07-08 00:41:13 +0000 | [diff] [blame] | 26 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 27 | #include "sferrors.h" |
| 28 | |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 29 | #include <stdlib.h> /* for qsort */ |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 30 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 31 | /*************************************************************************/ |
| 32 | /* */ |
| 33 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 34 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 35 | /* messages during execution. */ |
| 36 | /* */ |
| 37 | #undef FT_COMPONENT |
| 38 | #define FT_COMPONENT trace_ttload |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 39 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 40 | |
| 41 | /*************************************************************************/ |
| 42 | /* */ |
| 43 | /* <Function> */ |
| 44 | /* TT_LookUp_Table */ |
| 45 | /* */ |
| 46 | /* <Description> */ |
| 47 | /* Looks for a TrueType table by name. */ |
| 48 | /* */ |
| 49 | /* <Input> */ |
| 50 | /* face :: A face object handle. */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 51 | /* tag :: The searched tag. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 52 | /* */ |
| 53 | /* <Return> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 54 | /* A pointer to the table directory entry. 0 if not found. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 55 | /* */ |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 56 | FT_LOCAL_DEF( TT_Table ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 57 | TT_LookUp_Table( TT_Face face, |
| 58 | FT_ULong tag ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 59 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 60 | TT_Table entry; |
| 61 | TT_Table limit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 62 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 63 | |
Tom Kacvinsky | 200a1a4 | 2000-11-13 07:31:21 +0000 | [diff] [blame] | 64 | FT_TRACE3(( "TT_LookUp_Table: %08p, `%c%c%c%c' -- ", |
Werner Lemberg | 34e5270 | 2000-11-13 16:58:01 +0000 | [diff] [blame] | 65 | face, |
| 66 | (FT_Char)( tag >> 24 ), |
| 67 | (FT_Char)( tag >> 16 ), |
| 68 | (FT_Char)( tag >> 8 ), |
| 69 | (FT_Char)( tag ) )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 70 | |
| 71 | entry = face->dir_tables; |
| 72 | limit = entry + face->num_tables; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 73 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 74 | for ( ; entry < limit; entry++ ) |
| 75 | { |
| 76 | if ( entry->Tag == tag ) |
Tom Kacvinsky | 200a1a4 | 2000-11-13 07:31:21 +0000 | [diff] [blame] | 77 | { |
Werner Lemberg | 34e5270 | 2000-11-13 16:58:01 +0000 | [diff] [blame] | 78 | FT_TRACE3(( "found table.\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 79 | return entry; |
Tom Kacvinsky | 200a1a4 | 2000-11-13 07:31:21 +0000 | [diff] [blame] | 80 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 81 | } |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 82 | |
Tom Kacvinsky | 200a1a4 | 2000-11-13 07:31:21 +0000 | [diff] [blame] | 83 | FT_TRACE3(( "could not find table!\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 87 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 88 | /*************************************************************************/ |
| 89 | /* */ |
| 90 | /* <Function> */ |
| 91 | /* TT_Goto_Table */ |
| 92 | /* */ |
| 93 | /* <Description> */ |
| 94 | /* Looks for a TrueType table by name, then seek a stream to it. */ |
| 95 | /* */ |
| 96 | /* <Input> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 97 | /* face :: A face object handle. */ |
| 98 | /* tag :: The searched tag. */ |
| 99 | /* stream :: The stream to seek when the table is found. */ |
| 100 | /* */ |
| 101 | /* <Output> */ |
| 102 | /* length :: The length of the table if found, undefined otherwise. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 103 | /* */ |
| 104 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 105 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 106 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 107 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 108 | TT_Goto_Table( TT_Face face, |
| 109 | FT_ULong tag, |
| 110 | FT_Stream stream, |
| 111 | FT_ULong* length ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 112 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 113 | TT_Table table; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 114 | FT_Error error; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 115 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 116 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 117 | table = TT_LookUp_Table( face, tag ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 118 | if ( table ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 119 | { |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 120 | if ( length ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 121 | *length = table->Length; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 122 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 123 | if ( FT_STREAM_SEEK( table->Offset ) ) |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 124 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 125 | } |
| 126 | else |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 127 | error = SFNT_Err_Table_Missing; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 128 | |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 129 | Exit: |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 130 | return error; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /*************************************************************************/ |
| 135 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 136 | /* <Function> */ |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 137 | /* TT_Load_SFNT_HeaderRec */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 138 | /* */ |
| 139 | /* <Description> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 140 | /* Loads the header of a SFNT font file. Supports collections. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 141 | /* */ |
| 142 | /* <Input> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 143 | /* face :: A handle to the target face object. */ |
| 144 | /* stream :: The input stream. */ |
| 145 | /* face_index :: If the font is a collection, the number of the font */ |
| 146 | /* in the collection, ignored otherwise. */ |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 147 | /* */ |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 148 | /* <Output> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 149 | /* sfnt :: The SFNT header. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 150 | /* */ |
| 151 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 152 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 153 | /* */ |
| 154 | /* <Note> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 155 | /* The stream cursor must be at the font file's origin. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 156 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 157 | /* This function recognizes fonts embedded in a `TrueType collection' */ |
| 158 | /* */ |
| 159 | /* The header will be checked whether it is valid by looking at the */ |
| 160 | /* values of `search_range', `entry_selector', and `range_shift'. */ |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 161 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 162 | FT_LOCAL_DEF( FT_Error ) |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 163 | TT_Load_SFNT_HeaderRec( TT_Face face, |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 164 | FT_Stream stream, |
| 165 | FT_Long face_index, |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 166 | SFNT_Header sfnt ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 167 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 168 | FT_Error error; |
| 169 | FT_ULong format_tag; |
Werner Lemberg | 7a4fda8 | 2000-06-13 23:21:00 +0000 | [diff] [blame] | 170 | FT_Memory memory = stream->memory; |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 171 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 172 | const FT_Frame_Field sfnt_header_fields[] = |
| 173 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 174 | #undef FT_STRUCTURE |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 175 | #define FT_STRUCTURE SFNT_HeaderRec |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 176 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 177 | FT_FRAME_START( 8 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 178 | FT_FRAME_USHORT( num_tables ), |
| 179 | FT_FRAME_USHORT( search_range ), |
| 180 | FT_FRAME_USHORT( entry_selector ), |
| 181 | FT_FRAME_USHORT( range_shift ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 182 | FT_FRAME_END |
| 183 | }; |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 184 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 185 | const FT_Frame_Field ttc_header_fields[] = |
| 186 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 187 | #undef FT_STRUCTURE |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 188 | #define FT_STRUCTURE TTC_HeaderRec |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 189 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 190 | FT_FRAME_START( 8 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 191 | FT_FRAME_LONG( version ), |
| 192 | FT_FRAME_LONG( count ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 193 | FT_FRAME_END }; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 194 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 195 | |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 196 | FT_TRACE2(( "TT_Load_SFNT_HeaderRec: %08p, %ld\n", |
David Turner | 3581d06 | 2000-06-01 03:26:58 +0000 | [diff] [blame] | 197 | face, face_index )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 198 | |
Werner Lemberg | e1bbc01 | 2000-07-19 06:25:56 +0000 | [diff] [blame] | 199 | face->ttc_header.tag = 0; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 200 | face->ttc_header.version = 0; |
Werner Lemberg | e1bbc01 | 2000-07-19 06:25:56 +0000 | [diff] [blame] | 201 | face->ttc_header.count = 0; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 202 | |
| 203 | face->num_tables = 0; |
| 204 | |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 205 | /* first of all, read the first 4 bytes. If it is `ttcf', then the */ |
| 206 | /* file is a TrueType collection, otherwise it can be any other */ |
| 207 | /* kind of font. */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 208 | if ( FT_READ_ULONG( format_tag ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 209 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 210 | |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 211 | if ( format_tag == TTAG_ttcf ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 212 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 213 | FT_Int n; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 214 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 215 | |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 216 | FT_TRACE3(( "TT_Load_SFNT_HeaderRec: file is a collection\n" )); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 217 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 218 | /* it's a TrueType collection, i.e. a file containing several */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 219 | /* font files. Read the font directory now */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 220 | if ( FT_STREAM_READ_FIELDS( ttc_header_fields, &face->ttc_header ) ) |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 221 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 222 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 223 | /* now read the offsets of each font in the file */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 224 | if ( FT_NEW_ARRAY( face->ttc_header.offsets, face->ttc_header.count ) || |
| 225 | FT_FRAME_ENTER( face->ttc_header.count * 4L ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 226 | goto Exit; |
| 227 | |
Werner Lemberg | e1bbc01 | 2000-07-19 06:25:56 +0000 | [diff] [blame] | 228 | for ( n = 0; n < face->ttc_header.count; n++ ) |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 229 | face->ttc_header.offsets[n] = FT_GET_ULONG(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 230 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 231 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 232 | |
| 233 | /* check face index */ |
Werner Lemberg | e1bbc01 | 2000-07-19 06:25:56 +0000 | [diff] [blame] | 234 | if ( face_index >= face->ttc_header.count ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 235 | { |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 236 | error = SFNT_Err_Bad_Argument; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 237 | goto Exit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 238 | } |
| 239 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 240 | /* seek to the appropriate TrueType file, then read tag */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 241 | if ( FT_STREAM_SEEK( face->ttc_header.offsets[face_index] ) || |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 242 | FT_READ_LONG( format_tag ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 243 | goto Exit; |
| 244 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 245 | |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 246 | /* the format tag was read, now check the rest of the header */ |
| 247 | sfnt->format_tag = format_tag; |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 248 | if ( FT_STREAM_READ_FIELDS( sfnt_header_fields, sfnt ) ) |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 249 | goto Exit; |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 250 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 251 | /* now, check the values of `num_tables', `seach_range', etc. */ |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 252 | { |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 253 | FT_UInt num_tables = sfnt->num_tables; |
| 254 | FT_ULong entry_selector = 1L << sfnt->entry_selector; |
David Turner | 3581d06 | 2000-06-01 03:26:58 +0000 | [diff] [blame] | 255 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 256 | |
| 257 | /* IMPORTANT: Many fonts have an incorrect `search_range' value, so */ |
| 258 | /* we only check the `entry_selector' correctness here. */ |
| 259 | /* */ |
| 260 | if ( num_tables == 0 || |
| 261 | entry_selector > num_tables || |
| 262 | entry_selector * 2 <= num_tables ) |
David Turner | 3581d06 | 2000-06-01 03:26:58 +0000 | [diff] [blame] | 263 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 264 | FT_TRACE2(( "TT_Load_SFNT_HeaderRec: file is not SFNT!\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 265 | error = SFNT_Err_Unknown_File_Format; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 269 | Exit: |
| 270 | return error; |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 271 | } |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 272 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 273 | |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 274 | /*************************************************************************/ |
| 275 | /* */ |
| 276 | /* <Function> */ |
| 277 | /* TT_Load_Directory */ |
| 278 | /* */ |
| 279 | /* <Description> */ |
| 280 | /* Loads the table directory into a face object. */ |
| 281 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 282 | /* <InOut> */ |
| 283 | /* face :: A handle to the target face object. */ |
| 284 | /* */ |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 285 | /* <Input> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 286 | /* stream :: The input stream. */ |
| 287 | /* sfnt :: The SFNT directory header. */ |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 288 | /* */ |
| 289 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 290 | /* FreeType error code. 0 means success. */ |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 291 | /* */ |
| 292 | /* <Note> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 293 | /* The stream cursor must be at the font file's origin. */ |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 294 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 295 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 296 | TT_Load_Directory( TT_Face face, |
| 297 | FT_Stream stream, |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 298 | SFNT_Header sfnt ) |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 299 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 300 | FT_Error error; |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 301 | FT_Memory memory = stream->memory; |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 302 | |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 303 | TT_TableRec *entry, *limit; |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 304 | |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 305 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 306 | FT_TRACE2(( "TT_Load_Directory: %08p\n", face )); |
| 307 | |
| 308 | FT_TRACE2(( "-- Tables count: %12u\n", sfnt->num_tables )); |
| 309 | FT_TRACE2(( "-- Format version: %08lx\n", sfnt->format_tag )); |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 310 | |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 311 | face->num_tables = sfnt->num_tables; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 312 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 313 | if ( FT_NEW_ARRAY( face->dir_tables, face->num_tables ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 314 | goto Exit; |
| 315 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 316 | if ( FT_FRAME_ENTER( face->num_tables * 16L ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 317 | goto Exit; |
| 318 | |
| 319 | entry = face->dir_tables; |
| 320 | limit = entry + face->num_tables; |
| 321 | |
| 322 | for ( ; entry < limit; entry++ ) |
David Turner | d42c68e | 2000-01-27 13:56:02 +0000 | [diff] [blame] | 323 | { /* loop through the tables and get all entries */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 324 | entry->Tag = FT_GET_TAG4(); |
| 325 | entry->CheckSum = FT_GET_ULONG(); |
| 326 | entry->Offset = FT_GET_LONG(); |
| 327 | entry->Length = FT_GET_LONG(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 328 | |
| 329 | FT_TRACE2(( " %c%c%c%c - %08lx - %08lx\n", |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 330 | (FT_Char)( entry->Tag >> 24 ), |
| 331 | (FT_Char)( entry->Tag >> 16 ), |
| 332 | (FT_Char)( entry->Tag >> 8 ), |
| 333 | (FT_Char)( entry->Tag ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 334 | entry->Offset, |
| 335 | entry->Length )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 336 | } |
| 337 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 338 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 339 | |
| 340 | FT_TRACE2(( "Directory loaded\n\n" )); |
| 341 | |
| 342 | Exit: |
| 343 | return error; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /*************************************************************************/ |
| 348 | /* */ |
| 349 | /* <Function> */ |
| 350 | /* TT_Load_Any */ |
| 351 | /* */ |
| 352 | /* <Description> */ |
Werner Lemberg | c8f9cf3 | 2000-07-19 02:59:31 +0000 | [diff] [blame] | 353 | /* Loads any font table into client memory. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 354 | /* */ |
| 355 | /* <Input> */ |
| 356 | /* face :: The face object to look for. */ |
| 357 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 358 | /* tag :: The tag of table to load. Use the value 0 if you want */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 359 | /* to access the whole font file, else set this parameter */ |
| 360 | /* to a valid TrueType table tag that you can forge with */ |
| 361 | /* the MAKE_TT_TAG macro. */ |
| 362 | /* */ |
| 363 | /* offset :: The starting offset in the table (or the file if */ |
| 364 | /* tag == 0). */ |
| 365 | /* */ |
| 366 | /* length :: The address of the decision variable: */ |
| 367 | /* */ |
| 368 | /* If length == NULL: */ |
| 369 | /* Loads the whole table. Returns an error if */ |
| 370 | /* `offset' == 0! */ |
| 371 | /* */ |
| 372 | /* If *length == 0: */ |
| 373 | /* Exits immediately; returning the length of the given */ |
| 374 | /* table or of the font file, depending on the value of */ |
| 375 | /* `tag'. */ |
| 376 | /* */ |
| 377 | /* If *length != 0: */ |
| 378 | /* Loads the next `length' bytes of table or font, */ |
| 379 | /* starting at offset `offset' (in table or font too). */ |
| 380 | /* */ |
| 381 | /* <Output> */ |
| 382 | /* buffer :: The address of target buffer. */ |
| 383 | /* */ |
| 384 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 385 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 386 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 387 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 388 | TT_Load_Any( TT_Face face, |
| 389 | FT_ULong tag, |
| 390 | FT_Long offset, |
| 391 | FT_Byte* buffer, |
| 392 | FT_ULong* length ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 393 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 394 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 395 | FT_Stream stream; |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 396 | TT_Table table; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 397 | FT_ULong size; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 398 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 399 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 400 | if ( tag != 0 ) |
| 401 | { |
| 402 | /* look for tag in font directory */ |
| 403 | table = TT_LookUp_Table( face, tag ); |
| 404 | if ( !table ) |
| 405 | { |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 406 | error = SFNT_Err_Table_Missing; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 407 | goto Exit; |
| 408 | } |
| 409 | |
| 410 | offset += table->Offset; |
| 411 | size = table->Length; |
| 412 | } |
| 413 | else |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 414 | /* tag == 0 -- the user wants to access the font file directly */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 415 | size = face->root.stream->size; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 416 | |
| 417 | if ( length && *length == 0 ) |
| 418 | { |
| 419 | *length = size; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 420 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 421 | return SFNT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | if ( length ) |
| 425 | size = *length; |
| 426 | |
| 427 | stream = face->root.stream; |
Werner Lemberg | b1dd353 | 2000-07-31 22:51:00 +0000 | [diff] [blame] | 428 | /* the `if' is syntactic sugar for picky compilers */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 429 | if ( FT_STREAM_READ_AT( offset, buffer, size ) ) |
David Turner | 24d7024 | 2000-08-17 01:09:06 +0000 | [diff] [blame] | 430 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 431 | |
| 432 | Exit: |
| 433 | return error; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | /*************************************************************************/ |
| 438 | /* */ |
| 439 | /* <Function> */ |
Tom Kacvinsky | 200a1a4 | 2000-11-13 07:31:21 +0000 | [diff] [blame] | 440 | /* TT_Load_Generic_Header */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 441 | /* */ |
| 442 | /* <Description> */ |
Tom Kacvinsky | 200a1a4 | 2000-11-13 07:31:21 +0000 | [diff] [blame] | 443 | /* Loads the TrueType table `head' or `bhed'. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 444 | /* */ |
| 445 | /* <Input> */ |
| 446 | /* face :: A handle to the target face object. */ |
| 447 | /* stream :: The input stream. */ |
| 448 | /* */ |
| 449 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 450 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 451 | /* */ |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 452 | static FT_Error |
| 453 | TT_Load_Generic_Header( TT_Face face, |
| 454 | FT_Stream stream, |
| 455 | FT_ULong tag ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 456 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 457 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 458 | TT_Header* header; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 459 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 460 | static const FT_Frame_Field header_fields[] = |
| 461 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 462 | #undef FT_STRUCTURE |
| 463 | #define FT_STRUCTURE TT_Header |
| 464 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 465 | FT_FRAME_START( 54 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 466 | FT_FRAME_ULONG ( Table_Version ), |
| 467 | FT_FRAME_ULONG ( Font_Revision ), |
| 468 | FT_FRAME_LONG ( CheckSum_Adjust ), |
| 469 | FT_FRAME_LONG ( Magic_Number ), |
| 470 | FT_FRAME_USHORT( Flags ), |
| 471 | FT_FRAME_USHORT( Units_Per_EM ), |
| 472 | FT_FRAME_LONG ( Created[0] ), |
| 473 | FT_FRAME_LONG ( Created[1] ), |
| 474 | FT_FRAME_LONG ( Modified[0] ), |
| 475 | FT_FRAME_LONG ( Modified[1] ), |
| 476 | FT_FRAME_SHORT ( xMin ), |
| 477 | FT_FRAME_SHORT ( yMin ), |
| 478 | FT_FRAME_SHORT ( xMax ), |
| 479 | FT_FRAME_SHORT ( yMax ), |
| 480 | FT_FRAME_USHORT( Mac_Style ), |
| 481 | FT_FRAME_USHORT( Lowest_Rec_PPEM ), |
| 482 | FT_FRAME_SHORT ( Font_Direction ), |
| 483 | FT_FRAME_SHORT ( Index_To_Loc_Format ), |
| 484 | FT_FRAME_SHORT ( Glyph_Data_Format ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 485 | FT_FRAME_END |
| 486 | }; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 487 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 488 | |
Werner Lemberg | 34e5270 | 2000-11-13 16:58:01 +0000 | [diff] [blame] | 489 | FT_TRACE2(( "TT_Load_Generic_Header: " |
| 490 | "%08p, looking up font table `%c%c%c%c'.\n", |
| 491 | face, |
| 492 | (FT_Char)( tag >> 24 ), |
| 493 | (FT_Char)( tag >> 16 ), |
| 494 | (FT_Char)( tag >> 8 ), |
| 495 | (FT_Char)( tag ) )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 496 | |
David Turner | f96594f | 2000-11-06 23:07:51 +0000 | [diff] [blame] | 497 | error = face->goto_table( face, tag, stream, 0 ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 498 | if ( error ) |
| 499 | { |
Werner Lemberg | 04bfe31 | 2001-12-11 14:09:06 +0000 | [diff] [blame] | 500 | FT_TRACE2(( "TT_Load_Generic_Header: Font table is missing!\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 501 | goto Exit; |
| 502 | } |
| 503 | |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 504 | header = &face->header; |
| 505 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 506 | if ( FT_STREAM_READ_FIELDS( header_fields, header ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 507 | goto Exit; |
| 508 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 509 | FT_TRACE2(( " Units per EM: %8u\n", header->Units_Per_EM )); |
| 510 | FT_TRACE2(( " IndexToLoc: %8d\n", header->Index_To_Loc_Format )); |
Werner Lemberg | 04bfe31 | 2001-12-11 14:09:06 +0000 | [diff] [blame] | 511 | FT_TRACE2(( "TT_Load_Generic_Header: Font table loaded.\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 512 | |
| 513 | Exit: |
| 514 | return error; |
| 515 | } |
| 516 | |
Werner Lemberg | 4b68007 | 2000-11-07 06:30:29 +0000 | [diff] [blame] | 517 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 518 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 519 | TT_Load_Header( TT_Face face, |
| 520 | FT_Stream stream ) |
David Turner | f96594f | 2000-11-06 23:07:51 +0000 | [diff] [blame] | 521 | { |
| 522 | return TT_Load_Generic_Header( face, stream, TTAG_head ); |
| 523 | } |
| 524 | |
Werner Lemberg | 4b68007 | 2000-11-07 06:30:29 +0000 | [diff] [blame] | 525 | |
David Turner | f96594f | 2000-11-06 23:07:51 +0000 | [diff] [blame] | 526 | #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS |
Werner Lemberg | 4b68007 | 2000-11-07 06:30:29 +0000 | [diff] [blame] | 527 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 528 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 529 | TT_Load_Bitmap_Header( TT_Face face, |
| 530 | FT_Stream stream ) |
David Turner | f96594f | 2000-11-06 23:07:51 +0000 | [diff] [blame] | 531 | { |
| 532 | return TT_Load_Generic_Header( face, stream, TTAG_bhed ); |
| 533 | } |
Werner Lemberg | 4b68007 | 2000-11-07 06:30:29 +0000 | [diff] [blame] | 534 | |
| 535 | #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ |
| 536 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 537 | |
| 538 | /*************************************************************************/ |
| 539 | /* */ |
| 540 | /* <Function> */ |
| 541 | /* TT_Load_MaxProfile */ |
| 542 | /* */ |
| 543 | /* <Description> */ |
| 544 | /* Loads the maximum profile into a face object. */ |
| 545 | /* */ |
| 546 | /* <Input> */ |
| 547 | /* face :: A handle to the target face object. */ |
| 548 | /* stream :: The input stream. */ |
| 549 | /* */ |
| 550 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 551 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 552 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 553 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 554 | TT_Load_MaxProfile( TT_Face face, |
| 555 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 556 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 557 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 558 | TT_MaxProfile* maxProfile = &face->max_profile; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 559 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 560 | const FT_Frame_Field maxp_fields[] = |
| 561 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 562 | #undef FT_STRUCTURE |
| 563 | #define FT_STRUCTURE TT_MaxProfile |
| 564 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 565 | FT_FRAME_START( 6 ), |
| 566 | FT_FRAME_LONG ( version ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 567 | FT_FRAME_USHORT( numGlyphs ), |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 568 | FT_FRAME_END |
| 569 | }; |
| 570 | |
| 571 | const FT_Frame_Field maxp_fields_extra[] = |
| 572 | { |
| 573 | FT_FRAME_START( 26 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 574 | FT_FRAME_USHORT( maxPoints ), |
| 575 | FT_FRAME_USHORT( maxContours ), |
| 576 | FT_FRAME_USHORT( maxCompositePoints ), |
| 577 | FT_FRAME_USHORT( maxCompositeContours ), |
| 578 | FT_FRAME_USHORT( maxZones ), |
| 579 | FT_FRAME_USHORT( maxTwilightPoints ), |
| 580 | FT_FRAME_USHORT( maxStorage ), |
| 581 | FT_FRAME_USHORT( maxFunctionDefs ), |
| 582 | FT_FRAME_USHORT( maxInstructionDefs ), |
| 583 | FT_FRAME_USHORT( maxStackElements ), |
| 584 | FT_FRAME_USHORT( maxSizeOfInstructions ), |
| 585 | FT_FRAME_USHORT( maxComponentElements ), |
| 586 | FT_FRAME_USHORT( maxComponentDepth ), |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 587 | FT_FRAME_END |
| 588 | }; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 589 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 590 | |
| 591 | FT_TRACE2(( "Load_TT_MaxProfile: %08p\n", face )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 592 | |
| 593 | error = face->goto_table( face, TTAG_maxp, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 594 | if ( error ) |
| 595 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 596 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 597 | if ( FT_STREAM_READ_FIELDS( maxp_fields, maxProfile ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 598 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 599 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 600 | maxProfile->maxPoints = 0; |
| 601 | maxProfile->maxContours = 0; |
| 602 | maxProfile->maxCompositePoints = 0; |
| 603 | maxProfile->maxCompositeContours = 0; |
| 604 | maxProfile->maxZones = 0; |
| 605 | maxProfile->maxTwilightPoints = 0; |
| 606 | maxProfile->maxStorage = 0; |
| 607 | maxProfile->maxFunctionDefs = 0; |
| 608 | maxProfile->maxInstructionDefs = 0; |
| 609 | maxProfile->maxStackElements = 0; |
| 610 | maxProfile->maxSizeOfInstructions = 0; |
| 611 | maxProfile->maxComponentElements = 0; |
| 612 | maxProfile->maxComponentDepth = 0; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 613 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 614 | if ( maxProfile->version >= 0x10000L ) |
| 615 | { |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 616 | if ( FT_STREAM_READ_FIELDS( maxp_fields_extra, maxProfile ) ) |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 617 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 618 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 619 | /* XXX: an adjustment that is necessary to load certain */ |
| 620 | /* broken fonts like `Keystrokes MT' :-( */ |
| 621 | /* */ |
| 622 | /* We allocate 64 function entries by default when */ |
| 623 | /* the maxFunctionDefs field is null. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 624 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 625 | if ( maxProfile->maxFunctionDefs == 0 ) |
| 626 | maxProfile->maxFunctionDefs = 64; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 627 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 628 | face->root.num_glyphs = maxProfile->numGlyphs; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 629 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 630 | face->root.internal->max_points = |
| 631 | (FT_UShort)MAX( maxProfile->maxCompositePoints, |
| 632 | maxProfile->maxPoints ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 633 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 634 | face->root.internal->max_contours = |
| 635 | (FT_Short)MAX( maxProfile->maxCompositeContours, |
| 636 | maxProfile->maxContours ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 637 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 638 | face->max_components = (FT_ULong)maxProfile->maxComponentElements + |
| 639 | maxProfile->maxComponentDepth; |
| 640 | |
| 641 | /* XXX: some fonts have maxComponents set to 0; we will */ |
| 642 | /* then use 16 of them by default. */ |
| 643 | if ( face->max_components == 0 ) |
| 644 | face->max_components = 16; |
| 645 | |
| 646 | /* We also increase maxPoints and maxContours in order to support */ |
| 647 | /* some broken fonts. */ |
Werner Lemberg | 3975e2e | 2002-01-09 21:01:18 +0000 | [diff] [blame] | 648 | face->root.internal->max_points += (FT_UShort)8; |
| 649 | face->root.internal->max_contours += (FT_Short) 4; |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 650 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 651 | |
| 652 | FT_TRACE2(( "MAXP loaded.\n" )); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 653 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 654 | Exit: |
| 655 | return error; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | /*************************************************************************/ |
| 660 | /* */ |
| 661 | /* <Function> */ |
| 662 | /* TT_Load_Metrics */ |
| 663 | /* */ |
| 664 | /* <Description> */ |
| 665 | /* Loads the horizontal or vertical metrics table into a face object. */ |
| 666 | /* */ |
| 667 | /* <Input> */ |
| 668 | /* face :: A handle to the target face object. */ |
| 669 | /* stream :: The input stream. */ |
| 670 | /* vertical :: A boolean flag. If set, load vertical metrics. */ |
| 671 | /* */ |
| 672 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 673 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 674 | /* */ |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 675 | static FT_Error |
| 676 | TT_Load_Metrics( TT_Face face, |
| 677 | FT_Stream stream, |
| 678 | FT_Bool vertical ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 679 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 680 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 681 | FT_Memory memory = stream->memory; |
| 682 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 683 | FT_ULong table_len; |
| 684 | FT_Long num_shorts, num_longs, num_shorts_checked; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 685 | |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 686 | TT_LongMetrics * longs; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 687 | TT_ShortMetrics** shorts; |
| 688 | |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 689 | |
| 690 | FT_TRACE2(( "TT_Load_%s_Metrics: %08p\n", vertical ? "Vertical" |
| 691 | : "Horizontal", |
| 692 | face )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 693 | |
| 694 | if ( vertical ) |
| 695 | { |
| 696 | /* The table is optional, quit silently if it wasn't found */ |
| 697 | /* XXX: Some fonts have a valid vertical header with a non-null */ |
| 698 | /* `number_of_VMetrics' fields, but no corresponding `vmtx' */ |
| 699 | /* table to get the metrics from (e.g. mingliu). */ |
| 700 | /* */ |
| 701 | /* For safety, we set the field to 0! */ |
| 702 | /* */ |
| 703 | error = face->goto_table( face, TTAG_vmtx, stream, &table_len ); |
| 704 | if ( error ) |
| 705 | { |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 706 | /* Set number_Of_VMetrics to 0! */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 707 | FT_TRACE2(( " no vertical header in file.\n" )); |
| 708 | face->vertical.number_Of_VMetrics = 0; |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 709 | error = SFNT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 710 | goto Exit; |
| 711 | } |
| 712 | |
| 713 | num_longs = face->vertical.number_Of_VMetrics; |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 714 | longs = (TT_LongMetrics *)&face->vertical.long_metrics; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 715 | shorts = (TT_ShortMetrics**)&face->vertical.short_metrics; |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | error = face->goto_table( face, TTAG_hmtx, stream, &table_len ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 720 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 721 | { |
| 722 | FT_ERROR(( " no horizontal metrics in file!\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 723 | error = SFNT_Err_Hmtx_Table_Missing; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 724 | goto Exit; |
| 725 | } |
| 726 | |
| 727 | num_longs = face->horizontal.number_Of_HMetrics; |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 728 | longs = (TT_LongMetrics *)&face->horizontal.long_metrics; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 729 | shorts = (TT_ShortMetrics**)&face->horizontal.short_metrics; |
| 730 | } |
| 731 | |
| 732 | /* never trust derived values */ |
| 733 | |
| 734 | num_shorts = face->max_profile.numGlyphs - num_longs; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 735 | num_shorts_checked = ( table_len - num_longs * 4L ) / 2; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 736 | |
| 737 | if ( num_shorts < 0 ) |
| 738 | { |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 739 | FT_ERROR(( "TT_Load_%s_Metrics: more metrics than glyphs!\n", |
| 740 | vertical ? "Vertical" |
| 741 | : "Horizontal" )); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 742 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 743 | error = vertical ? SFNT_Err_Invalid_Vert_Metrics |
| 744 | : SFNT_Err_Invalid_Horiz_Metrics; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 745 | goto Exit; |
| 746 | } |
| 747 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 748 | if ( FT_NEW_ARRAY( *longs, num_longs ) || |
| 749 | FT_NEW_ARRAY( *shorts, num_shorts ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 750 | goto Exit; |
| 751 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 752 | if ( FT_FRAME_ENTER( table_len ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 753 | goto Exit; |
| 754 | |
| 755 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 756 | TT_LongMetrics cur = *longs; |
| 757 | TT_LongMetrics limit = cur + num_longs; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 758 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 759 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 760 | for ( ; cur < limit; cur++ ) |
| 761 | { |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 762 | cur->advance = FT_GET_USHORT(); |
| 763 | cur->bearing = FT_GET_SHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 767 | /* do we have an inconsistent number of metric values? */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 768 | { |
| 769 | TT_ShortMetrics* cur = *shorts; |
| 770 | TT_ShortMetrics* limit = cur + MIN( num_shorts, num_shorts_checked ); |
| 771 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 772 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 773 | for ( ; cur < limit; cur++ ) |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 774 | *cur = FT_GET_SHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 775 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 776 | /* we fill up the missing left side bearings with the */ |
| 777 | /* last valid value. Since this will occur for buggy CJK */ |
| 778 | /* fonts usually only, nothing serious will happen */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 779 | if ( num_shorts > num_shorts_checked && num_shorts_checked > 0 ) |
| 780 | { |
Tom Kacvinsky | 4a1bc8f | 2001-04-02 17:47:16 +0000 | [diff] [blame] | 781 | FT_Short val = (*shorts)[num_shorts_checked - 1]; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 782 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 783 | |
| 784 | limit = *shorts + num_shorts; |
| 785 | for ( ; cur < limit; cur++ ) |
| 786 | *cur = val; |
| 787 | } |
| 788 | } |
| 789 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 790 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 791 | |
| 792 | FT_TRACE2(( "loaded\n" )); |
| 793 | |
| 794 | Exit: |
| 795 | return error; |
| 796 | } |
| 797 | |
| 798 | |
| 799 | /*************************************************************************/ |
| 800 | /* */ |
| 801 | /* <Function> */ |
| 802 | /* TT_Load_Metrics_Header */ |
| 803 | /* */ |
| 804 | /* <Description> */ |
| 805 | /* Loads the horizontal or vertical header in a face object. */ |
| 806 | /* */ |
| 807 | /* <Input> */ |
| 808 | /* face :: A handle to the target face object. */ |
| 809 | /* stream :: The input stream. */ |
| 810 | /* vertical :: A boolean flag. If set, load vertical metrics. */ |
| 811 | /* */ |
| 812 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 813 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 814 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 815 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 816 | TT_Load_Metrics_Header( TT_Face face, |
| 817 | FT_Stream stream, |
| 818 | FT_Bool vertical ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 819 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 820 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 821 | TT_HoriHeader* header; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 822 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 823 | const FT_Frame_Field metrics_header_fields[] = |
| 824 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 825 | #undef FT_STRUCTURE |
| 826 | #define FT_STRUCTURE TT_HoriHeader |
| 827 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 828 | FT_FRAME_START( 36 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 829 | FT_FRAME_ULONG ( Version ), |
| 830 | FT_FRAME_SHORT ( Ascender ), |
| 831 | FT_FRAME_SHORT ( Descender ), |
| 832 | FT_FRAME_SHORT ( Line_Gap ), |
| 833 | FT_FRAME_USHORT( advance_Width_Max ), |
| 834 | FT_FRAME_SHORT ( min_Left_Side_Bearing ), |
| 835 | FT_FRAME_SHORT ( min_Right_Side_Bearing ), |
| 836 | FT_FRAME_SHORT ( xMax_Extent ), |
| 837 | FT_FRAME_SHORT ( caret_Slope_Rise ), |
| 838 | FT_FRAME_SHORT ( caret_Slope_Run ), |
Werner Lemberg | 5dea444 | 2001-08-13 11:44:29 +0000 | [diff] [blame] | 839 | FT_FRAME_SHORT ( caret_Offset ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 840 | FT_FRAME_SHORT ( Reserved[0] ), |
| 841 | FT_FRAME_SHORT ( Reserved[1] ), |
| 842 | FT_FRAME_SHORT ( Reserved[2] ), |
| 843 | FT_FRAME_SHORT ( Reserved[3] ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 844 | FT_FRAME_SHORT ( metric_Data_Format ), |
| 845 | FT_FRAME_USHORT( number_Of_HMetrics ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 846 | FT_FRAME_END |
| 847 | }; |
| 848 | |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 849 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 850 | FT_TRACE2(( vertical ? "Vertical header " : "Horizontal header " )); |
| 851 | |
| 852 | if ( vertical ) |
| 853 | { |
| 854 | face->vertical_info = 0; |
| 855 | |
| 856 | /* The vertical header table is optional, so return quietly if */ |
| 857 | /* we don't find it. */ |
| 858 | error = face->goto_table( face, TTAG_vhea, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 859 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 860 | { |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 861 | error = SFNT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 862 | goto Exit; |
| 863 | } |
| 864 | |
| 865 | face->vertical_info = 1; |
| 866 | header = (TT_HoriHeader*)&face->vertical; |
| 867 | } |
| 868 | else |
| 869 | { |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 870 | /* The horizontal header is mandatory; return an error if we */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 871 | /* don't find it. */ |
| 872 | error = face->goto_table( face, TTAG_hhea, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 873 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 874 | { |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 875 | error = SFNT_Err_Horiz_Header_Missing; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 876 | goto Exit; |
| 877 | } |
| 878 | |
| 879 | header = &face->horizontal; |
| 880 | } |
| 881 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 882 | if ( FT_STREAM_READ_FIELDS( metrics_header_fields, header ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 883 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 884 | |
| 885 | header->long_metrics = NULL; |
| 886 | header->short_metrics = NULL; |
| 887 | |
| 888 | FT_TRACE2(( "loaded\n" )); |
| 889 | |
| 890 | /* Now try to load the corresponding metrics */ |
| 891 | |
| 892 | error = TT_Load_Metrics( face, stream, vertical ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 893 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 894 | Exit: |
| 895 | return error; |
| 896 | } |
| 897 | |
| 898 | |
| 899 | /*************************************************************************/ |
| 900 | /* */ |
| 901 | /* <Function> */ |
| 902 | /* TT_Load_Names */ |
| 903 | /* */ |
| 904 | /* <Description> */ |
| 905 | /* Loads the name records. */ |
| 906 | /* */ |
| 907 | /* <Input> */ |
| 908 | /* face :: A handle to the target face object. */ |
| 909 | /* stream :: The input stream. */ |
| 910 | /* */ |
| 911 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 912 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 913 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 914 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 915 | TT_Load_Names( TT_Face face, |
| 916 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 917 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 918 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 919 | FT_Memory memory = stream->memory; |
| 920 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 921 | FT_ULong table_pos, table_len; |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 922 | FT_ULong storageOffset, storageSize; |
| 923 | FT_Byte* storage; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 924 | |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 925 | TT_NameTable names; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 926 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 927 | const FT_Frame_Field name_table_fields[] = |
| 928 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 929 | #undef FT_STRUCTURE |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 930 | #define FT_STRUCTURE TT_NameTableRec |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 931 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 932 | FT_FRAME_START( 6 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 933 | FT_FRAME_USHORT( format ), |
| 934 | FT_FRAME_USHORT( numNameRecords ), |
| 935 | FT_FRAME_USHORT( storageOffset ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 936 | FT_FRAME_END |
| 937 | }; |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 938 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 939 | const FT_Frame_Field name_record_fields[] = |
| 940 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 941 | #undef FT_STRUCTURE |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 942 | #define FT_STRUCTURE TT_NameEntryRec |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 943 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 944 | /* no FT_FRAME_START */ |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 945 | FT_FRAME_USHORT( platformID ), |
| 946 | FT_FRAME_USHORT( encodingID ), |
| 947 | FT_FRAME_USHORT( languageID ), |
| 948 | FT_FRAME_USHORT( nameID ), |
| 949 | FT_FRAME_USHORT( stringLength ), |
| 950 | FT_FRAME_USHORT( stringOffset ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 951 | FT_FRAME_END |
| 952 | }; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 953 | |
| 954 | |
| 955 | FT_TRACE2(( "Names " )); |
| 956 | |
| 957 | error = face->goto_table( face, TTAG_name, stream, &table_len ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 958 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 959 | { |
| 960 | /* The name table is required so indicate failure. */ |
| 961 | FT_TRACE2(( "is missing!\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 962 | error = SFNT_Err_Name_Table_Missing; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 963 | goto Exit; |
| 964 | } |
| 965 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 966 | table_pos = FT_STREAM_POS(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 967 | |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 968 | names = &face->name_table; |
| 969 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 970 | if ( FT_STREAM_READ_FIELDS( name_table_fields, names ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 971 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 972 | |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 973 | /* check the 'storageOffset' field */ |
| 974 | storageOffset = names->storageOffset; |
| 975 | if ( storageOffset < (FT_ULong)(6 + 12*names->numNameRecords) || |
| 976 | table_len <= storageOffset ) |
| 977 | { |
| 978 | FT_ERROR(( "TT.load_names: invalid 'name' table\n" )); |
| 979 | error = SFNT_Err_Name_Table_Missing; |
| 980 | goto Exit; |
| 981 | } |
| 982 | |
| 983 | storageSize = (FT_ULong)(table_len - storageOffset); |
| 984 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 985 | /* Allocate the array of name records. */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 986 | if ( FT_ALLOC( names->names, |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 987 | names->numNameRecords*sizeof(TT_NameEntryRec) + storageSize ) || |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 988 | FT_FRAME_ENTER( names->numNameRecords * 12L ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 989 | goto Exit; |
| 990 | |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 991 | storage = (FT_Byte*)(names->names + names->numNameRecords); |
| 992 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 993 | /* Load the name records and determine how much storage is needed */ |
| 994 | /* to hold the strings themselves. */ |
| 995 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 996 | TT_NameEntryRec* cur = names->names; |
| 997 | TT_NameEntryRec* limit = cur + names->numNameRecords; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 998 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 999 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1000 | for ( ; cur < limit; cur ++ ) |
| 1001 | { |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1002 | if ( FT_STREAM_READ_FIELDS( name_record_fields, cur ) ) |
Werner Lemberg | b1dd353 | 2000-07-31 22:51:00 +0000 | [diff] [blame] | 1003 | break; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 1004 | |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 1005 | /* invalid name entries will have "cur->string" set to NULL !! */ |
| 1006 | if ( (FT_ULong)(cur->stringOffset + cur->stringLength) < storageSize ) |
| 1007 | cur->string = storage + cur->stringOffset; |
David Turner | 28ea6f6 | 2002-03-05 16:12:57 +0000 | [diff] [blame] | 1008 | else |
| 1009 | { |
| 1010 | /* that's an invalid entry */ |
| 1011 | cur->stringOffset = 0; |
| 1012 | cur->string = NULL; |
| 1013 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1017 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1018 | |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 1019 | if (error) |
| 1020 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1021 | |
David Turner | 28ea6f6 | 2002-03-05 16:12:57 +0000 | [diff] [blame] | 1022 | storageOffset -= 6 + 12*names->numNameRecords; |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1023 | if ( FT_STREAM_SKIP( storageOffset ) || |
| 1024 | FT_STREAM_READ( storage, storageSize ) ) |
David Turner | 28ea6f6 | 2002-03-05 16:12:57 +0000 | [diff] [blame] | 1025 | goto Exit; |
| 1026 | |
| 1027 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1028 | #ifdef FT_DEBUG_LEVEL_TRACE |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1029 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1030 | /* Print Name Record Table in case of debugging */ |
| 1031 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1032 | TT_NameEntryRec* cur = names->names; |
| 1033 | TT_NameEntryRec* limit = cur + names->numNameRecords; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1034 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1035 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1036 | for ( ; cur < limit; cur++ ) |
| 1037 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1038 | FT_UInt j; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1039 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1040 | |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 1041 | FT_TRACE3(( "(%2d %2d %4x %2d) ", |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1042 | cur->platformID, |
| 1043 | cur->encodingID, |
| 1044 | cur->languageID, |
| 1045 | cur->nameID )); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1046 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1047 | /* I know that M$ encoded strings are Unicode, */ |
| 1048 | /* but this works reasonable well for debugging purposes. */ |
| 1049 | if ( cur->string ) |
David Turner | d3c8e06 | 2000-12-04 22:53:55 +0000 | [diff] [blame] | 1050 | for ( j = 0; j < (FT_UInt)cur->stringLength; j++ ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1051 | { |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 1052 | FT_Byte c = *(FT_Byte*)(cur->string + j); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1053 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1054 | |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 1055 | if ( c >= 32 && c < 128 ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1056 | FT_TRACE3(( "%c", c )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1057 | } |
David Turner | c03d9cf | 2002-02-27 23:10:19 +0000 | [diff] [blame] | 1058 | else |
| 1059 | FT_TRACE3(( "INVALID ENTRY !!\n" )); |
| 1060 | |
| 1061 | FT_TRACE3(( "\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1062 | } |
| 1063 | } |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1064 | |
| 1065 | #endif /* FT_DEBUG_LEVEL_TRACE */ |
| 1066 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1067 | FT_TRACE2(( "loaded\n" )); |
| 1068 | |
David Turner | 49bd4f0 | 2000-07-12 16:57:37 +0000 | [diff] [blame] | 1069 | /* everything went well, update face->num_names */ |
| 1070 | face->num_names = names->numNameRecords; |
| 1071 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1072 | Exit: |
| 1073 | return error; |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | /*************************************************************************/ |
| 1078 | /* */ |
| 1079 | /* <Function> */ |
| 1080 | /* TT_Free_Names */ |
| 1081 | /* */ |
| 1082 | /* <Description> */ |
| 1083 | /* Frees the name records. */ |
| 1084 | /* */ |
| 1085 | /* <Input> */ |
| 1086 | /* face :: A handle to the target face object. */ |
| 1087 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1088 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1089 | TT_Free_Names( TT_Face face ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1090 | { |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1091 | FT_Memory memory = face->root.driver->root.memory; |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1092 | TT_NameTable names = &face->name_table; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1093 | |
| 1094 | |
| 1095 | /* free strings table */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1096 | FT_FREE( names->names ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* free strings storage */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1099 | FT_FREE( names->storage ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1100 | |
| 1101 | names->numNameRecords = 0; |
| 1102 | names->format = 0; |
| 1103 | names->storageOffset = 0; |
| 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | /*************************************************************************/ |
| 1108 | /* */ |
| 1109 | /* <Function> */ |
| 1110 | /* TT_Load_CMap */ |
| 1111 | /* */ |
| 1112 | /* <Description> */ |
| 1113 | /* Loads the cmap directory in a face object. The cmaps itselves are */ |
| 1114 | /* loaded on demand in the `ttcmap.c' module. */ |
| 1115 | /* */ |
| 1116 | /* <Input> */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1117 | /* face :: A handle to the target face object. */ |
| 1118 | /* stream :: A handle to the input stream. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1119 | /* */ |
| 1120 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1121 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1122 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1123 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1124 | TT_Load_CMap( TT_Face face, |
| 1125 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1126 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1127 | FT_Error error; |
| 1128 | FT_Memory memory = stream->memory; |
| 1129 | FT_Long table_start; |
| 1130 | TT_CMapDirRec cmap_dir; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1131 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1132 | const FT_Frame_Field cmap_fields[] = |
| 1133 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1134 | #undef FT_STRUCTURE |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1135 | #define FT_STRUCTURE TT_CMapDirRec |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1136 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1137 | FT_FRAME_START( 4 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1138 | FT_FRAME_USHORT( tableVersionNumber ), |
| 1139 | FT_FRAME_USHORT( numCMaps ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1140 | FT_FRAME_END |
| 1141 | }; |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 1142 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1143 | const FT_Frame_Field cmap_rec_fields[] = |
| 1144 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1145 | #undef FT_STRUCTURE |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1146 | #define FT_STRUCTURE TT_CMapTableRec |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1147 | |
Werner Lemberg | bcf8d4b | 2001-08-24 23:11:34 +0000 | [diff] [blame] | 1148 | FT_FRAME_START( 4 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1149 | FT_FRAME_USHORT( format ), |
| 1150 | FT_FRAME_USHORT( length ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1151 | FT_FRAME_END |
| 1152 | }; |
| 1153 | |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 1154 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1155 | FT_TRACE2(( "CMaps " )); |
| 1156 | |
| 1157 | error = face->goto_table( face, TTAG_cmap, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1158 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1159 | { |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1160 | error = SFNT_Err_CMap_Table_Missing; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1161 | goto Exit; |
| 1162 | } |
| 1163 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1164 | table_start = FT_STREAM_POS(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1165 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1166 | if ( FT_STREAM_READ_FIELDS( cmap_fields, &cmap_dir ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1167 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1168 | |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 1169 | /* reserve space in face table for cmap tables */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1170 | if ( FT_NEW_ARRAY( face->charmaps, cmap_dir.numCMaps ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1171 | goto Exit; |
| 1172 | |
| 1173 | face->num_charmaps = cmap_dir.numCMaps; |
| 1174 | { |
| 1175 | TT_CharMap charmap = face->charmaps; |
| 1176 | TT_CharMap limit = charmap + face->num_charmaps; |
| 1177 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1178 | |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 1179 | /* read the header of each charmap first */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1180 | if ( FT_FRAME_ENTER( face->num_charmaps * 8L ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1181 | goto Exit; |
| 1182 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1183 | for ( ; charmap < limit; charmap++ ) |
| 1184 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1185 | TT_CMapTable cmap; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1186 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1187 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1188 | charmap->root.face = (FT_Face)face; |
| 1189 | cmap = &charmap->cmap; |
| 1190 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1191 | cmap->loaded = FALSE; |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1192 | cmap->platformID = FT_GET_USHORT(); |
| 1193 | cmap->platformEncodingID = FT_GET_USHORT(); |
| 1194 | cmap->offset = (FT_ULong)FT_GET_LONG(); |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 1195 | } |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1196 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1197 | FT_FRAME_EXIT(); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1198 | |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 1199 | /* now read the rest of each table */ |
| 1200 | for ( charmap = face->charmaps; charmap < limit; charmap++ ) |
| 1201 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1202 | TT_CMapTable cmap = &charmap->cmap; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1203 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1204 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1205 | if ( FT_STREAM_SEEK( table_start + (FT_Long)cmap->offset ) || |
| 1206 | FT_STREAM_READ_FIELDS( cmap_rec_fields, cmap ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1207 | goto Exit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1208 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1209 | cmap->offset = FT_STREAM_POS(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | FT_TRACE2(( "loaded\n" )); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1214 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1215 | Exit: |
| 1216 | return error; |
| 1217 | } |
| 1218 | |
| 1219 | |
| 1220 | /*************************************************************************/ |
| 1221 | /* */ |
| 1222 | /* <Function> */ |
| 1223 | /* TT_Load_OS2 */ |
| 1224 | /* */ |
| 1225 | /* <Description> */ |
| 1226 | /* Loads the OS2 table. */ |
| 1227 | /* */ |
| 1228 | /* <Input> */ |
| 1229 | /* face :: A handle to the target face object. */ |
| 1230 | /* stream :: A handle to the input stream. */ |
| 1231 | /* */ |
| 1232 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1233 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1234 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1235 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1236 | TT_Load_OS2( TT_Face face, |
| 1237 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1238 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1239 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1240 | TT_OS2* os2; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 1241 | |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 1242 | const FT_Frame_Field os2_fields[] = |
| 1243 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1244 | #undef FT_STRUCTURE |
| 1245 | #define FT_STRUCTURE TT_OS2 |
| 1246 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1247 | FT_FRAME_START( 78 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1248 | FT_FRAME_USHORT( version ), |
| 1249 | FT_FRAME_SHORT ( xAvgCharWidth ), |
| 1250 | FT_FRAME_USHORT( usWeightClass ), |
| 1251 | FT_FRAME_USHORT( usWidthClass ), |
| 1252 | FT_FRAME_SHORT ( fsType ), |
| 1253 | FT_FRAME_SHORT ( ySubscriptXSize ), |
| 1254 | FT_FRAME_SHORT ( ySubscriptYSize ), |
| 1255 | FT_FRAME_SHORT ( ySubscriptXOffset ), |
| 1256 | FT_FRAME_SHORT ( ySubscriptYOffset ), |
| 1257 | FT_FRAME_SHORT ( ySuperscriptXSize ), |
| 1258 | FT_FRAME_SHORT ( ySuperscriptYSize ), |
| 1259 | FT_FRAME_SHORT ( ySuperscriptXOffset ), |
| 1260 | FT_FRAME_SHORT ( ySuperscriptYOffset ), |
| 1261 | FT_FRAME_SHORT ( yStrikeoutSize ), |
| 1262 | FT_FRAME_SHORT ( yStrikeoutPosition ), |
| 1263 | FT_FRAME_SHORT ( sFamilyClass ), |
| 1264 | FT_FRAME_BYTE ( panose[0] ), |
| 1265 | FT_FRAME_BYTE ( panose[1] ), |
| 1266 | FT_FRAME_BYTE ( panose[2] ), |
| 1267 | FT_FRAME_BYTE ( panose[3] ), |
| 1268 | FT_FRAME_BYTE ( panose[4] ), |
| 1269 | FT_FRAME_BYTE ( panose[5] ), |
| 1270 | FT_FRAME_BYTE ( panose[6] ), |
| 1271 | FT_FRAME_BYTE ( panose[7] ), |
| 1272 | FT_FRAME_BYTE ( panose[8] ), |
| 1273 | FT_FRAME_BYTE ( panose[9] ), |
| 1274 | FT_FRAME_ULONG ( ulUnicodeRange1 ), |
| 1275 | FT_FRAME_ULONG ( ulUnicodeRange2 ), |
| 1276 | FT_FRAME_ULONG ( ulUnicodeRange3 ), |
| 1277 | FT_FRAME_ULONG ( ulUnicodeRange4 ), |
| 1278 | FT_FRAME_BYTE ( achVendID[0] ), |
| 1279 | FT_FRAME_BYTE ( achVendID[1] ), |
| 1280 | FT_FRAME_BYTE ( achVendID[2] ), |
| 1281 | FT_FRAME_BYTE ( achVendID[3] ), |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 1282 | |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1283 | FT_FRAME_USHORT( fsSelection ), |
| 1284 | FT_FRAME_USHORT( usFirstCharIndex ), |
| 1285 | FT_FRAME_USHORT( usLastCharIndex ), |
| 1286 | FT_FRAME_SHORT ( sTypoAscender ), |
| 1287 | FT_FRAME_SHORT ( sTypoDescender ), |
| 1288 | FT_FRAME_SHORT ( sTypoLineGap ), |
| 1289 | FT_FRAME_USHORT( usWinAscent ), |
| 1290 | FT_FRAME_USHORT( usWinDescent ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1291 | FT_FRAME_END |
| 1292 | }; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1293 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1294 | const FT_Frame_Field os2_fields_extra[] = |
| 1295 | { |
| 1296 | FT_FRAME_START( 8 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1297 | FT_FRAME_ULONG( ulCodePageRange1 ), |
| 1298 | FT_FRAME_ULONG( ulCodePageRange2 ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1299 | FT_FRAME_END |
| 1300 | }; |
David Turner | 1119bae | 2000-05-02 11:01:49 +0000 | [diff] [blame] | 1301 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1302 | const FT_Frame_Field os2_fields_extra2[] = |
| 1303 | { |
| 1304 | FT_FRAME_START( 10 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1305 | FT_FRAME_SHORT ( sxHeight ), |
| 1306 | FT_FRAME_SHORT ( sCapHeight ), |
| 1307 | FT_FRAME_USHORT( usDefaultChar ), |
| 1308 | FT_FRAME_USHORT( usBreakChar ), |
| 1309 | FT_FRAME_USHORT( usMaxContext ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1310 | FT_FRAME_END |
| 1311 | }; |
| 1312 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1313 | |
| 1314 | FT_TRACE2(( "OS/2 Table " )); |
| 1315 | |
| 1316 | /* We now support old Mac fonts where the OS/2 table doesn't */ |
| 1317 | /* exist. Simply put, we set the `version' field to 0xFFFF */ |
| 1318 | /* and test this value each time we need to access the table. */ |
| 1319 | error = face->goto_table( face, TTAG_OS2, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1320 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1321 | { |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 1322 | FT_TRACE2(( "is missing!\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1323 | face->os2.version = 0xFFFF; |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1324 | error = SFNT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1325 | goto Exit; |
| 1326 | } |
| 1327 | |
David Turner | a56489e | 2000-02-13 13:41:56 +0000 | [diff] [blame] | 1328 | os2 = &face->os2; |
| 1329 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1330 | if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1331 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1332 | |
| 1333 | os2->ulCodePageRange1 = 0; |
| 1334 | os2->ulCodePageRange2 = 0; |
Werner Lemberg | 36af3ea | 2001-07-17 12:37:54 +0000 | [diff] [blame] | 1335 | os2->sxHeight = 0; |
| 1336 | os2->sCapHeight = 0; |
| 1337 | os2->usDefaultChar = 0; |
| 1338 | os2->usBreakChar = 0; |
| 1339 | os2->usMaxContext = 0; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1340 | |
| 1341 | if ( os2->version >= 0x0001 ) |
| 1342 | { |
| 1343 | /* only version 1 tables */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1344 | if ( FT_STREAM_READ_FIELDS( os2_fields_extra, os2 ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1345 | goto Exit; |
David Turner | 1119bae | 2000-05-02 11:01:49 +0000 | [diff] [blame] | 1346 | |
| 1347 | if ( os2->version >= 0x0002 ) |
| 1348 | { |
| 1349 | /* only version 2 tables */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1350 | if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, os2 ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1351 | goto Exit; |
David Turner | 1119bae | 2000-05-02 11:01:49 +0000 | [diff] [blame] | 1352 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | FT_TRACE2(( "loaded\n" )); |
| 1356 | |
| 1357 | Exit: |
| 1358 | return error; |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | /*************************************************************************/ |
| 1363 | /* */ |
| 1364 | /* <Function> */ |
| 1365 | /* TT_Load_Postscript */ |
| 1366 | /* */ |
| 1367 | /* <Description> */ |
| 1368 | /* Loads the Postscript table. */ |
| 1369 | /* */ |
| 1370 | /* <Input> */ |
| 1371 | /* face :: A handle to the target face object. */ |
| 1372 | /* stream :: A handle to the input stream. */ |
| 1373 | /* */ |
| 1374 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1375 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1376 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1377 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1378 | TT_Load_PostScript( TT_Face face, |
| 1379 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1380 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1381 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1382 | TT_Postscript* post = &face->postscript; |
David Turner | b1677a8 | 2000-05-29 20:37:41 +0000 | [diff] [blame] | 1383 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1384 | static const FT_Frame_Field post_fields[] = |
| 1385 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1386 | #undef FT_STRUCTURE |
| 1387 | #define FT_STRUCTURE TT_Postscript |
| 1388 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1389 | FT_FRAME_START( 32 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1390 | FT_FRAME_ULONG( FormatType ), |
| 1391 | FT_FRAME_ULONG( italicAngle ), |
| 1392 | FT_FRAME_SHORT( underlinePosition ), |
| 1393 | FT_FRAME_SHORT( underlineThickness ), |
| 1394 | FT_FRAME_ULONG( isFixedPitch ), |
| 1395 | FT_FRAME_ULONG( minMemType42 ), |
| 1396 | FT_FRAME_ULONG( maxMemType42 ), |
| 1397 | FT_FRAME_ULONG( minMemType1 ), |
| 1398 | FT_FRAME_ULONG( maxMemType1 ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1399 | FT_FRAME_END |
| 1400 | }; |
| 1401 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1402 | |
| 1403 | FT_TRACE2(( "PostScript " )); |
| 1404 | |
| 1405 | error = face->goto_table( face, TTAG_post, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1406 | if ( error ) |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1407 | return SFNT_Err_Post_Table_Missing; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1408 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1409 | if ( FT_STREAM_READ_FIELDS( post_fields, post ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1410 | return error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1411 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1412 | /* we don't load the glyph names, we do that in another */ |
| 1413 | /* module (ttpost). */ |
| 1414 | FT_TRACE2(( "loaded\n" )); |
| 1415 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1416 | return SFNT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | |
| 1420 | /*************************************************************************/ |
| 1421 | /* */ |
| 1422 | /* <Function> */ |
David Turner | 51179f0 | 2000-05-18 16:18:05 +0000 | [diff] [blame] | 1423 | /* TT_Load_PCLT */ |
| 1424 | /* */ |
| 1425 | /* <Description> */ |
| 1426 | /* Loads the PCL 5 Table. */ |
| 1427 | /* */ |
| 1428 | /* <Input> */ |
| 1429 | /* face :: A handle to the target face object. */ |
| 1430 | /* stream :: A handle to the input stream. */ |
| 1431 | /* */ |
| 1432 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1433 | /* FreeType error code. 0 means success. */ |
David Turner | 51179f0 | 2000-05-18 16:18:05 +0000 | [diff] [blame] | 1434 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1435 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1436 | TT_Load_PCLT( TT_Face face, |
| 1437 | FT_Stream stream ) |
David Turner | 51179f0 | 2000-05-18 16:18:05 +0000 | [diff] [blame] | 1438 | { |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1439 | static const FT_Frame_Field pclt_fields[] = |
| 1440 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1441 | #undef FT_STRUCTURE |
| 1442 | #define FT_STRUCTURE TT_PCLT |
| 1443 | |
David Turner | d18388e | 2000-07-03 15:00:49 +0000 | [diff] [blame] | 1444 | FT_FRAME_START( 54 ), |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 1445 | FT_FRAME_ULONG ( Version ), |
| 1446 | FT_FRAME_ULONG ( FontNumber ), |
| 1447 | FT_FRAME_USHORT( Pitch ), |
| 1448 | FT_FRAME_USHORT( xHeight ), |
| 1449 | FT_FRAME_USHORT( Style ), |
| 1450 | FT_FRAME_USHORT( TypeFamily ), |
| 1451 | FT_FRAME_USHORT( CapHeight ), |
| 1452 | FT_FRAME_BYTES ( TypeFace, 16 ), |
| 1453 | FT_FRAME_BYTES ( CharacterComplement, 8 ), |
| 1454 | FT_FRAME_BYTES ( FileName, 6 ), |
| 1455 | FT_FRAME_CHAR ( StrokeWeight ), |
| 1456 | FT_FRAME_CHAR ( WidthType ), |
| 1457 | FT_FRAME_BYTE ( SerifStyle ), |
| 1458 | FT_FRAME_BYTE ( Reserved ), |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1459 | FT_FRAME_END |
| 1460 | }; |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 1461 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1462 | FT_Error error; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1463 | TT_PCLT* pclt = &face->pclt; |
| 1464 | |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 1465 | |
David Turner | 51179f0 | 2000-05-18 16:18:05 +0000 | [diff] [blame] | 1466 | FT_TRACE2(( "PCLT " )); |
| 1467 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1468 | /* optional table */ |
| 1469 | error = face->goto_table( face, TTAG_PCLT, stream, 0 ); |
| 1470 | if ( error ) |
| 1471 | { |
| 1472 | FT_TRACE2(( "missing (optional)\n" )); |
| 1473 | pclt->Version = 0; |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1474 | return SFNT_Err_Ok; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1475 | } |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 1476 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1477 | if ( FT_STREAM_READ_FIELDS( pclt_fields, pclt ) ) |
David Turner | 51179f0 | 2000-05-18 16:18:05 +0000 | [diff] [blame] | 1478 | goto Exit; |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 1479 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1480 | FT_TRACE2(( "loaded\n" )); |
| 1481 | |
Werner Lemberg | 920d41e | 2000-06-05 14:32:32 +0000 | [diff] [blame] | 1482 | Exit: |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1483 | return error; |
| 1484 | } |
| 1485 | |
David Turner | 51179f0 | 2000-05-18 16:18:05 +0000 | [diff] [blame] | 1486 | |
| 1487 | /*************************************************************************/ |
| 1488 | /* */ |
| 1489 | /* <Function> */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1490 | /* TT_Load_Gasp */ |
| 1491 | /* */ |
| 1492 | /* <Description> */ |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 1493 | /* Loads the `gasp' table into a face object. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1494 | /* */ |
| 1495 | /* <Input> */ |
| 1496 | /* face :: A handle to the target face object. */ |
| 1497 | /* stream :: The input stream. */ |
| 1498 | /* */ |
| 1499 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1500 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1501 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1502 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1503 | TT_Load_Gasp( TT_Face face, |
| 1504 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1505 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1506 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1507 | FT_Memory memory = stream->memory; |
| 1508 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1509 | FT_UInt j,num_ranges; |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1510 | TT_GaspRange gaspranges; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1511 | |
| 1512 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1513 | FT_TRACE2(( "TT_Load_Gasp: %08p\n", face )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1514 | |
| 1515 | /* the gasp table is optional */ |
| 1516 | error = face->goto_table( face, TTAG_gasp, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1517 | if ( error ) |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1518 | return SFNT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1519 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1520 | if ( FT_FRAME_ENTER( 4L ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1521 | goto Exit; |
| 1522 | |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1523 | face->gasp.version = FT_GET_USHORT(); |
| 1524 | face->gasp.numRanges = FT_GET_USHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1525 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1526 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1527 | |
| 1528 | num_ranges = face->gasp.numRanges; |
| 1529 | FT_TRACE3(( "number of ranges = %d\n", num_ranges )); |
| 1530 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1531 | if ( FT_NEW_ARRAY( gaspranges, num_ranges ) || |
| 1532 | FT_FRAME_ENTER( num_ranges * 4L ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1533 | goto Exit; |
| 1534 | |
| 1535 | face->gasp.gaspRanges = gaspranges; |
| 1536 | |
| 1537 | for ( j = 0; j < num_ranges; j++ ) |
| 1538 | { |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1539 | gaspranges[j].maxPPEM = FT_GET_USHORT(); |
| 1540 | gaspranges[j].gaspFlag = FT_GET_USHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1541 | |
| 1542 | FT_TRACE3(( " [max:%d flag:%d]", |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1543 | gaspranges[j].maxPPEM, |
| 1544 | gaspranges[j].gaspFlag )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1545 | } |
| 1546 | FT_TRACE3(( "\n" )); |
| 1547 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1548 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1549 | FT_TRACE2(( "GASP loaded\n" )); |
| 1550 | |
| 1551 | Exit: |
| 1552 | return error; |
| 1553 | } |
| 1554 | |
| 1555 | |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1556 | FT_CALLBACK_DEF( int ) |
| 1557 | tt_kern_pair_compare( const void* a, |
| 1558 | const void* b ); |
| 1559 | |
| 1560 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1561 | /*************************************************************************/ |
| 1562 | /* */ |
| 1563 | /* <Function> */ |
| 1564 | /* TT_Load_Kern */ |
| 1565 | /* */ |
| 1566 | /* <Description> */ |
| 1567 | /* Loads the first kerning table with format 0 in the font. Only */ |
| 1568 | /* accepts the first horizontal kerning table. Developers should use */ |
| 1569 | /* the `ftxkern' extension to access other kerning tables in the font */ |
| 1570 | /* file, if they really want to. */ |
| 1571 | /* */ |
| 1572 | /* <Input> */ |
| 1573 | /* face :: A handle to the target face object. */ |
| 1574 | /* stream :: The input stream. */ |
| 1575 | /* */ |
| 1576 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1577 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1578 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1579 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1580 | TT_Load_Kern( TT_Face face, |
| 1581 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1582 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1583 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1584 | FT_Memory memory = stream->memory; |
| 1585 | |
Werner Lemberg | cf24d51 | 2001-06-18 14:23:45 +0000 | [diff] [blame] | 1586 | FT_UInt n, num_tables; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1587 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1588 | |
Werner Lemberg | fbeb41d | 2000-07-02 00:27:53 +0000 | [diff] [blame] | 1589 | /* the kern table is optional; exit silently if it is missing */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1590 | error = face->goto_table( face, TTAG_kern, stream, 0 ); |
| 1591 | if ( error ) |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1592 | return SFNT_Err_Ok; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1593 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1594 | if ( FT_FRAME_ENTER( 4L ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1595 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1596 | |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1597 | (void)FT_GET_USHORT(); /* version */ |
| 1598 | num_tables = FT_GET_USHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1599 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1600 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1601 | |
| 1602 | for ( n = 0; n < num_tables; n++ ) |
| 1603 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1604 | FT_UInt coverage; |
| 1605 | FT_UInt length; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1606 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1607 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1608 | if ( FT_FRAME_ENTER( 6L ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1609 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1610 | |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1611 | (void)FT_GET_USHORT(); /* version */ |
| 1612 | length = FT_GET_USHORT() - 6; /* substract header length */ |
| 1613 | coverage = FT_GET_USHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1614 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1615 | FT_FRAME_EXIT(); |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1616 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1617 | if ( coverage == 0x0001 ) |
| 1618 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1619 | FT_UInt num_pairs; |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1620 | TT_Kern0_Pair pair; |
| 1621 | TT_Kern0_Pair limit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1622 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1623 | |
| 1624 | /* found a horizontal format 0 kerning table! */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1625 | if ( FT_FRAME_ENTER( 8L ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1626 | goto Exit; |
| 1627 | |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1628 | num_pairs = FT_GET_USHORT(); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1629 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1630 | /* skip the rest */ |
| 1631 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1632 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1633 | |
| 1634 | /* allocate array of kerning pairs */ |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1635 | if ( FT_NEW_ARRAY( face->kern_pairs, num_pairs ) || |
| 1636 | FT_FRAME_ENTER( 6L * num_pairs ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1637 | goto Exit; |
| 1638 | |
| 1639 | pair = face->kern_pairs; |
| 1640 | limit = pair + num_pairs; |
| 1641 | for ( ; pair < limit; pair++ ) |
| 1642 | { |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1643 | pair->left = FT_GET_USHORT(); |
| 1644 | pair->right = FT_GET_USHORT(); |
| 1645 | pair->value = FT_GET_USHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1648 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1649 | |
| 1650 | face->num_kern_pairs = num_pairs; |
| 1651 | face->kern_table_index = n; |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 1652 | |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1653 | /* ensure that the kerning pair table is sorted (yes, some */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1654 | /* fonts have unsorted tables!) */ |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1655 | { |
| 1656 | FT_UInt i; |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1657 | TT_Kern0_Pair pair0; |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 1658 | |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1659 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1660 | pair0 = face->kern_pairs; |
| 1661 | |
| 1662 | for ( i = 1; i < num_pairs; i++, pair0++ ) |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1663 | { |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1664 | if ( tt_kern_pair_compare( pair0, pair0 + 1 ) != -1 ) |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1665 | { |
| 1666 | qsort( (void*)face->kern_pairs, (int)num_pairs, |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1667 | sizeof ( TT_Kern0_PairRec ), tt_kern_pair_compare ); |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1668 | break; |
| 1669 | } |
| 1670 | } |
| 1671 | } |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 1672 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1673 | goto Exit; |
| 1674 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1675 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1676 | if ( FT_STREAM_SKIP( length ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1677 | goto Exit; |
| 1678 | } |
| 1679 | |
| 1680 | /* no kern table found -- doesn't matter */ |
| 1681 | face->kern_table_index = -1; |
| 1682 | face->num_kern_pairs = 0; |
| 1683 | face->kern_pairs = NULL; |
| 1684 | |
| 1685 | Exit: |
| 1686 | return error; |
| 1687 | } |
| 1688 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1689 | |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1690 | #undef TT_KERN_INDEX |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1691 | #define TT_KERN_INDEX( g1, g2 ) ( ( (FT_ULong)g1 << 16 ) | g2 ) |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1692 | |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1693 | FT_CALLBACK_DEF( int ) |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1694 | tt_kern_pair_compare( const void* a, |
| 1695 | const void* b ) |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1696 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1697 | TT_Kern0_Pair pair1 = (TT_Kern0_Pair)a; |
| 1698 | TT_Kern0_Pair pair2 = (TT_Kern0_Pair)b; |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1699 | |
| 1700 | FT_ULong index1 = TT_KERN_INDEX( pair1->left, pair1->right ); |
| 1701 | FT_ULong index2 = TT_KERN_INDEX( pair2->left, pair2->right ); |
| 1702 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1703 | |
David Turner | 9a554eb | 2001-06-27 12:40:46 +0000 | [diff] [blame] | 1704 | return ( index1 < index2 ? -1 : |
| 1705 | ( index1 > index2 ? 1 : 0 )); |
| 1706 | } |
| 1707 | |
| 1708 | #undef TT_KERN_INDEX |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1709 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 1710 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1711 | /*************************************************************************/ |
| 1712 | /* */ |
| 1713 | /* <Function> */ |
| 1714 | /* TT_Load_Hdmx */ |
| 1715 | /* */ |
| 1716 | /* <Description> */ |
| 1717 | /* Loads the horizontal device metrics table. */ |
| 1718 | /* */ |
| 1719 | /* <Input> */ |
| 1720 | /* face :: A handle to the target face object. */ |
| 1721 | /* stream :: A handle to the input stream. */ |
| 1722 | /* */ |
| 1723 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1724 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1725 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1726 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1727 | TT_Load_Hdmx( TT_Face face, |
| 1728 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1729 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1730 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1731 | FT_Memory memory = stream->memory; |
| 1732 | |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1733 | TT_Hdmx hdmx = &face->hdmx; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1734 | FT_Long num_glyphs; |
| 1735 | FT_Long record_size; |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1736 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1737 | |
| 1738 | hdmx->version = 0; |
| 1739 | hdmx->num_records = 0; |
| 1740 | hdmx->records = 0; |
| 1741 | |
| 1742 | /* this table is optional */ |
| 1743 | error = face->goto_table( face, TTAG_hdmx, stream, 0 ); |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1744 | if ( error ) |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 1745 | return SFNT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1746 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1747 | if ( FT_FRAME_ENTER( 8L ) ) |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1748 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1749 | |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1750 | hdmx->version = FT_GET_USHORT(); |
| 1751 | hdmx->num_records = FT_GET_SHORT(); |
| 1752 | record_size = FT_GET_LONG(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1753 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1754 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1755 | |
| 1756 | /* Only recognize format 0 */ |
| 1757 | if ( hdmx->version != 0 ) |
| 1758 | goto Exit; |
| 1759 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1760 | if ( FT_NEW_ARRAY( hdmx->records, hdmx->num_records ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1761 | goto Exit; |
| 1762 | |
| 1763 | num_glyphs = face->root.num_glyphs; |
| 1764 | record_size -= num_glyphs + 2; |
| 1765 | |
| 1766 | { |
David Turner | b5713c5 | 2002-03-14 11:26:29 +0000 | [diff] [blame] | 1767 | TT_HdmxEntry cur = hdmx->records; |
| 1768 | TT_HdmxEntry limit = cur + hdmx->num_records; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1769 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1770 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1771 | for ( ; cur < limit; cur++ ) |
| 1772 | { |
| 1773 | /* read record */ |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 1774 | if ( FT_READ_BYTE( cur->ppem ) || |
| 1775 | FT_READ_BYTE( cur->max_width ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1776 | goto Exit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1777 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1778 | if ( FT_ALLOC( cur->widths, num_glyphs ) || |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1779 | FT_STREAM_READ( cur->widths, num_glyphs ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1780 | goto Exit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1781 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1782 | /* skip padding bytes */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 1783 | if ( record_size > 0 && FT_STREAM_SKIP( record_size ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1784 | goto Exit; |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | Exit: |
| 1789 | return error; |
| 1790 | } |
| 1791 | |
| 1792 | |
| 1793 | /*************************************************************************/ |
| 1794 | /* */ |
| 1795 | /* <Function> */ |
| 1796 | /* TT_Free_Hdmx */ |
| 1797 | /* */ |
| 1798 | /* <Description> */ |
| 1799 | /* Frees the horizontal device metrics table. */ |
| 1800 | /* */ |
| 1801 | /* <Input> */ |
| 1802 | /* face :: A handle to the target face object. */ |
| 1803 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1804 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 52005c3 | 2001-06-27 23:25:46 +0000 | [diff] [blame] | 1805 | TT_Free_Hdmx( TT_Face face ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1806 | { |
| 1807 | if ( face ) |
| 1808 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1809 | FT_Int n; |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1810 | FT_Memory memory = face->root.driver->root.memory; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1811 | |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 1812 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1813 | for ( n = 0; n < face->hdmx.num_records; n++ ) |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1814 | FT_FREE( face->hdmx.records[n].widths ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1815 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 1816 | FT_FREE( face->hdmx.records ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1817 | face->hdmx.num_records = 0; |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | |
| 1822 | /* END */ |