1 /* Copyright (C) 2003 artofcode LLC. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 /* $Id: ttfsfnt.h,v 1.6 2003/12/09 21:17:59 giles Exp $ */ 17 /* Changes after Apple: replaced non-portable types with ISO/IEC 988:1999 exact-size types */ 18 19 /* 20 File 'sfnt.h' 21 22 Contains 'sfnt' resource structure description 23 24 Copyright 1991 Apple Computer, Inc. 25 26 */ 27 28 #ifndef sfntIncludes 29 #define sfntIncludes 30 31 #include "stdint_.h" /* make sure stdint types are available */ 32 33 typedef uint8_t uint8; /* 8-bit unsigned integer */ 34 typedef int8_t int8; /* 8-bit signed integer */ 35 typedef uint16_t uint16; /* 16-bit unsigned integer */ 36 typedef int16_t int16; /* 16-bit signed integer */ 37 typedef uint32_t uint32; /* 32-bit unsigned integer */ 38 typedef int32_t int32; /* 32-bit signed integer */ 39 #if 0 40 typedef int32_t Fixed; /* 16.16 32-bit signed fixed-point number */ 41 #endif 42 typedef int16_t FUnit; /* Smallest measurable distance in em space (16-bit signed integer) */ 43 typedef int16_t FWord; /* 16-bit signed integer that describes a quantity in FUnits */ 44 typedef uint16_t uFWord; /* 16-bit unsigned integer that describes a quantity in FUnits */ 45 typedef int16_t F2Dot14; /* 2.14 16-bit signed fixed-point number */ 46 #if 0 47 typedef int32_t F26Dot6; /* 26.6 32-bit signed fixed-point number */ 48 #endif 49 50 typedef struct { 51 uint32 bc; 52 uint32 ad; 53 } BigDate; 54 55 typedef struct { 56 uint32 tag; 57 uint32 checkSum; 58 uint32 offset; 59 uint32 length; 60 } sfnt_DirectoryEntry; 61 62 #define SFNT_VERSION 0x10000 63 64 /* 65 * The search fields limits numOffsets to 4096. 66 */ 67 typedef struct { 68 Fixed version; /* 1.0 */ 69 uint16 numOffsets; /* number of tables */ 70 uint16 searchRange; /* (max2 <= numOffsets)*16 */ 71 uint16 entrySelector; /* log2(max2 <= numOffsets) */ 72 uint16 rangeShift; /* numOffsets*16-searchRange*/ 73 sfnt_DirectoryEntry table[1]; /* table[numOffsets] */ 74 } sfnt_OffsetTable; 75 76 #define OFFSETTABLESIZE 12 /* not including any entries */ 77 78 typedef enum sfntHeaderFlagBits { 79 Y_POS_SPECS_BASELINE = 1, 80 X_POS_SPECS_LSB = 2, 81 HINTS_USE_POINTSIZE = 4, 82 USE_INTEGER_SCALING = 8, 83 INSTRUCTIONS_CHANGE_ADVANCEWIDTHS = 16, 84 X_POS_SPECS_BASELINE = 32, 85 Y_POS_SPECS_TSB = 64 86 } sfntHeaderFlagBits; 87 88 #define SFNT_MAGIC 0x5F0F3CF5 89 #define SHORT_INDEX_TO_LOC_FORMAT 0 90 #define LONG_INDEX_TO_LOC_FORMAT 1 91 #define GLYPH_DATA_FORMAT 0 92 #define FONT_HEADER_VERSION 0x10000 93 94 typedef struct { 95 Fixed version; /* for this table, set to 1.0 */ 96 Fixed fontRevision; /* For Font Manufacturer */ 97 uint32 checkSumAdjustment; 98 uint32 magicNumber; /* signature, should always be 0x5F0F3CF5 == MAGIC */ 99 uint16 flags; 100 uint16 unitsPerEm; /* Specifies how many in Font Units we have per EM */ 101 102 BigDate created; 103 BigDate modified; 104 105 /** This is the font wide bounding box in ideal space 106 (baselines and metrics are NOT worked into these numbers) **/ 107 int16 xMin; 108 int16 yMin; 109 int16 xMax; 110 int16 yMax; 111 112 uint16 macStyle; /* macintosh style word */ 113 uint16 lowestRecPPEM; /* lowest recommended pixels per Em */ 114 115 /* 0: fully mixed directional glyphs, 1: only strongly L->R or T->B glyphs, 116 -1: only strongly R->L or B->T glyphs, 2: like 1 but also contains neutrals, 117 -2: like -1 but also contains neutrals */ 118 int16 fontDirectionHint; 119 120 int16 indexToLocFormat; 121 int16 glyphDataFormat; 122 } sfnt_FontHeader; 123 124 #define METRIC_HEADER_FORMAT 0x10000 125 126 typedef struct { 127 Fixed version; /* for this table, set to 1.0 */ 128 int16 ascender; 129 int16 descender; 130 int16 lineGap; /* linespacing = ascender - descender + linegap */ 131 uint16 advanceMax; 132 int16 sideBearingMin; /* left or top */ 133 int16 otherSideBearingMin; /* right or bottom */ 134 int16 extentMax; /* Max of ( SB[i] + bounds[i] ), i loops through all glyphs */ 135 int16 caretSlopeNumerator; 136 int16 caretSlopeDenominator; 137 int16 caretOffset; 138 139 uint32 reserved1, reserved2; /* set to 0 */ 140 141 int16 metricDataFormat; /* set to 0 for current format */ 142 uint16 numberLongMetrics; /* if format == 0 */ 143 } sfnt_MetricsHeader; 144 145 typedef sfnt_MetricsHeader sfnt_HorizontalHeader; 146 typedef sfnt_MetricsHeader sfnt_VerticalHeader; 147 148 #define MAX_PROFILE_VERSION 0x10000 149 150 typedef struct { 151 Fixed version; /* for this table, set to 1.0 */ 152 uint16 numGlyphs; 153 uint16 maxPoints; /* in an individual glyph */ 154 uint16 maxContours; /* in an individual glyph */ 155 uint16 maxCompositePoints; /* in an composite glyph */ 156 uint16 maxCompositeContours; /* in an composite glyph */ 157 uint16 maxElements; /* set to 2, or 1 if no twilightzone points */ 158 uint16 maxTwilightPoints; /* max points in element zero */ 159 uint16 maxStorage; /* max number of storage locations */ 160 uint16 maxFunctionDefs; /* max number of FDEFs in any preprogram */ 161 uint16 maxInstructionDefs; /* max number of IDEFs in any preprogram */ 162 uint16 maxStackElements; /* max number of stack elements for any individual glyph */ 163 uint16 maxSizeOfInstructions; /* max size in bytes for any individual glyph */ 164 uint16 maxComponentElements; /* number of glyphs referenced at top level */ 165 uint16 maxComponentDepth; /* levels of recursion, 1 for simple components */ 166 } sfnt_maxProfileTable; 167 168 169 typedef struct { 170 uint16 advance; 171 int16 sideBearing; 172 } sfnt_GlyphMetrics; 173 174 typedef sfnt_GlyphMetrics sfnt_HorizontalMetrics; 175 typedef sfnt_GlyphMetrics sfnt_VerticalMetrics; 176 177 typedef int16 sfnt_ControlValue; 178 179 /* 180 * Char2Index structures, including platform IDs 181 */ 182 typedef struct { 183 uint16 format; 184 uint16 length; 185 uint16 version; 186 } sfnt_mappingTable; 187 188 typedef struct { 189 uint16 platformID; 190 uint16 specificID; 191 uint32 offset; 192 } sfnt_platformEntry; 193 194 typedef struct { 195 uint16 version; 196 uint16 numTables; 197 sfnt_platformEntry platform[1]; /* platform[numTables] */ 198 } sfnt_char2IndexDirectory; 199 #define SIZEOFCHAR2INDEXDIR 4 200 201 typedef struct { 202 uint16 platformID; 203 uint16 specificID; 204 uint16 languageID; 205 uint16 nameID; 206 uint16 length; 207 uint16 offset; 208 } sfnt_NameRecord; 209 210 typedef struct { 211 uint16 format; 212 uint16 count; 213 uint16 stringOffset; 214 /* sfnt_NameRecord[count] */ 215 } sfnt_NamingTable; 216 217 #define DEVWIDTHEXTRA 2 /* size + max */ 218 /* 219 * Each record is n+2 bytes, padded to long word alignment. 220 * First byte is ppem, second is maxWidth, rest are widths for each glyph 221 */ 222 typedef struct { 223 int16 version; 224 int16 numRecords; 225 int32 recordSize; 226 /* Byte widths[numGlyphs+DEVWIDTHEXTRA] * numRecords */ 227 } sfnt_DeviceMetrics; 228 229 #define stdPostTableFormat 0x10000 230 #define wordPostTableFormat 0x20000 231 #define bytePostTableFormat 0x28000 232 #define richardsPostTableFormat 0x30000 233 234 typedef struct { 235 Fixed version; 236 Fixed italicAngle; 237 int16 underlinePosition; 238 int16 underlineThickness; 239 int16 isFixedPitch; 240 int16 pad; 241 uint32 minMemType42; 242 uint32 maxMemType42; 243 uint32 minMemType1; 244 uint32 maxMemType1; 245 /* if version == 2.0 246 { 247 numberGlyphs; 248 unsigned short[numberGlyphs]; 249 pascalString[numberNewNames]; 250 } 251 else if version == 2.5 252 { 253 numberGlyphs; 254 int8[numberGlyphs]; 255 } 256 */ 257 } sfnt_PostScriptInfo; 258 259 typedef enum outlinePacking { 260 ONCURVE = 1, 261 XSHORT = 2, 262 YSHORT = 4, 263 REPEAT_FLAGS = 8, 264 /* IF XSHORT */ 265 SHORT_X_IS_POS = 16, /* the short vector is positive */ 266 /* ELSE */ 267 NEXT_X_IS_ZERO = 16, /* the relative x coordinate is zero */ 268 /* ENDIF */ 269 /* IF YSHORT */ 270 SHORT_Y_IS_POS = 32, /* the short vector is positive */ 271 /* ELSE */ 272 NEXT_Y_IS_ZERO = 32 /* the relative y coordinate is zero */ 273 /* ENDIF */ 274 } outlinePacking; 275 276 typedef enum componentPacking { 277 COMPONENTCTRCOUNT = -1, 278 ARG_1_AND_2_ARE_WORDS = 1, /* if not, they are bytes */ 279 ARGS_ARE_XY_VALUES = 2, /* if not, they are points */ 280 ROUND_XY_TO_GRID = 4, 281 WE_HAVE_A_SCALE = 8, /* if not, Sx = Sy = 1.0 */ 282 NON_OVERLAPPING = 16, 283 MORE_COMPONENTS = 32, /* if not, this is the last one */ 284 WE_HAVE_AN_X_AND_Y_SCALE = 64, /* Sx != Sy */ 285 WE_HAVE_A_TWO_BY_TWO = 128, /* t00, t01, t10, t11 */ 286 WE_HAVE_INSTRUCTIONS = 256, /* short count followed by instructions follows */ 287 USE_MY_METRICS = 512 /* use my metrics for parent glyph */ 288 } componentPacking; 289 290 typedef struct { 291 uint16 firstCode; 292 uint16 entryCount; 293 int16 idDelta; 294 uint16 idRangeOffset; 295 } sfnt_subheader; 296 297 typedef struct { 298 uint16 segCountX2; 299 uint16 searchRange; 300 uint16 entrySelector; 301 uint16 rangeShift; 302 } sfnt_4_subheader; 303 304 /* sfnt_enum.h */ 305 306 typedef enum { 307 plat_Unicode, 308 plat_Macintosh, 309 plat_ISO, 310 plat_MS 311 } platformEnums; 312 313 #define tag_FontHeader 'daeh' /* (*(LPDWORD)"head") */ 314 #define tag_HoriHeader 'aehh' /* (*(LPDWORD)"hhea") */ 315 #define tag_VertHeader 'aehv' /* (*(LPDWORD)"vhea") */ 316 #define tag_IndexToLoc 'acol' /* (*(LPDWORD)"loca") */ 317 #define tag_MaxProfile 'pxam' /* (*(LPDWORD)"maxp") */ 318 #define tag_ControlValue ' tvc' /* (*(LPDWORD)"cvt ") */ 319 #define tag_PreProgram 'perp' /* (*(LPDWORD)"prep") */ 320 #define tag_GlyphData 'fylg' /* (*(LPDWORD)"glyf") */ 321 #define tag_HorizontalMetrics 'xtmh' /* (*(LPDWORD)"hmtx") */ 322 #define tag_VerticalMetrics 'xtmv' /* (*(LPDWORD)"vmtx") */ 323 #define tag_CharToIndexMap 'pamc' /* (*(LPDWORD)"cmap") */ 324 #define tag_FontProgram 'mgpf' /* (*(LPDWORD)"fpgm") */ 325 326 #define tag_Kerning 'nrek' /* (*(LPDWORD)"kern") */ 327 #define tag_HoriDeviceMetrics 'xmdh' /* (*(LPDWORD)"hdmx") */ 328 #define tag_NamingTable 'eman' /* (*(LPDWORD)"name") */ 329 #define tag_PostScript 'tsop' /* (*(LPDWORD)"post") */ 330 331 #if 0 332 /* access.h */ 333 #define fNoError 0 334 #define fTableNotFound -1 335 #define fNameNotFound -2 336 #define fMemoryError -3 337 #define fUnimplemented -4 338 #define fCMapNotFound -5 339 #define fGlyphNotFound -6 340 341 typedef int32 FontError; 342 #endif 343 344 typedef struct FontTableInfo { 345 int32 offset; /* from beginning of sfnt to beginning of the table */ 346 int32 length; /* length of the table */ 347 int32 checkSum; /* checkSum of the table */ 348 } FontTableInfo; 349 350 #define RAW_TRUE_TYPE_SIZE 512 351 352 #endif 353