Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

Ttf.h

00001 class TtfTable;
00002 class GdcTtf;
00003 
00004 class LgiClass GdcFontMetrics {
00005 public:
00006     long tmHeight; 
00007     long tmAscent; 
00008     long tmDescent; 
00009     long tmInternalLeading; 
00010     long tmExternalLeading; 
00011     long tmAveCharWidth; 
00012     long tmMaxCharWidth; 
00013     long tmWeight; 
00014     long tmOverhang; 
00015     long tmDigitizedAspectX; 
00016     long tmDigitizedAspectY; 
00017     char tmFirstChar; 
00018     char tmLastChar; 
00019     char tmDefaultChar; 
00020     char tmBreakChar; 
00021     char tmItalic; 
00022     char tmUnderlined; 
00023     char tmStruckOut; 
00024     char tmPitchAndFamily; 
00025     char tmCharSet; 
00026 };
00027 
00028 class LgiClass GTypeFace {
00029 protected:
00030     uint Flags;         // FNT_xxx flags
00031     uint Height; 
00032     uint Width; 
00033     uint Escapement; 
00034     uint Orientation; 
00035     uint Weight; 
00036     uchar CharSet; 
00037     uchar OutPrecision; 
00038     uchar ClipPrecision; 
00039     uchar Quality; 
00040     uchar PitchAndFamily; 
00041     char FaceName[33];
00042 
00043     // Output
00044     COLOUR ForeCol;
00045     COLOUR BackCol;
00046     bool Trans;
00047 
00048     int TabSize;
00049 
00050 public:
00051     GTypeFace()
00052     {
00053         ForeCol = 0;
00054         BackCol = 0xFFFFFF;
00055         Trans = FALSE;
00056         TabSize = 0;
00057     }
00058     
00059     virtual ~GTypeFace() {}
00060 
00061     virtual void Colour(COLOUR Fore, COLOUR Back = 0xFFFFFFFF) { ForeCol = Fore; BackCol = Back; }
00062     void Fore(COLOUR f) { ForeCol = f; }
00063     COLOUR Fore() { return ForeCol; }
00064     void Back(COLOUR b) { BackCol = b; }
00065     COLOUR Back() { return BackCol; }
00066     void Transparent(bool t) { Trans = t; }
00067 
00068     void SetTabs(int tabsize)
00069     {
00070         TabSize = tabsize;
00071     }
00072 
00073     virtual bool Load(GFile &F) { return FALSE; }
00074     virtual bool Save(GFile &F) { return FALSE; }
00075 };
00076 
00077 typedef unsigned long               TTF_FIXED;
00078 typedef signed short                TTF_FWORD;
00079 typedef unsigned short              TTF_UFWORD;
00080 typedef signed short                TTF_F2DOT14;
00081 
00082 class LgiClass TtfFileHeader {
00083 public:
00084     TTF_FIXED Version;          // 0x00010000 for version 1.0.
00085     ushort  NumTables;          // Number of tables. 
00086     ushort  SearchRange;            // (Maximum power of 2 £ numTables) x 16.
00087     ushort  EntrySelector;          // Log2(maximum power of 2 £ numTables).
00088     ushort  RangeShift;         // NumTables x 16-searchRange.
00089 
00090     bool Read(GFile &F);
00091     bool Write(GFile &F);
00092     void Dump();
00093 };
00094 
00095 class LgiClass TtfTable {
00096 public:
00097     char    Tag[4];             // 4-byte identifier.
00098     ulong   CheckSum;           // CheckSum for this table.
00099     ulong   Offset;             // Offset from beginning of TrueType font file.
00100     ulong   Length;             // Length of this table.
00101 
00102     void    *Table;
00103 
00104     virtual bool Read(GFile &F);
00105     virtual bool Write(GFile &F);
00106     virtual void Dump();
00107 };
00108 
00109 class LgiClass TtfObj {
00110 public:
00111     GdcTtf *Parent;
00112     TtfObj() { Parent = 0; }
00113     void *FindTag(char *t);
00114 };
00115 
00116 class LgiClass TtfHeader : public TtfObj {
00117 public:
00118     ulong   Version;            // 0x00010000 for version 1.0.
00119     ulong   Revision;           // Set by font manufacturer.
00120     ulong   CheckSumAdjustment;     // To compute: set it to 0, sum the entire font as ULONG, then store 0xB1B0AFBA - sum.
00121     ulong   MagicNumber;            // Set to 0x5F0F3CF5.
00122     ushort  Flags;              // 0x0001 - baseline for font at y=0
00123                         // 0x0002 - left sidebearing at x=0
00124                         // 0x0004 - instructions may depend on point size
00125                         // 0x0008 - force ppem to integer values for all internal scaler math, may use fractional ppem sizes if this bit is clear
00126                         // 0x0010 - instructions may alter advance width (the advance widths might not scale linearly)
00127                         // Note: All other bits must be zero.
00128     ushort  UnitsPerEm;         // Valid range is from 16 to 16384
00129     quad    InternationalDate;      // (8-byte field).
00130     quad    Modified;           // International date (8-byte field).
00131     TTF_FWORD xMin;             // For all glyph bounding boxes.
00132     TTF_FWORD yMin;             // For all glyph bounding boxes.
00133     TTF_FWORD xMax;             // For all glyph bounding boxes.
00134     TTF_FWORD yMax;             // For all glyph bounding boxes.
00135     ushort  MacStyle;           // 0x0001 - bold (if set to 1)
00136                         // 0x0002 - italic (if set to 1)
00137                         // Bits 2-15 reserved (set to 0).
00138     ushort  LowestRecPPEM;          // Smallest readable size in pixels.
00139     short   FontDirectionHint;      // 0   Fully mixed directional glyphs
00140                         // 1   Only strongly left to right
00141                         // 2   Like 1 but also contains neutrals
00142                         // -1   Only strongly right to left
00143                         // -2   Like -1 but also contains neutrals.
00144     short   IndexToLocFormat;       // 0 for short offsets
00145                         // 1 for long.
00146     short   GlyphDataFormat;        // 0 for current format.
00147 
00148     bool Read(GFile &F);
00149     bool Write(GFile &F);
00150     void Dump();
00151 };
00152 
00153 class LgiClass TtfMaxProfile : public TtfObj {
00154 public:
00155     ulong   Version;            // 0x00010000 for version 1.0.
00156     ushort  NumGlyphs;          // The number of glyphs in the font.
00157     ushort  MaxPoints;          // Maximum points in a non-composite glyph.
00158     ushort  MaxContours;            // Maximum contours in a non-composite glyph.
00159     ushort  MaxCompositePoints;     // Maximum points in a composite glyph.
00160     ushort  MaxCompositeContours;       // Maximum contours in a composite glyph.
00161     ushort  MaxZones;           // 1 if instructions do not use the twilight zone (Z0), or 2 if instructions do use Z0; should be set to 2 in most cases.
00162     ushort  MaxTwilightPoints;      // Maximum points used in Z0.
00163     ushort  MaxStorage;         // Number of Storage Area locations. 
00164     ushort  MaxFunctionDefs;        // Number of FDEFs.
00165     ushort  MaxInstructionDefs;     // Number of IDEFs.
00166     ushort  MaxStackElements;       // Maximum stack depth .
00167     ushort  MaxSizeOfInstructions;      // Maximum byte count for glyph instructions.
00168     ushort  MaxComponentElements;       // Maximum number of components referenced at "top level" for any composite glyph.
00169     ushort  MaxComponentDepth;      // Maximum levels of recursion; 1 for simple components.
00170 
00171     bool Read(GFile &F);
00172     bool Write(GFile &F);
00173     void Dump();
00174 };
00175 
00176 class LgiClass TtfLocation : public TtfObj {
00177 
00178     int Entries;
00179     int Type;
00180     void *Data;
00181 
00182 public:
00183     TtfLocation();
00184     virtual ~TtfLocation();
00185 
00186     int operator [](int i);
00187     bool Read(GFile &F);
00188     bool Write(GFile &F);
00189     void Dump();
00190 };
00191 
00192 class LgiClass DataList {
00193 
00194     int Alloc;
00195 
00196 public:
00197     int Size;
00198     double *Data;
00199 
00200     DataList()
00201     {
00202         Size = 0;
00203         Alloc = 0;
00204         Data = 0;
00205     }
00206 
00207     virtual ~DataList()
00208     {
00209         DeleteArray(Data);
00210     }
00211 
00212     void AddValue(double n)
00213     {
00214         if (Size >= Alloc)
00215         {
00216             int NewAlloc = (Size + 16) & (~0xF);
00217             double *Temp = NEW(double[NewAlloc]);
00218             if (Temp)
00219             {
00220                 memcpy(Temp, Data, sizeof(double)*Size);
00221                 DeleteArray(Data);
00222                 Data = Temp;
00223                 Alloc = NewAlloc;
00224             }
00225             else
00226             {
00227                 return;
00228             }
00229         }
00230 
00231         if (Size > 0)
00232         {
00233             for (int i=0; i<Size; i++)
00234             {
00235                 if (Data[i] > n)
00236                 {
00237                     memmove(Data + i + 1, Data + i, sizeof(double)*(Size-i));
00238                     Data[i] = n;
00239                     Size++;
00240                     return;
00241                 }
00242             }
00243             Data[Size] = n;
00244         }
00245         else
00246         {
00247             Data[0] = n;
00248         }
00249 
00250         Size++;
00251     }
00252 };
00253 
00254 class LgiClass TtfContour {
00255 
00256     class CPt {
00257     public:
00258         double x, y;
00259     };
00260 
00261     // From glyph
00262     int *x, *y;
00263     uchar *Flags;
00264     int XOff, YOff;
00265     
00266     // Out stuff
00267     int Points;
00268     int Alloc;
00269     CPt *Point;
00270 
00271     bool SetPoints(int p);
00272     void Bezier(CPt *p, double Threshold = 0.5);
00273 
00274 public:
00275     TtfContour();
00276     ~TtfContour();
00277 
00278     void Setup(int *x, int *y, uchar *Flags, int MinX, int MinY);
00279     bool Create(int Pts, double XScale, double YScale);
00280     bool RasterX(int Size, DataList *List);
00281     bool RasterY(int Size, DataList *List);
00282 
00283     void DebugDraw(GSurface *pDC, int Sx, int Sy);
00284 };
00285 
00286 class LgiClass TtfGlyph : public TtfObj {
00287 
00288     int Points;
00289     uchar *Temp;
00290 
00291 public:
00292     TtfGlyph();
00293     ~TtfGlyph();
00294 
00295     short   Contours;           // If  the number of contours is greater than or equal to zero,
00296                         // this is a single glyph, if negative, this is a composite glyph.
00297     TTF_FWORD xMin;             // Minimum x for coordinate data.
00298     TTF_FWORD yMin;             // Minimum y for coordinate data.
00299     TTF_FWORD xMax;             // Maximum x for coordinate data.
00300     TTF_FWORD yMax;             // Maximum y for coordinate data.
00301 
00302     // simple glyph
00303     ushort  *EndPtsOfContours;      // Array of last points of each contour; n  is the number of contours.
00304     ushort  InstructionLength;      // Total number of bytes for instructions.
00305     uchar   *Instructions;          // Array of instructions for each glyph; n  is the number of instructions.
00306     uchar   *Flags;             // Array of flags for each coordinate in outline; n  is the number of flags.
00307     int *X;             // First coordinates relative to (0,0)
00308     int *Y;             // others are relative to previous point.
00309 
00310     // complex glyph
00311     // yeah right... later i think... maybe
00312 
00313     int GetX() { return xMax - xMin; }
00314     int GetY() { return yMax - yMin; }
00315 
00316     bool Read(GFile &F);
00317     bool Write(GFile &F);
00318     void Dump();
00319     void Draw(GSurface *pDC, int x, int y, int Scale);
00320     int DrawEm(GSurface *pDC, int X, int Y, int EmUnits, double PixelsPerEm);
00321     bool Rasterize( GSurface *pDC,
00322             GRect *pDest,
00323             double xppem,
00324             double yppem,
00325             int BaseLine);
00326 };
00327 
00328 class LgiClass TtfMap {
00329 public:
00330     TtfMap() {}
00331     virtual ~TtfMap() {}
00332     virtual int operator[](int i) { return 0; }
00333     virtual bool Read(GFile &F) { return FALSE; }
00334     virtual bool Write(GFile &F) { return FALSE; }
00335     virtual void Dump() {}
00336 };
00337 
00338 class LgiClass TtfCMapTable {
00339 public:
00340     TtfCMapTable();
00341     ~TtfCMapTable();
00342 
00343     ushort  PlatformID;
00344     ushort  EncodingID;
00345     ulong   Offset;
00346 
00347     ushort Format;
00348     TtfMap  *Map;
00349 
00350     bool Read(GFile &F);
00351     bool Write(GFile &F);
00352     void Dump();
00353 };
00354 
00355 class LgiClass TtfCMapByteEnc : public TtfMap {
00356 
00357     ushort  Format;             // set to 0
00358     ushort  Length;             // length in bytes of the subtable
00359     ushort  Version;
00360     uchar   Map[256];
00361 
00362 public:
00363     int operator[](int i);
00364     bool Read(GFile &F);
00365     bool Write(GFile &F);
00366     void Dump();
00367 };
00368 
00369 class LgiClass TtfCMapHighByte : public TtfMap {
00370 
00371     class SubHeader {
00372     public:
00373         ushort  FirstCode;      // First valid low byte for this subHeader
00374         ushort  EntryCount;     // Number of valid low bytes for this subHeader
00375         short   IdDelta;
00376         ushort  IdRangeOffset;
00377     };
00378 
00379     ushort  Format;             // set to 2
00380     ushort  Length;
00381     ushort  Version;
00382     ushort  subHeaderKeys[256];     // Array that maps high bytes to subHeaders:
00383                         // value is subHeader index * 8.
00384     SubHeader *Header;
00385     ushort  *GlyphIndexArray;
00386 
00387 public:
00388     int operator[](int i) { return 0; }
00389     bool Read(GFile &F) { return FALSE; }
00390     bool Write(GFile &F) { return FALSE; }
00391     void Dump() {}
00392 };
00393 
00394 class LgiClass TtfCMapSegDelta : public TtfMap {
00395 
00396     int SegCount;
00397     int IdCount;
00398 
00399     ushort  Format;             // set to 4
00400     ushort  Length;
00401     ushort  Version;
00402     ushort  SegCountX2;         // 2 x segCount.
00403     ushort  SearchRange;        // 2 x (2**floor(log2(segCount)))
00404     ushort  EntrySelector;      // log2(searchRange/2)
00405     ushort  RangeShift;         // 2 x segCount - searchRange
00406     ushort  *EndCount;          // End characterCode for each segment,last =0xFFFF.
00407     ushort  *StartCount;        // Start character code for each segment.
00408     short   *IdDelta;           // Delta for all character codes in segment.
00409     ushort  *IdRangeOffset;     // Offsets into glyphIdArray or 0
00410                                 // the GlyphIdArray is appended to the
00411                                 // end of the IdRangeOffset array
00412 
00413 public:
00414     TtfCMapSegDelta();
00415     ~TtfCMapSegDelta();
00416 
00417     int operator[](int i);
00418     bool Read(GFile &F);
00419     bool Write(GFile &F);
00420     void Dump();
00421 };
00422 
00423 class LgiClass TtfCMap : public TtfObj {
00424 
00425     TtfMap *Fravorite;
00426 
00427 public:
00428     ushort  Version;
00429     ushort  Tables;
00430     TtfCMapTable *Table;
00431 
00432     TtfCMap();
00433     ~TtfCMap();
00434     int operator[](int i) { return (Fravorite) ? (*Fravorite)[i] : 0; }
00435     bool Read(GFile &F);
00436     bool Write(GFile &F);
00437     void Dump();
00438 };
00439 
00440 class LgiClass TtfRaster : public TtfObj {
00441 
00442     friend class GSurface;
00443 
00444     int XPixelsPerEm;
00445     int YPixelsPerEm;
00446     int Glyphs;
00447 
00448 public:
00449     int *BaseLine;          // pixels down to baseline in bitmap
00450     GRect *pSource;     // where glyph is stored in the bitmap
00451     GSurface *pDC;      // the bitmap
00452 
00453     TtfRaster();
00454     ~TtfRaster();
00455 
00456     double GetXPixelsPerEm() { return XPixelsPerEm; }
00457     double GetYPixelsPerEm() { return YPixelsPerEm; }
00458     bool Rasterize(double xPPEm, double yPPEm, int OverSample);
00459     int DrawChar(GSurface *pDC, int x, int y, int Char);
00460 };
00461 
00462 class LgiClass GdcTtf : public GTypeFace {
00463 
00464     friend class TtfObj;
00465 
00466 protected:
00467     int Tables;
00468     TtfTable *TableList;
00469     TtfTable *FindTag(char *t);
00470     TtfTable *SeekTag(char *t, GFile *F);
00471 
00472     TtfHeader Header;
00473     TtfMaxProfile Profile;
00474     TtfLocation Location;
00475     TtfGlyph **Glyph;
00476     TtfCMap Map;
00477 
00478     int Rasters;
00479     TtfRaster **Raster;
00480     TtfRaster *FindRaster(int Point, int XDpi = 96, int YDpi = -1);
00481 
00482 public:
00483     GdcTtf();
00484     virtual ~GdcTtf();
00485 
00486     virtual bool Load(GFile &F);
00487     virtual bool Save(GFile &F);
00488     virtual bool Rasterize( int Point,
00489                             int StyleFlags,
00490                             int OverSample = 2,
00491                             int XDpi = 96,
00492                             int YDpi = -1);
00493 
00494     void Test(GSurface *pDC);
00495     virtual void Size(int *x, int *y, char *Str, int Len = -1, int Flags = 0);
00496     int X(char *Str, int Len = -1, int Flags = 0);
00497     int Y(char *Str, int Len = -1, int Flags = 0);
00498 
00499     // Text drawing functions
00500     virtual bool SelectPoint(int Pt) { return FALSE; }
00501     virtual void Text(GSurface *pDC, int x, int y, char *Str, int Len = -1);
00502 };
00503 
00504 #define LFONT_LIGHT                 FW_LIGHT
00505 #define LFONT_NORMAL                FW_NORMAL
00506 #define LFONT_BOLD                  FW_BOLD
00507 
00508 class LgiClass GFont : public GdcTtf {
00509 
00510     HFONT   hFont;
00511     float   *Widths;
00512 
00513     void SetWidths();
00514 
00515 public:
00516     GFont();
00517     ~GFont();
00518 
00519     HFONT Handle() { return hFont; }
00520 
00521     bool Load(GFile &F) { return TRUE; }
00522     bool Save(GFile &F) { return FALSE; }
00523 
00524     bool Create(char *Face,
00525                 int Height,
00526                 int Width = 0,
00527                 int Weight = LFONT_NORMAL,
00528                 uint32 Italic = false,
00529                 uint32 Underline = false,
00530                 uint32 StrikeOut = false,
00531                 uint32 CharSet = ANSI_CHARSET,
00532                 int Escapement = 0,
00533                 int Orientation = 0,
00534                 uint32 OutputPrecision = OUT_DEFAULT_PRECIS,
00535                 uint32 ClipPrecision = CLIP_DEFAULT_PRECIS,
00536                 uint32 Quality = ANTIALIASED_QUALITY,
00537                 uint32 PitchAndFamily = DEFAULT_PITCH);
00538 
00539     bool CreateFont(LOGFONT *LogFont);
00540 
00541     void Text(  GSurface *pDC,
00542                 int x, int y,
00543                 char *Str,
00544                 int Len = -1,
00545                 GRect *r = NULL); // ASCII version
00546     void Size(int *x, int *y, char *Str, int Len = -1, int Flags = 0);
00547     int CharAt(int x, char *Str, int Len = -1);
00548 };
00549 
00550 
00551 

Generated on Wed Oct 26 14:46:52 2005 for Lgi by  doxygen 1.4.1