home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s076 / 4.img / DEMO / SFNT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-30  |  10.0 KB  |  317 lines

  1. /*
  2.     File:       sfnt.h
  3.  
  4.     Copyright:  c 1988-1990 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #ifndef SFNT_ENUMS
  9. #include "sfnt_en.h"
  10. #endif
  11.  
  12. typedef struct {
  13.     uint32 bc;
  14.     uint32 ad;
  15. } BigDate;
  16.  
  17. typedef struct {
  18.     sfnt_TableTag   tag;
  19.     uint32          checkSum;
  20.     uint32          offset;
  21.     uint32          length;
  22. } sfnt_DirectoryEntry;
  23.  
  24. /*
  25.  *  The search fields limits numOffsets to 4096.
  26.  */
  27. typedef struct {
  28.     int32 version;                  /* 0x10000 (1.0) */
  29.     uint16 numOffsets;              /* number of tables */
  30.     uint16 searchRange;             /* (max2 <= numOffsets)*16 */
  31.     uint16 entrySelector;           /* log2 (max2 <= numOffsets) */
  32.     uint16 rangeShift;              /* numOffsets*16-searchRange*/
  33.     sfnt_DirectoryEntry table[1];   /* table[numOffsets] */
  34. } sfnt_OffsetTable;
  35. #define OFFSETTABLESIZE     12  /* not including any entries */
  36.  
  37. /*
  38.  *  for the flags field
  39.  */
  40. #define Y_POS_SPECS_BASELINE            0x0001
  41. #define X_POS_SPECS_LSB                 0x0002
  42. #define HINTS_USE_POINTSIZE             0x0004
  43. #define USE_INTEGER_SCALING             0x0008
  44.  
  45. #define SFNT_MAGIC 0x5F0F3CF5
  46.  
  47. #define SHORT_INDEX_TO_LOC_FORMAT       0
  48. #define LONG_INDEX_TO_LOC_FORMAT        1
  49. #define GLYPH_DATA_FORMAT               0
  50.  
  51. typedef struct {
  52.     Fixed       version;            /* for this table, set to 1.0 */
  53.     Fixed       fontRevision;       /* For Font Manufacturer */
  54.     uint32      checkSumAdjustment;
  55.     uint32      magicNumber;        /* signature, should always be 0x5F0F3CF5  == MAGIC */
  56.     uint16      flags;
  57.     uint16      unitsPerEm;         /* Specifies how many in Font Units we have per EM */
  58.  
  59.     BigDate     created;
  60.     BigDate     modified;
  61.  
  62.     /** This is the font wide bounding box in ideal space
  63.  (baselines and metrics are NOT worked into these numbers) **/
  64.     FUnit       xMin;
  65.     FUnit       yMin;
  66.     FUnit       xMax;
  67.     FUnit       yMax;
  68.  
  69.     uint16      macStyle;               /* macintosh style word */
  70.     uint16      lowestRecPPEM;          /* lowest recommended pixels per Em */
  71.  
  72.     /* 0: fully mixed directional glyphs, 1: only strongly L->R or T->B glyphs, 
  73.        -1: only strongly R->L or B->T glyphs, 2: like 1 but also contains neutrals,
  74.        -2: like -1 but also contains neutrals */
  75.     int16       fontDirectionHint;
  76.  
  77.     int16       indexToLocFormat;
  78.     int16       glyphDataFormat;
  79. } sfnt_FontHeader;
  80.  
  81. typedef struct {
  82.     Fixed       version;                /* for this table, set to 1.0 */
  83.  
  84.     FUnit       yAscender;
  85.     FUnit       yDescender;
  86.     FUnit       yLineGap;       /* Recommended linespacing = ascender - descender + linegap */
  87.     uFUnit      advanceWidthMax;
  88.     FUnit       minLeftSideBearing;
  89.     FUnit       minRightSideBearing;
  90.     FUnit       xMaxExtent; /* Max of (LSBi + (XMAXi - XMINi)), i loops through all glyphs */
  91.  
  92.     int16       horizontalCaretSlopeNumerator;
  93.     int16       horizontalCaretSlopeDenominator;
  94.  
  95.     uint16      reserved0;
  96.     uint16      reserved1;
  97.     uint16      reserved2;
  98.     uint16      reserved3;
  99.     uint16      reserved4;
  100.  
  101.     int16       metricDataFormat;           /* set to 0 for current format */
  102.     uint16      numberOf_LongHorMetrics;    /* if format == 0 */
  103. } sfnt_HorizontalHeader;
  104.  
  105. typedef struct {
  106.     Fixed       version;                /* for this table, set to 1.0 */
  107.     uint16      numGlyphs;
  108.     uint16      maxPoints;              /* in an individual glyph */
  109.     uint16      maxContours;            /* in an individual glyph */
  110.     uint16      maxCompositePoints;     /* in an composite glyph */
  111.     uint16      maxCompositeContours;   /* in an composite glyph */
  112.     uint16      maxElements;            /* set to 2, or 1 if no twilightzone points */
  113.     uint16      maxTwilightPoints;      /* max points in element zero */
  114.     uint16      maxStorage;             /* max number of storage locations */
  115.     uint16      maxFunctionDefs;        /* max number of FDEFs in any preprogram */
  116.     uint16      maxInstructionDefs;     /* max number of IDEFs in any preprogram */
  117.     uint16      maxStackElements;       /* max number of stack elements for any individual glyph */
  118.     uint16      maxSizeOfInstructions;  /* max size in bytes for any individual glyph */
  119.     uint16      maxComponentElements;   /* number of glyphs referenced at top level */
  120.     uint16      maxComponentDepth;      /* levels of recursion, 1 for simple components */
  121. } sfnt_maxProfileTable;
  122.  
  123.  
  124. typedef struct {
  125.     uint16      advanceWidth;
  126.     int16       leftSideBearing;
  127. } sfnt_HorizontalMetrics;
  128.  
  129. /*
  130.  *  CVT is just a bunch of int16s
  131.  */
  132. typedef int16 sfnt_ControlValue;
  133.  
  134. /*
  135.  *  Char2Index structures, including platform IDs
  136.  */
  137. typedef struct {
  138.     uint16  format;
  139.     uint16  length;
  140.     uint16  version;
  141. } sfnt_mappingTable;
  142.  
  143. typedef struct {
  144.     uint16  platformID;
  145.     uint16  specificID;
  146.     uint32  offset;
  147. } sfnt_platformEntry;
  148.  
  149. typedef struct {
  150.     uint16  version;
  151.     uint16  numTables;
  152.     sfnt_platformEntry platform[1]; /* platform[numTables] */
  153. } sfnt_char2IndexDirectory;
  154. #define SIZEOFCHAR2INDEXDIR     4
  155.  
  156. typedef struct {
  157.     uint16 platformID;
  158.     uint16 specificID;
  159.     uint16 languageID;
  160.     uint16 nameID;
  161.     uint16 length;
  162.     uint16 offset;
  163. } sfnt_NameRecord;
  164.  
  165. typedef struct {
  166.     uint16 format;
  167.     uint16 count;
  168.     uint16 stringOffset;
  169. /*  sfnt_NameRecord[count]  */
  170. } sfnt_NamingTable;
  171.  
  172.  
  173. #define DEVEXTRA    2   /* size + max */
  174. /*
  175.  *  Each record is n+2 bytes, padded to long word alignment.
  176.  *  First byte is ppem, second is maxWidth, rest are widths for each glyph
  177.  */
  178. typedef struct {
  179.     int16               version;
  180.     int16               numRecords;
  181.     int32               recordSize;
  182.     /* Byte widths[numGlyphs+2] * numRecords */
  183. } sfnt_DeviceMetrics;
  184.  
  185. #ifdef UNNAMED_UNION        /* Anonymous unions are supported */
  186. #define postScriptNameIndices    /* by some C implementations,  */
  187. #endif                /* but they are not portable. */
  188.  
  189. typedef struct {
  190.     Fixed   version;                /* 1.0 */
  191.     Fixed   italicAngle;
  192.     FUnit   underlinePosition;
  193.     FUnit   underlineThickness;
  194.     int16   isFixedPitch;
  195.     int16   pad;
  196.     uint32  minMemType42;
  197.     uint32  maxMemType42;
  198.     uint32  minMemType1;
  199.     uint32  maxMemType1;
  200.  
  201.     uint16  numberGlyphs;
  202.     union
  203.     {
  204.       uint16  glyphNameIndex[1];   /* version == 2.0 */
  205.       int8    glyphNameIndex25[1]; /* version == 2.5 */
  206.     } postScriptNameIndices;
  207. } sfnt_PostScriptInfo;
  208.  
  209. #ifdef postScriptNameIndices
  210. #undef postScriptNameIndices
  211. #endif 
  212.  
  213. typedef struct {
  214.     uint16  Version;
  215.     int16   xAvgCharWidth;
  216.     uint16  usWeightClass;
  217.     uint16  usWidthClass;
  218.     int16   fsType;
  219.     int16   ySubscriptXSize;
  220.     int16   ySubscriptYSize;
  221.     int16   ySubscriptXOffset;
  222.     int16   ySubscriptYOffset;
  223.     int16   ySuperScriptXSize;
  224.     int16   ySuperScriptYSize;
  225.     int16   ySuperScriptXOffset;
  226.     int16   ySuperScriptYOffset;
  227.     int16   yStrikeOutSize;
  228.     int16   yStrikeOutPosition;
  229.     int16   sFamilyClass;
  230.     uint8   Panose [10];
  231.     uint32  ulCharRange [4];
  232.     char    achVendID [4];
  233.     uint16  usSelection;
  234.     uint16  usFirstChar;
  235.     uint16  usLastChar;
  236. } sfnt_OS2;
  237. /* various typedef to access to the sfnt data */
  238.  
  239. typedef sfnt_OffsetTable          FAR *sfnt_OffsetTablePtr;
  240. typedef sfnt_FontHeader           FAR *sfnt_FontHeaderPtr;
  241. typedef sfnt_HorizontalHeader     FAR *sfnt_HorizontalHeaderPtr;
  242. typedef sfnt_maxProfileTable      FAR *sfnt_maxProfileTablePtr;
  243. typedef sfnt_ControlValue         FAR *sfnt_ControlValuePtr;
  244. typedef sfnt_char2IndexDirectory  FAR *sfnt_char2IndexDirectoryPtr;
  245. typedef sfnt_HorizontalMetrics    FAR *sfnt_HorizontalMetricsPtr;
  246. typedef sfnt_platformEntry        FAR *sfnt_platformEntryPtr;
  247. typedef sfnt_NamingTable          FAR *sfnt_NamingTablePtr;
  248. typedef sfnt_OS2                  FAR *sfnt_OS2Ptr;
  249. typedef sfnt_DirectoryEntry       FAR *sfnt_DirectoryEntryPtr;
  250. typedef sfnt_PostScriptInfo       FAR *sfnt_PostScriptInfoPtr;
  251.  
  252.  
  253.  
  254.  
  255. /*
  256.  * UNPACKING Constants
  257. */
  258. #define ONCURVE             0x01
  259. #define XSHORT              0x02
  260. #define YSHORT              0x04
  261. #define REPEAT_FLAGS        0x08 /* repeat flag n times */
  262. /* IF XSHORT */
  263. #define SHORT_X_IS_POS      0x10 /* the short vector is positive */
  264. /* ELSE */
  265. #define NEXT_X_IS_ZERO      0x10 /* the relative x coordinate is zero */
  266. /* ENDIF */
  267. /* IF YSHORT */
  268. #define SHORT_Y_IS_POS      0x20 /* the short vector is positive */
  269. /* ELSE */
  270. #define NEXT_Y_IS_ZERO      0x20 /* the relative y coordinate is zero */
  271. /* ENDIF */
  272. /* 0x40 & 0x80              RESERVED
  273. ** Set to Zero
  274. **
  275. */
  276.  
  277. /*
  278.  * Composite glyph constants
  279.  */
  280. #define COMPONENTCTRCOUNT           -1      /* ctrCount == -1 for composite */
  281. #define ARG_1_AND_2_ARE_WORDS       0x0001  /* if set args are words otherwise they are bytes */
  282. #define ARGS_ARE_XY_VALUES          0x0002  /* if set args are xy values, otherwise they are points */
  283. #define ROUND_XY_TO_GRID            0x0004  /* for the xy values if above is true */
  284. #define WE_HAVE_A_SCALE             0x0008  /* Sx = Sy, otherwise scale == 1.0 */
  285. #define NON_OVERLAPPING             0x0010  /* set to same value for all components */
  286. #define MORE_COMPONENTS             0x0020  /* indicates at least one more glyph after this one */
  287. #define WE_HAVE_AN_X_AND_Y_SCALE    0x0040  /* Sx, Sy */
  288. #define WE_HAVE_A_TWO_BY_TWO        0x0080  /* t00, t01, t10, t11 */
  289. #define WE_HAVE_INSTRUCTIONS        0x0100  /* instructions follow */
  290.  
  291. /*
  292.  *  Private enums for tables used by the scaler.  See sfnt_Classify
  293.  */
  294. typedef enum {
  295.     sfnt_fontHeader,
  296.     sfnt_horiHeader,
  297.     sfnt_indexToLoc,
  298.     sfnt_maxProfile,
  299.     sfnt_controlValue,
  300.     sfnt_preProgram,
  301.     sfnt_glyphData,
  302.     sfnt_horizontalMetrics,
  303.     sfnt_charToIndexMap,
  304.     sfnt_fontProgram,
  305. #ifdef PC_OS
  306.     sfnt_Postscript,
  307.     sfnt_HoriDeviceMetrics,
  308.     sfnt_LinearThreeShold,
  309.     sfnt_Names,
  310.     sfnt_OS_2,
  311. #endif
  312. #ifdef FSCFG_USE_GLYPH_DIRECTORY
  313.     sfnt_GlyphDirectory,
  314. #endif 
  315.     sfnt_NUMTABLEINDEX
  316. } sfnt_tableIndex;
  317.