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