1 /*--------------------------------------------------------------------*//*:Ignore this sentence. 2 Copyright (C) 2007 SIL International. All rights reserved. 3 4 Distributable under the terms of either the Common Public License or the 5 GNU Lesser General Public License, as specified in the LICENSING.txt file. 6 7 File: TtfTypes.h 8 Responsibility: Tim Eves 9 Last reviewed: Not yet. 10 11 Description: 12 Provides types required to represent the TTF basic types. 13 -------------------------------------------------------------------------------*//*:End Ignore*/ 14 15 16 //********************************************************************************************** 17 // Include files 18 //********************************************************************************************** 19 #include "GrPlatform.h" 20 21 namespace TtfUtil 22 { 23 //********************************************************************************************** 24 // Forward declarations 25 //********************************************************************************************** 26 27 28 //********************************************************************************************** 29 // Type declarations 30 //********************************************************************************************** 31 typedef gr::data8 uint8; 32 typedef gr::sdata8 int8; 33 typedef gr::data16 uint16; 34 typedef gr::sdata16 int16; 35 typedef gr::data32 uint32; 36 typedef gr::sdata32 int32; 37 38 typedef int16 short_frac; 39 typedef int32 fixed; 40 typedef int16 fword; 41 typedef uint16 ufword; 42 typedef int16 f2dot14; 43 typedef uint32 long_date_time[2]; 44 45 //********************************************************************************************** 46 // Constants and enum types 47 //**********************************************************************************************/ 48 enum 49 { 50 OneFix = 1<<16 51 }; 52 53 //********************************************************************************************** 54 // Table declarations 55 //********************************************************************************************** 56 namespace Sfnt 57 { 58 #pragma pack(1) // We need this or the structure members aren't alligned 59 // correctly. Fortunately this form of pragma is supposed 60 // to be recongnised by VS C++ too (at least according to 61 // MSDN). 62 63 struct OffsetSubTable 64 { 65 uint32 scaler_type; 66 uint16 num_tables, 67 search_range, 68 entry_selector, 69 range_shift; 70 struct Entry 71 { 72 uint32 tag, 73 checksum, 74 offset, 75 length; 76 } table_directory[1]; 77 78 enum ScalerType 79 { 80 TrueTypeMac = 0x74727565U, 81 TrueTypeWin = 0x00010000U, 82 Type1 = 0x74797031U 83 }; 84 }; 85 86 87 88 89 struct CharacterCodeMap 90 { 91 uint16 version, 92 num_subtables; 93 struct 94 { 95 uint16 platform_id, 96 platform_specific_id; 97 uint32 offset; 98 } encoding[1]; 99 }; 100 101 struct CmapSubTable 102 { 103 uint16 format, 104 length, 105 language; 106 }; 107 108 struct CmapSubTableFormat4 : CmapSubTable 109 { 110 uint16 seg_count_x2, 111 search_range, 112 entry_selector, 113 range_shift, 114 end_code[1]; 115 // There are arrarys after this which need their 116 // start positions calculated since end_code is 117 // seg_count uint16s long. 118 }; 119 120 struct CmapSubTableFormat12 121 { 122 fixed format; 123 uint32 length, 124 language, 125 num_groups; 126 struct 127 { 128 uint32 start_char_code, 129 end_char_code, 130 start_glyph_id; 131 } group[1]; 132 }; 133 134 135 136 struct FontHeader 137 { 138 fixed version, 139 font_revision; 140 uint32 check_sum_adjustment, 141 magic_number; 142 uint16 flags, 143 units_per_em; 144 long_date_time created, 145 modified; 146 fword x_min, 147 y_min, 148 x_max, 149 y_max; 150 uint16 mac_style, 151 lowest_rec_ppem; 152 int16 font_direction_hint, 153 index_to_loc_format, 154 glyph_data_format; 155 enum 156 { 157 MagicNumber = 0x5F0F3CF5, 158 GlypDataFormat = 0 159 }; 160 enum {ShortIndexLocFormat, LongIndexLocFormat}; 161 }; 162 163 164 165 166 struct PostScriptGlyphName 167 { 168 fixed format, 169 italic_angle; 170 fword underline_position, 171 underline_thickness; 172 uint32 is_fixed_pitch, 173 min_mem_type42, 174 max_mem_type42, 175 min_mem_type1, 176 max_mem_type1; 177 enum 178 { 179 Format1 = 0x10000, 180 Format2 = 0x20000, 181 Format25 = 0x28000, 182 Format3 = 0x30000, 183 Format4 = 0x40000 184 }; 185 }; 186 187 struct PostScriptGlyphName2 : PostScriptGlyphName 188 { 189 uint16 number_of_glyphs, 190 glyph_name_index[1]; 191 }; 192 193 struct PostScriptGlyphName25 : PostScriptGlyphName 194 { 195 uint16 number_of_glyphs; 196 int8 offset[1]; 197 }; 198 199 struct PostScriptGlyphName3 : PostScriptGlyphName {}; 200 201 struct PostScriptGlyphName4 : PostScriptGlyphName 202 { 203 uint16 glyph_to_char_map[1]; 204 }; 205 206 207 struct HorizontalHeader 208 { 209 fixed version; 210 fword ascent, 211 descent, 212 line_gap; 213 ufword advance_width_max; 214 fword min_left_side_bearing, 215 max_left_side_bearing, 216 x_max_element; 217 int16 caret_slope_rise, 218 caret_slope_run; 219 fword caret_offset; 220 int16 reserved[4], 221 metric_data_format; 222 uint16 num_long_hor_metrics; 223 }; 224 225 struct MaximumProfile 226 { 227 fixed version; 228 uint16 num_glyphs, 229 max_points, 230 max_contours, 231 max_component_points, 232 max_component_contours, 233 max_zones, 234 max_twilight_points, 235 max_storage, 236 max_function_defs, 237 max_instruction_defs, 238 max_stack_elements, 239 max_size_of_instructions, 240 max_component_elements, 241 max_component_depth; 242 }; 243 244 245 typedef gr::byte Panose[10]; 246 247 struct Compatibility0 248 { 249 uint16 version; 250 int16 x_avg_char_width; 251 uint16 weight_class, 252 width_class; 253 int16 fs_type, 254 y_subscript_x_size, 255 y_subscript_y_size, 256 y_subscript_x_offset, 257 y_subscript_y_offset, 258 y_superscript_x_size, 259 y_superscript_y_size, 260 y_superscript_x_offset, 261 y_superscript_y_offset, 262 y_strikeout_size, 263 y_strikeout_position, 264 family_class; 265 Panose panose; 266 uint32 unicode_range[4]; 267 int8 ach_vend_id[4]; 268 uint16 fs_selection, 269 fs_first_char_index, 270 fs_last_char_index, // Acording to Apple's spec this is where v0 should end 271 typo_ascender, 272 typo_descender, 273 type_linegap, 274 win_ascent, 275 win_descent; 276 277 enum 278 { 279 Italic =0x01, 280 Underscore=0x02, 281 Negative =0x04, 282 Outlined =0x08, 283 StrikeOut =0x10, 284 Bold =0x20 285 }; 286 }; 287 288 struct Compatibility1 : Compatibility0 289 { 290 uint32 codepage_range[2]; 291 }; 292 293 struct Compatibility2 : Compatibility1 294 { 295 int16 x_height, 296 cap_height; 297 uint16 default_char, 298 break_char, 299 max_context; 300 }; 301 302 struct Compatibility3 : Compatibility2 {}; 303 304 typedef Compatibility3 Compatibility; 305 306 307 struct NameRecord 308 { 309 uint16 platform_id, 310 platform_specific_id, 311 language_id, 312 name_id, 313 length, 314 offset; 315 enum {Unicode, Mactintosh, Reserved, Microsoft}; 316 enum 317 { 318 Copyright, Family, Subfamily, UniqueSubfamily, 319 Fullname, Version, PostScript 320 }; 321 }; 322 323 struct FontNames 324 { 325 uint16 format, 326 count, 327 string_offset; 328 NameRecord name_record[1]; 329 }; 330 331 332 struct HorizontalMetric 333 { 334 uint16 advance_width; 335 int16 left_side_bearing; 336 }; 337 338 339 struct Glyph 340 { 341 int16 number_of_contours; 342 fword x_min, 343 y_min, 344 x_max, 345 y_max; 346 }; 347 348 struct SimpleGlyph : Glyph 349 { 350 uint16 end_pts_of_contours[1]; 351 enum 352 { 353 OnCurve = 0x01, 354 XShort = 0x02, 355 YShort = 0x04, 356 Repeat = 0x08, 357 XIsSame = 0x10, 358 XIsPos = 0x10, 359 YIsSame = 0x20, 360 YIsPos = 0x20 361 }; 362 }; 363 364 struct CompoundGlyph : Glyph 365 { 366 uint16 flags, 367 glyph_index; 368 enum 369 { 370 Arg1Arg2Words = 0x01, 371 ArgsAreXYValues = 0x02, 372 RoundXYToGrid = 0x04, 373 HaveScale = 0x08, 374 MoreComponents = 0x20, 375 HaveXAndYScale = 0x40, 376 HaveTwoByTwo = 0x80, 377 HaveInstructions = 0x100, 378 UseMyMetrics = 0x200, 379 OverlapCompund = 0x400, 380 ScaledOffset = 0x800, 381 UnscaledOffset = 0x1000 382 }; 383 }; 384 385 #pragma pack() 386 } // end of namespace Sfnt 387 388 } // end of namespace TtfUtil 389