1 /* Copyright (C) 2001-2006 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, modified 8 or distributed except as expressly authorized under the terms of that 9 license. Refer to licensing information at http://www.artifex.com/ 10 or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, 11 San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. 12 */ 13 14 /* $Id: ttfoutl.h 8022 2007-06-05 22:23:38Z giles $ */ 15 /* The TrueType instruction interpreter interface definition. */ 16 17 #ifndef incl_ttfoutl 18 #define incl_ttfoutl 19 20 #ifndef TFace_defined 21 #define TFace_defined 22 typedef struct _TFace TFace; 23 #endif 24 25 #ifndef TInstance_defined 26 #define TInstance_defined 27 typedef struct _TInstance TInstance; 28 #endif 29 30 #ifndef TExecution_Context_defined 31 #define TExecution_Context_defined 32 typedef struct _TExecution_Context TExecution_Context; 33 #endif 34 35 #ifndef ttfInterpreter_DEFINED 36 # define ttfInterpreter_DEFINED 37 typedef struct ttfInterpreter_s ttfInterpreter; 38 #endif 39 40 /* Define auxiliary data types for the TT interpreter. */ 41 42 typedef struct ttfMemoryDescriptor_s ttfMemoryDescriptor; 43 44 typedef struct { 45 double a, b, c, d, tx, ty; 46 } FloatMatrix; 47 48 typedef struct { 49 double x, y; 50 } FloatPoint; 51 52 #if ARCH_LOG2_SIZEOF_LONG == 2 53 typedef signed long F26Dot6; 54 #elif ARCH_LOG2_SIZEOF_INT == 2 55 typedef signed int F26Dot6; 56 #else 57 #error "No appropriate type for Fixed 26.6 Floats" 58 #endif 59 60 typedef struct { 61 F26Dot6 x; 62 F26Dot6 y; 63 } F26Dot6Point; 64 65 /* Define an abstract class for accessing memory managers from the TT interpreter. */ 66 typedef struct ttfMemory_s ttfMemory; 67 struct ttfMemory_s { 68 void *(*alloc_bytes)(ttfMemory *, int size, const char *cname); 69 void *(*alloc_struct)(ttfMemory *, const ttfMemoryDescriptor *, const char *cname); 70 void (*free)(ttfMemory *, void *p, const char *cname); 71 } ; 72 73 typedef struct ttfSubGlyphUsage_s ttfSubGlyphUsage; 74 75 /* Define a capsule for the TT interpreter. */ 76 struct ttfInterpreter_s { 77 TExecution_Context *exec; 78 ttfSubGlyphUsage *usage; 79 int usage_size; 80 int usage_top; 81 int lock; 82 ttfMemory *ttf_memory; 83 }; 84 85 /* Define TT interpreter return codes. */ 86 typedef enum { 87 fNoError, 88 fTableNotFound, 89 fNameNotFound, 90 fMemoryError, 91 fUnimplemented, 92 fCMapNotFound, 93 fGlyphNotFound, 94 fBadFontData, 95 fPatented, 96 fBadInstruction 97 } FontError; 98 99 /* Define an abstract class for accessing TT data from the TT interpreter. */ 100 typedef struct ttfReader_s ttfReader; 101 struct ttfReader_s { 102 bool (*Eof)(ttfReader *); 103 void (*Read)(ttfReader *, void *p, int n); 104 void (*Seek)(ttfReader *, int nPos); 105 int (*Tell)(ttfReader *); 106 bool (*Error)(ttfReader *); 107 int (*LoadGlyph)(ttfReader *, int nIndex, const byte **, int *); 108 void (*ReleaseGlyph)(ttfReader *, int nIndex); 109 int (*get_metrics)(const ttfReader *ttf, uint glyph_index, bool bVertical, 110 short *sideBearing, unsigned short *nAdvance); 111 }; 112 113 /* Define an auxiliary structure for ttfFont. */ 114 typedef struct { 115 int nPos, nLen; 116 } ttfPtrElem; 117 118 /* Define a capsule for a TT face. 119 Diue to historical reason the name is some misleading. 120 It should be ttfFace. */ 121 #ifndef ttfFont_DEFINED 122 # define ttfFont_DEFINED 123 typedef struct ttfFont_s ttfFont; 124 #endif 125 struct ttfFont_s { 126 ttfPtrElem t_cvt_; 127 ttfPtrElem t_fpgm; 128 ttfPtrElem t_glyf; 129 ttfPtrElem t_head; 130 ttfPtrElem t_hhea; 131 ttfPtrElem t_hmtx; 132 ttfPtrElem t_vhea; 133 ttfPtrElem t_vmtx; 134 ttfPtrElem t_loca; 135 ttfPtrElem t_maxp; 136 ttfPtrElem t_prep; 137 ttfPtrElem t_cmap; 138 unsigned short nUnitsPerEm; 139 unsigned int nFlags; 140 unsigned int nNumGlyphs; 141 unsigned int nMaxComponents; 142 unsigned int nLongMetricsVert; 143 unsigned int nLongMetricsHorz; 144 unsigned int nIndexToLocFormat; 145 bool patented; 146 bool design_grid; 147 TFace *face; 148 TInstance *inst; 149 TExecution_Context *exec; 150 ttfInterpreter *tti; 151 void (*DebugRepaint)(ttfFont *); 152 int (*DebugPrint)(ttfFont *, const char *s, ...); 153 }; 154 155 void ttfFont__init(ttfFont *this, ttfMemory *mem, 156 void (*DebugRepaint)(ttfFont *), 157 int (*DebugPrint)(ttfFont *, const char *s, ...)); 158 void ttfFont__finit(ttfFont *this); 159 FontError ttfFont__Open(ttfInterpreter *, ttfFont *, ttfReader *r, 160 unsigned int nTTC, float w, float h, 161 bool design_grid); 162 163 /* Define an abstract class for exporting outlines from the TT interpreter. */ 164 typedef struct ttfExport_s ttfExport; 165 struct ttfExport_s { 166 bool bPoints, bOutline; 167 void (*MoveTo)(ttfExport *, FloatPoint*); 168 void (*LineTo)(ttfExport *, FloatPoint*); 169 void (*CurveTo)(ttfExport *, FloatPoint*, FloatPoint*, FloatPoint*); 170 void (*Close)(ttfExport *); 171 void (*Point)(ttfExport *, FloatPoint*, bool bOnCurve, bool bNewPath); 172 void (*SetWidth)(ttfExport *, FloatPoint*); 173 void (*DebugPaint)(ttfExport *); 174 }; 175 176 int ttfInterpreter__obtain(ttfMemory *mem, ttfInterpreter **ptti); 177 void ttfInterpreter__release(ttfInterpreter **ptti); 178 179 /* Define an class for outline description. */ 180 typedef struct { 181 bool bCompound; 182 int contourCount; 183 uint pointCount; 184 F26Dot6Point advance; 185 F26Dot6 sideBearing; 186 F26Dot6 xMinB, yMinB, xMaxB, yMaxB; 187 } ttfGlyphOutline; 188 189 /* Define an class for generating TT outlines. */ 190 typedef struct { 191 bool bOutline; 192 bool bFirst; 193 bool bVertical; 194 int nPointsTotal; 195 int nContoursTotal; 196 F26Dot6 ppx, ppy; 197 ttfReader *r; 198 ttfExport *exp; 199 ttfFont *pFont; 200 ttfGlyphOutline out; 201 FloatMatrix post_transform; 202 } ttfOutliner; 203 204 void ttfOutliner__init(ttfOutliner *, ttfFont *f, ttfReader *r, ttfExport *exp, 205 bool bOutline, bool bFirst, bool bVertical); 206 FontError ttfOutliner__Outline(ttfOutliner *this, int glyphIndex, 207 float orig_x, float orig_y, FloatMatrix *m1); 208 void ttfOutliner__DrawGlyphOutline(ttfOutliner *this); 209 210 #endif 211