📄 ttf.txt
字号:
//Ttf.h
class TtfTable;
class GdcTtf;
class LgiClass GdcFontMetrics {
public:
long tmHeight;
long tmAscent;
long tmDescent;
long tmInternalLeading;
long tmExternalLeading;
long tmAveCharWidth;
long tmMaxCharWidth;
long tmWeight;
long tmOverhang;
long tmDigitizedAspectX;
long tmDigitizedAspectY;
char tmFirstChar;
char tmLastChar;
char tmDefaultChar;
char tmBreakChar;
char tmItalic;
char tmUnderlined;
char tmStruckOut;
char tmPitchAndFamily;
char tmCharSet;
};
class LgiClass GTypeFace {
protected:
uint Flags; // FNT_xxx flags
uint Height;
uint Width;
uint Escapement;
uint Orientation;
uint Weight;
uchar CharSet;
uchar OutPrecision;
uchar ClipPrecision;
uchar Quality;
uchar PitchAndFamily;
char FaceName[33];
// Output
COLOUR ForeCol;
COLOUR BackCol;
bool Trans;
int TabSize;
public:
GTypeFace()
{
ForeCol = 0;
BackCol = 0xFFFFFF;
Trans = FALSE;
TabSize = 0;
}
virtual ~GTypeFace() {}
virtual void Colour(COLOUR Fore, COLOUR Back = 0xFFFFFFFF) { ForeCol = Fore; BackCol = Back; }
void Fore(COLOUR f) { ForeCol = f; }
COLOUR Fore() { return ForeCol; }
void Back(COLOUR b) { BackCol = b; }
COLOUR Back() { return BackCol; }
void Transparent(bool t) { Trans = t; }
void SetTabs(int tabsize)
{
TabSize = tabsize;
}
virtual bool Load(GFile &F) { return FALSE; }
virtual bool Save(GFile &F) { return FALSE; }
};
typedef unsigned long TTF_FIXED;
typedef signed short TTF_FWORD;
typedef unsigned short TTF_UFWORD;
typedef signed short TTF_F2DOT14;
class LgiClass TtfFileHeader {
public:
TTF_FIXED Version; // 0x00010000 for version 1.0.
ushort NumTables; // Number of tables.
ushort SearchRange; // (Maximum power of 2 £ numTables) x 16.
ushort EntrySelector; // Log2(maximum power of 2 £ numTables).
ushort RangeShift; // NumTables x 16-searchRange.
bool Read(GFile &F);
bool Write(GFile &F);
void Dump();
};
class LgiClass TtfTable {
public:
char Tag[4]; // 4-byte identifier.
ulong CheckSum; // CheckSum for this table.
ulong Offset; // Offset from beginning of TrueType font file.
ulong Length; // Length of this table.
void *Table;
virtual bool Read(GFile &F);
virtual bool Write(GFile &F);
virtual void Dump();
};
class LgiClass TtfObj {
public:
GdcTtf *Parent;
TtfObj() { Parent = 0; }
void *FindTag(char *t);
};
class LgiClass TtfHeader : public TtfObj {
public:
ulong Version; // 0x00010000 for version 1.0.
ulong Revision; // Set by font manufacturer.
ulong CheckSumAdjustment; // To compute: set it to 0, sum the entire font as ULONG, then store 0xB1B0AFBA - sum.
ulong MagicNumber; // Set to 0x5F0F3CF5.
ushort Flags; // 0x0001 - baseline for font at y=0
// 0x0002 - left sidebearing at x=0
// 0x0004 - instructions may depend on point size
// 0x0008 - force ppem to integer values for all internal scaler math, may use fractional ppem sizes if this bit is clear
// 0x0010 - instructions may alter advance width (the advance widths might not scale linearly)
// Note: All other bits must be zero.
ushort UnitsPerEm; // Valid range is from 16 to 16384
quad InternationalDate; // (8-byte field).
quad Modified; // International date (8-byte field).
TTF_FWORD xMin; // For all glyph bounding boxes.
TTF_FWORD yMin; // For all glyph bounding boxes.
TTF_FWORD xMax; // For all glyph bounding boxes.
TTF_FWORD yMax; // For all glyph bounding boxes.
ushort MacStyle; // 0x0001 - bold (if set to 1)
// 0x0002 - italic (if set to 1)
// Bits 2-15 reserved (set to 0).
ushort LowestRecPPEM; // Smallest readable size in pixels.
short 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.
short IndexToLocFormat; // 0 for short offsets
// 1 for long.
short GlyphDataFormat; // 0 for current format.
bool Read(GFile &F);
bool Write(GFile &F);
void Dump();
};
class LgiClass TtfMaxProfile : public TtfObj {
public:
ulong Version; // 0x00010000 for version 1.0.
ushort NumGlyphs; // The number of glyphs in the font.
ushort MaxPoints; // Maximum points in a non-composite glyph.
ushort MaxContours; // Maximum contours in a non-composite glyph.
ushort MaxCompositePoints; // Maximum points in a composite glyph.
ushort MaxCompositeContours; // Maximum contours in a composite glyph.
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.
ushort MaxTwilightPoints; // Maximum points used in Z0.
ushort MaxStorage; // Number of Storage Area locations.
ushort MaxFunctionDefs; // Number of FDEFs.
ushort MaxInstructionDefs; // Number of IDEFs.
ushort MaxStackElements; // Maximum stack depth .
ushort MaxSizeOfInstructions; // Maximum byte count for glyph instructions.
ushort MaxComponentElements; // Maximum number of components referenced at "top level" for any composite glyph.
ushort MaxComponentDepth; // Maximum levels of recursion; 1 for simple components.
bool Read(GFile &F);
bool Write(GFile &F);
void Dump();
};
class LgiClass TtfLocation : public TtfObj {
int Entries;
int Type;
void *Data;
public:
TtfLocation();
virtual ~TtfLocation();
int operator [](int i);
bool Read(GFile &F);
bool Write(GFile &F);
void Dump();
};
class LgiClass DataList {
int Alloc;
public:
int Size;
double *Data;
DataList()
{
Size = 0;
Alloc = 0;
Data = 0;
}
virtual ~DataList()
{
DeleteArray(Data);
}
void AddValue(double n)
{
if (Size >= Alloc)
{
int NewAlloc = (Size + 16) & (~0xF);
double *Temp = NEW(double[NewAlloc]);
if (Temp)
{
memcpy(Temp, Data, sizeof(double)*Size);
DeleteArray(Data);
Data = Temp;
Alloc = NewAlloc;
}
else
{
return;
}
}
if (Size > 0)
{
for (int i=0; i<Size; i++)
{
if (Data[i] > n)
{
memmove(Data + i + 1, Data + i, sizeof(double)*(Size-i));
Data[i] = n;
Size++;
return;
}
}
Data[Size] = n;
}
else
{
Data[0] = n;
}
Size++;
}
};
class LgiClass TtfContour {
class CPt {
public:
double x, y;
};
// From glyph
int *x, *y;
uchar *Flags;
int XOff, YOff;
// Out stuff
int Points;
int Alloc;
CPt *Point;
bool SetPoints(int p);
void Bezier(CPt *p, double Threshold = 0.5);
public:
TtfContour();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -