// TTF database.
//
-// These really shouldn't be included here, but are for now...
-//#include <string.h>
-////#include <afxwin.h> // This is needed only for things like BOOL, etc.
-//#include <fstream.h>
-//#include <stdlib.h>
-//#include <malloc.h> // Both for malloc, free, _msize, realloc
-
#ifndef __TTF_H__
#define __TTF_H__
+#include <stdint.h>
#include "list.h"
-#include "types.h"
#include "glyphpoints.h"
#define MAXGLYPHS 4096 // Number of glyphs in object
#define MAXPOINTS 2000 // Number of points in a glyph
-#define MAXHINTS 2000 // Number of hint uint8s in glyph
+#define MAXHINTS 2000 // Number of hint uint8_ts in glyph
//
// "head" struct
//
struct Head
{
- uint32 version; // Fixed - Table version number (0x00010000 for version 1.0.)
- uint32 fontRevision; // Fixed - fontRevision (Set by font manufacturer.)
- uint32 checkSumAdjustment; // To compute: Set it to 0, sum the entire font
+ uint32_t version; // Fixed - Table version number (0x00010000 for version 1.0.)
+ uint32_t fontRevision; // Fixed - fontRevision (Set by font manufacturer.)
+ uint32_t checkSumAdjustment; // To compute: Set it to 0, sum the entire font
// as ULONG, then store 0xB1B0AFBA - sum.
- uint32 magicNumber; // Set to 0x5F0F3CF5.
- uint16 flags; /* Bit 0 - baseline for font at y=0;
+ uint32_t magicNumber; // Set to 0x5F0F3CF5.
+ uint16_t flags; /* Bit 0 - baseline for font at y=0;
Bit 1 - left sidebearing at x=0;
Bit 2 - instructions may depend on point size;
Bit 3 - force ppem to integer values for all
Bit 4 - instructions may alter advance width
(the advance widths might not scale linearly);
Note: All other bits must be zero.*/
- uint16 unitsPerEm; // Valid range is from 16 to 16384
- uint32 /*longDateTime*/ createdh, createdl; // International date (8-uint8 field).
- uint32 /*longDateTime*/ modifiedh, modifiedl; // International date (8-uint8 field).
- uint16 xMin; // For all glyph bounding boxes.
- uint16 yMin; // For all glyph bounding boxes.
- uint16 xMax; // For all glyph bounding boxes.
- uint16 yMax; // For all glyph bounding boxes.
- uint16 macStyle; /* Bit 0 bold (if set to 1); Bit 1 italic (if set to 1)
+ uint16_t unitsPerEm; // Valid range is from 16 to 16384
+ uint32_t /*longDateTime*/ createdh, createdl; // International date (8-uint8_t field).
+ uint32_t /*longDateTime*/ modifiedh, modifiedl; // International date (8-uint8_t field).
+ uint16_t xMin; // For all glyph bounding boxes.
+ uint16_t yMin; // For all glyph bounding boxes.
+ uint16_t xMax; // For all glyph bounding boxes.
+ uint16_t yMax; // For all glyph bounding boxes.
+ uint16_t macStyle; /* Bit 0 bold (if set to 1); Bit 1 italic (if set to 1)
Bits 2-15 reserved (set to 0).*/
- uint16 lowestRecPPEM; // Smallest readable size in pixels.
- int16 fontDirectionHint; /* 0 Fully mixed directional glyphs;
+ uint16_t lowestRecPPEM; // Smallest readable size in pixels.
+ int16_t fontDirectionHint; /* 0 Fully mixed directional glyphs;
1 Only strongly left to right;
2 Like 1 but also contains neutrals;
-1 Only strongly right to left;
-2 Like -1 but also contains neutrals.*/
- int16 indexToLocFormat; // 0 for short offsets, 1 for long.
- int16 glyphDataFormat; // 0 for current format.
+ int16_t indexToLocFormat; // 0 for short offsets, 1 for long.
+ int16_t glyphDataFormat; // 0 for current format.
};
//
//
struct Maxp
{
- uint32 version; // Table version number 0x00010000 for version 1.0.
- uint16 numGlyphs; // The number of glyphs in the font.
- uint16 maxPoints; // Maximum points in a non-composite glyph.
- uint16 maxContours; // Maximum contours in a non-composite glyph.
- uint16 maxCompositePoints; // Maximum points in a composite glyph.
- uint16 maxCompositeContours; // Maximum contours in a composite glyph.
- uint16 maxZones; // 1 if instructions do not use the twilight
+ uint32_t version; // Table version number 0x00010000 for version 1.0.
+ uint16_t numGlyphs; // The number of glyphs in the font.
+ uint16_t maxPoints; // Maximum points in a non-composite glyph.
+ uint16_t maxContours; // Maximum contours in a non-composite glyph.
+ uint16_t maxCompositePoints; // Maximum points in a composite glyph.
+ uint16_t maxCompositeContours; // Maximum contours in a composite glyph.
+ uint16_t 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.
- uint16 maxTwilightPoints; // Maximum points used in Z0.
- uint16 maxStorage; // Number of Storage Area locations.
- uint16 maxFunctionDefs; // Number of FDEFs.
- uint16 maxInstructionDefs; // Number of IDEFs.
- uint16 maxStackElements; // Maximum stack depth.
- uint16 maxSizeOfInstructions; // Maximum uint8 count for glyph instructions.
- uint16 maxComponentElements; // Maximum number of components referenced at
+ uint16_t maxTwilightPoints; // Maximum points used in Z0.
+ uint16_t maxStorage; // Number of Storage Area locations.
+ uint16_t maxFunctionDefs; // Number of FDEFs.
+ uint16_t maxInstructionDefs; // Number of IDEFs.
+ uint16_t maxStackElements; // Maximum stack depth.
+ uint16_t maxSizeOfInstructions; // Maximum uint8_t count for glyph instructions.
+ uint16_t maxComponentElements; // Maximum number of components referenced at
// "top level" for any composite glyph.
- uint16 maxComponentDepth; // Maximum levels of recursion; 1 for simple components.
+ uint16_t maxComponentDepth; // Maximum levels of recursion; 1 for simple components.
};
//
Type Description
USHORT Platform ID.
USHORT Platform-specific encoding ID.
-ULONG uint8 offset from beginning of table to the subtable for this encoding.
+ULONG uint8_t offset from beginning of table to the subtable for this encoding.
USHORT format Format number is set to 4.
-USHORT length Length in uint8s.
+USHORT length Length in uint8_ts.
USHORT version Version number (starts at 0).
USHORT segCountX2 2 x segCount.
USHORT searchRange 2 x (2**floor(log2(segCount)))
struct Box
{
- int16 llx, lly, urx, ury;
+ int16_t llx, lly, urx, ury;
// Default constructor
- Box(int16 lx = 0, int16 ly = 0, int16 rx = 0, int16 ry = 0):
+ Box(int16_t lx = 0, int16_t ly = 0, int16_t rx = 0, int16_t ry = 0):
llx(lx), lly(ly), urx(rx), ury(ry) {}
};
struct NameRec
{
- uint16 platformID, platformSpecID, languageID, nameID, length;
- uint8 * str;
+ uint16_t platformID, platformSpecID, languageID, nameID, length;
+ uint8_t * str;
NameRec(): str(NULL) {}
languageID = c.languageID;
nameID = c.nameID;
length = c.length;
-//Fix this str = (uint8 *)strdup((char *)c.str);
+//Fix this str = (uint8_t *)strdup((char *)c.str);
}
};
struct Composite
{
- uint16 flags, glyphIndex;
- int16 arg1, arg2;
+ uint16_t flags, glyphIndex;
+ int16_t arg1, arg2;
float xScale, yScale, scale01, scale10;
- Composite(uint16 fl = 0, uint16 gl = 0, int16 a1 = 0, int16 a2 = 0,
+ Composite(uint16_t fl = 0, uint16_t gl = 0, int16_t a1 = 0, int16_t a2 = 0,
float xs = 1.0f, float ys = 1.0f, float s01 = 1.0f, float s10 = 1.0f):
flags(fl), glyphIndex(gl), arg1(a1), arg2(a2), xScale(xs), yScale(ys),
scale01(s01), scale10(s10) {}
class TTF
{
private:
- bool EncodeGlyph(uint16);
- bool DecodeGlyph(uint16);
+ bool EncodeGlyph(uint16_t);
+ bool DecodeGlyph(uint16_t);
bool ExtractTables(void);
bool BuildTables(void);
bool Load(const char *); // Load font database
bool Save(const char *); // Save font database
void ClearTables(void); // Deallocate memory...
- bool SetGlyph(uint16 glyphnum); // Set internal pointer/encode/decode
- bool AddGlyph(uint16 glyphnum);
- bool DeleteGlyph(uint16 glyphnum);
+ bool SetGlyph(uint16_t glyphnum); // Set internal pointer/encode/decode
+ bool AddGlyph(uint16_t glyphnum);
+ bool DeleteGlyph(uint16_t glyphnum);
Box GetBoundingBox(void);
- GlyphPt GetPoint(uint16 pointno);
- uint16 GetNumberOfPolys(void);
- uint16 GetPolyEnd(uint16 polynum);
- int GetPointX(uint16 pointno);
- int GetPointY(uint16 pointno);
- bool GetOnCurve(uint16 pointno);
- bool SetOnCurve(uint16 pointno, bool state);
- bool MovePoint(uint16 pointno, int x, int y);
- bool MovePoint(uint16 pointno, GlyphPt p);
- bool AddPoint(uint16 pointno, int x, int y, bool state);
- bool DeletePoint(uint16 pointno);
+ GlyphPt GetPoint(uint16_t pointno);
+ uint16_t GetNumberOfPolys(void);
+ uint16_t GetPolyEnd(uint16_t polynum);
+ int GetPointX(uint16_t pointno);
+ int GetPointY(uint16_t pointno);
+ bool GetOnCurve(uint16_t pointno);
+ bool SetOnCurve(uint16_t pointno, bool state);
+ bool MovePoint(uint16_t pointno, int x, int y);
+ bool MovePoint(uint16_t pointno, GlyphPt p);
+ bool AddPoint(uint16_t pointno, int x, int y, bool state);
+ bool DeletePoint(uint16_t pointno);
bool IsCompositeGlyph(void);
- GlyphPoints GetGlyphPoints(uint16);
- GlyphPoints GetAllCompositePoints(uint16);
- void GetCharName(int, uint8 *);
+ GlyphPoints GetGlyphPoints(uint16_t);
+ GlyphPoints GetAllCompositePoints(uint16_t);
+ void GetCharName(int, uint8_t *);
private:
bool isDirty; // Has glyph been modified?
bool isCompositeGlyph; // Is it a composite? (need structs to store composite info...)
- uint16 currentGlyph; // The glyph currently decoded
- uint16 numberOfPoints;
+ uint16_t currentGlyph; // The glyph currently decoded
+ uint16_t numberOfPoints;
int gx[MAXPOINTS]; // Internal point arrays...
int gy[MAXPOINTS]; // These could be dynamically allocated in the
bool onCurve[MAXPOINTS]; // constructor, with default values being set
- uint16 numberOfHints;
- uint8 hint[MAXHINTS]; // Hints storage
- uint16 numberOfPolys; // Number of polygons in glyph
- uint16 poly[200]; // End points of polygons
- int16 llx, lly, urx, ury; // Lower left/Upper right X/Y
+ uint16_t numberOfHints;
+ uint8_t hint[MAXHINTS]; // Hints storage
+ uint16_t numberOfPolys; // Number of polygons in glyph
+ uint16_t poly[200]; // End points of polygons
+ int16_t llx, lly, urx, ury; // Lower left/Upper right X/Y
// public://remove after debugging...
- uint8 * glyph[MAXGLYPHS]; // Placeholders for glyphs
- uint32 glyphLen[MAXGLYPHS]; // Glyph lengths are stored since malloc() is sloppy
+ uint8_t * glyph[MAXGLYPHS]; // Placeholders for glyphs
+ uint32_t glyphLen[MAXGLYPHS]; // Glyph lengths are stored since malloc() is sloppy
Maxp myMaxp; // Internal placeholders for this shiat
Head myHead;
// public: //private: later...
List<Composite> compositeList; // Composite glyph list
- uint8 * EBDT, * EBLC, * EBSC, * LTSH, * OS_2, * PCLT, * VDMX, * cmap, * cvt, * fpgm,
+ uint8_t * EBDT, * EBLC, * EBSC, * LTSH, * OS_2, * PCLT, * VDMX, * cmap, * cvt, * fpgm,
* gasp, * glyf, * hdmx, * head, * hhea, * hmtx, * kern, * loca, * maxp, * name,
* post, * prep, * vhea, * vmtx;
- uint32 EBDT_len, EBLC_len, EBSC_len, LTSH_len, OS_2_len, PCLT_len, VDMX_len, cmap_len,
+ uint32_t EBDT_len, EBLC_len, EBSC_len, LTSH_len, OS_2_len, PCLT_len, VDMX_len, cmap_len,
cvt_len, fpgm_len, gasp_len, glyf_len, hdmx_len, head_len, hhea_len, hmtx_len,
kern_len, loca_len, maxp_len, name_len, post_len, prep_len, vhea_len, vmtx_len;
- uint8 * * parray[24]; // Pointer array
- uint32 * larray[24]; // Length array
+ uint8_t * * parray[24]; // Pointer array
+ uint32_t * larray[24]; // Length array
bool loaded; // Font loaded/init'ed?
};