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