Modified Get{BYTE,WORD,DWORD}() to return the respective type
Having e.g. GetWORD() return a WORD rather than int eliminates the need for a cast when assigning to WORD variables. We use casts only when assigning to a different (but same-sized) type. Also, check for EOF explicitly when calling fgetc().pull/3/head
parent
a72575d04e
commit
dcc963aa4b
|
@ -373,9 +373,9 @@ public:
|
||||||
Vector origin, u, v;
|
Vector origin, u, v;
|
||||||
|
|
||||||
int Getc(void);
|
int Getc(void);
|
||||||
int GetBYTE(void);
|
BYTE GetBYTE(void);
|
||||||
int GetWORD(void);
|
WORD GetWORD(void);
|
||||||
int GetDWORD(void);
|
DWORD GetDWORD(void);
|
||||||
|
|
||||||
void LoadGlyph(int index);
|
void LoadGlyph(int index);
|
||||||
bool LoadFontFromFile(bool nameOnly);
|
bool LoadFontFromFile(bool nameOnly);
|
||||||
|
|
44
ttf.cpp
44
ttf.cpp
|
@ -59,7 +59,7 @@ void TtfFontList::PlotString(char *font, char *str, double spacing,
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
int TtfFont::Getc(void) {
|
int TtfFont::Getc(void) {
|
||||||
int c = fgetc(fh);
|
int c = fgetc(fh);
|
||||||
if(c < 0) {
|
if(c == EOF) {
|
||||||
throw "EOF";
|
throw "EOF";
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
|
@ -68,22 +68,22 @@ int TtfFont::Getc(void) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Helpers to get 1, 2, or 4 bytes from the .ttf file. Big endian.
|
// Helpers to get 1, 2, or 4 bytes from the .ttf file. Big endian.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
int TtfFont::GetBYTE(void) {
|
BYTE TtfFont::GetBYTE(void) {
|
||||||
return Getc();
|
return (BYTE)Getc();
|
||||||
}
|
}
|
||||||
int TtfFont::GetWORD(void) {
|
WORD TtfFont::GetWORD(void) {
|
||||||
BYTE b0, b1;
|
BYTE b0, b1;
|
||||||
b1 = Getc();
|
b1 = (BYTE)Getc();
|
||||||
b0 = Getc();
|
b0 = (BYTE)Getc();
|
||||||
|
|
||||||
return (b1 << 8) | b0;
|
return (b1 << 8) | b0;
|
||||||
}
|
}
|
||||||
int TtfFont::GetDWORD(void) {
|
DWORD TtfFont::GetDWORD(void) {
|
||||||
BYTE b0, b1, b2, b3;
|
BYTE b0, b1, b2, b3;
|
||||||
b3 = Getc();
|
b3 = (BYTE)Getc();
|
||||||
b2 = Getc();
|
b2 = (BYTE)Getc();
|
||||||
b1 = Getc();
|
b1 = (BYTE)Getc();
|
||||||
b0 = Getc();
|
b0 = (BYTE)Getc();
|
||||||
|
|
||||||
return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
|
return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
|
||||||
}
|
}
|
||||||
|
@ -98,11 +98,11 @@ void TtfFont::LoadGlyph(int index) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
SWORD contours = GetWORD();
|
SWORD contours = (SWORD)GetWORD();
|
||||||
SWORD xMin = GetWORD();
|
SWORD xMin = (SWORD)GetWORD();
|
||||||
SWORD yMin = GetWORD();
|
SWORD yMin = (SWORD)GetWORD();
|
||||||
SWORD xMax = GetWORD();
|
SWORD xMax = (SWORD)GetWORD();
|
||||||
SWORD yMax = GetWORD();
|
SWORD yMax = (SWORD)GetWORD();
|
||||||
|
|
||||||
if(useGlyph['A'] == index) {
|
if(useGlyph['A'] == index) {
|
||||||
scale = (1024*1024) / yMax;
|
scale = (1024*1024) / yMax;
|
||||||
|
@ -167,7 +167,7 @@ void TtfFont::LoadGlyph(int index) {
|
||||||
if(flags[i] & FLAG_X_IS_SAME) {
|
if(flags[i] & FLAG_X_IS_SAME) {
|
||||||
// no change
|
// no change
|
||||||
} else {
|
} else {
|
||||||
SWORD d = GetWORD();
|
SWORD d = (SWORD)GetWORD();
|
||||||
xa += d;
|
xa += d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ void TtfFont::LoadGlyph(int index) {
|
||||||
if(flags[i] & FLAG_Y_IS_SAME) {
|
if(flags[i] & FLAG_Y_IS_SAME) {
|
||||||
// no change
|
// no change
|
||||||
} else {
|
} else {
|
||||||
SWORD d = GetWORD();
|
SWORD d = (SWORD)GetWORD();
|
||||||
ya += d;
|
ya += d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,10 +267,10 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) {
|
||||||
|
|
||||||
for(i = 0; i < numTables; i++) {
|
for(i = 0; i < numTables; i++) {
|
||||||
char tag[5] = "xxxx";
|
char tag[5] = "xxxx";
|
||||||
tag[0] = GetBYTE();
|
tag[0] = (char)GetBYTE();
|
||||||
tag[1] = GetBYTE();
|
tag[1] = (char)GetBYTE();
|
||||||
tag[2] = GetBYTE();
|
tag[2] = (char)GetBYTE();
|
||||||
tag[3] = GetBYTE();
|
tag[3] = (char)GetBYTE();
|
||||||
DWORD checksum = GetDWORD();
|
DWORD checksum = GetDWORD();
|
||||||
DWORD offset = GetDWORD();
|
DWORD offset = GetDWORD();
|
||||||
DWORD length = GetDWORD();
|
DWORD length = GetDWORD();
|
||||||
|
|
Loading…
Reference in New Issue