X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fttf.cpp;h=799f0321ffc288aad01c42836e19b991d961d0c7;hb=0c01fa32c7e0629ae61992e0419f03724fc18487;hp=ce312a8d6dfc2ddd70265dfc0f9265f4a13028ae;hpb=3ef71393f70213eb53db552605ae3c93f1303ee9;p=ttedit diff --git a/src/ttf.cpp b/src/ttf.cpp index ce312a8..799f032 100755 --- a/src/ttf.cpp +++ b/src/ttf.cpp @@ -20,7 +20,7 @@ // - Eliminate ALL references to BYTE, WORD, SBYTE, SWORD, etc. // -#include // For file handling, etc. // +#include // For file handling, etc. #include #include #include "charnames.h" @@ -35,7 +35,7 @@ #define NUMTABS 24 // Number of distinct tables -/*void fskip(HANDLE file, uint32 bytesToSkip) +/*void fskip(HANDLE file, uint32_t bytesToSkip) { SetFilePointer(file, (LONG)bytesToSkip, NULL, FILE_CURRENT); }*/ @@ -43,9 +43,9 @@ // // Get a BYTE from the current file... // -uint8 ReadByte(FILE * file) +uint8_t ReadByte(FILE * file) { - return (uint8)fgetc(file); + return (uint8_t)fgetc(file); } // The following routines get and put WORDs and DWORDs in little endian @@ -55,10 +55,10 @@ uint8 ReadByte(FILE * file) // // Get a WORD from the current file... // -uint16 ReadWord(FILE * file) +uint16_t ReadWord(FILE * file) { - uint16 word = (uint16)fgetc(file) << 8; - word |= (uint16)fgetc(file); + uint16_t word = (uint16_t)fgetc(file) << 8; + word |= (uint16_t)fgetc(file); return word; } @@ -66,14 +66,14 @@ uint16 ReadWord(FILE * file) // // Get a double WORD from the current file... // -uint32 ReadDWord(FILE * file) +uint32_t ReadDWord(FILE * file) { - uint32 dword = 0; + uint32_t dword = 0; for(int i=0; i<4; i++) { dword <<= 8; - dword |= (uint8)fgetc(file); + dword |= (uint8_t)fgetc(file); } return dword; @@ -82,7 +82,7 @@ uint32 ReadDWord(FILE * file) // // Write a WORD to the current file... // -void WriteWord(FILE * file, uint16 word) +void WriteWord(FILE * file, uint16_t word) { fputc(word >> 8, file); // Hi byte fputc(word & 0xFF, file); // Lo byte @@ -91,7 +91,7 @@ void WriteWord(FILE * file, uint16 word) // // Write a double WORD to the current file... // -void WriteDWord(FILE * file, uint32 dword) +void WriteDWord(FILE * file, uint32_t dword) { for(int i=0; i<4; i++) { @@ -107,7 +107,7 @@ void WriteDWord(FILE * file, uint32 dword) // // Return a BYTE from a BYTE based table // -uint8 GetByte(uint8 * table, uint32 &ptr) +uint8_t GetByte(uint8_t * table, uint32_t &ptr) { return table[ptr++]; } @@ -115,25 +115,25 @@ uint8 GetByte(uint8 * table, uint32 &ptr) // // Return a WORD from a BYTE based table // -uint16 GetWord(uint8 * table, uint32 &ptr) +uint16_t GetWord(uint8_t * table, uint32_t &ptr) { - uint16 hi = table[ptr++]; - uint16 lo = table[ptr++]; + uint16_t hi = table[ptr++]; + uint16_t lo = table[ptr++]; - return (uint16)((hi<<8) | lo); + return (uint16_t)((hi<<8) | lo); } // // Return a double WORD from a BYTE based table // -uint32 GetDWord(uint8 * table, uint32 &ptr) +uint32_t GetDWord(uint8_t * table, uint32_t &ptr) { - uint32 hi1 = table[ptr++]; - uint32 lo1 = table[ptr++]; - uint32 hi2 = table[ptr++]; - uint32 lo2 = table[ptr++]; + uint32_t hi1 = table[ptr++]; + uint32_t lo1 = table[ptr++]; + uint32_t hi2 = table[ptr++]; + uint32_t lo2 = table[ptr++]; - return (uint32)((hi1 << 24) | (lo1 << 16) | (hi2 << 8) | lo2); + return (uint32_t)((hi1 << 24) | (lo1 << 16) | (hi2 << 8) | lo2); } ///////////////////////////////////////////////////////////////////////////// @@ -143,7 +143,7 @@ uint32 GetDWord(uint8 * table, uint32 &ptr) // // Store a BYTE in a BYTE based table // -void SetByte(uint8 * table, uint32 &ptr, uint8 data) +void SetByte(uint8_t * table, uint32_t &ptr, uint8_t data) { table[ptr++] = data; } @@ -151,7 +151,7 @@ void SetByte(uint8 * table, uint32 &ptr, uint8 data) // // Store a WORD in a BYTE based table // -void SetWord(uint8 * table, uint32 &ptr, uint16 data) +void SetWord(uint8_t * table, uint32_t &ptr, uint16_t data) { table[ptr++] = data>>8; table[ptr++] = data&0xFF; } @@ -159,16 +159,16 @@ void SetWord(uint8 * table, uint32 &ptr, uint16 data) // // Store a DWORD in a BYTE based table // -void SetDWord(uint8 * table, uint32 &ptr, uint32 data) +void SetDWord(uint8_t * table, uint32_t &ptr, uint32_t data) { - table[ptr++] = (uint8)(data >> 24); table[ptr++] = (uint8)(data >> 16); - table[ptr++] = (uint8)(data >> 8); table[ptr++] = (uint8)(data & 0xFF); + table[ptr++] = (uint8_t)(data >> 24); table[ptr++] = (uint8_t)(data >> 16); + table[ptr++] = (uint8_t)(data >> 8); table[ptr++] = (uint8_t)(data & 0xFF); } ///////////////////////////////////////////////////////////////////////////// // Fixed point to float (& vice versa) conversions ///////////////////////////////////////////////////////////////////////////// -float FixedToFloat(int16 fixed) +float FixedToFloat(int16_t fixed) { return (float)fixed / 16384.0f; } @@ -201,10 +201,10 @@ TTF::TTF(void) larray[18] = &maxp_len; larray[19] = &name_len; larray[20] = &post_len; larray[21] = &prep_len; larray[22] = &vhea_len; larray[23] = &vmtx_len; - for(uint32 i=0; i 255) || (curx < -255)) // I.e., it's 2 uint8 value + if ((curx > 255) || (curx < -255)) // I.e., it's 2 uint8_t value SetWord(xbuf, xp, curx); else { @@ -473,7 +473,7 @@ bool TTF::EncodeGlyph(uint16 glyphnum) if (cury) { - if ((cury > 255) || (cury < -255)) // I.e., it's 2 uint8 value + if ((cury > 255) || (cury < -255)) // I.e., it's 2 uint8_t value SetWord(ybuf, yp, cury); else { @@ -502,7 +502,7 @@ bool TTF::EncodeGlyph(uint16 glyphnum) { if (fbuf[i] == fbuf[i+1]) // { - uint8 count = 0; // Sentinel takes care of check for end of flags... + uint8_t count = 0; // Sentinel takes care of check for end of flags... while (fbuf[i] == fbuf[++i]) count++; // Count number of repeats i--; fbuf[fp++] = fbuf[i] | 0x08; // Set repeat flag @@ -514,35 +514,35 @@ bool TTF::EncodeGlyph(uint16 glyphnum) fp = numberOfPoints; // Find length of glyph and reallocate space if necessary - uint32 newLength = 12 + numberOfPolys*2 + numberOfHints + fp + xp + yp; + uint32_t newLength = 12 + numberOfPolys*2 + numberOfHints + fp + xp + yp; if (newLength & 0x03) newLength += (4 - newLength & 0x03); if (glyphLen[glyphnum] != newLength) { - glyph[glyphnum] = (uint8 *)realloc(glyph[glyphnum], newLength); + glyph[glyphnum] = (uint8_t *)realloc(glyph[glyphnum], newLength); glyphLen[glyphnum] = newLength; } // And finally, store it! - uint32 gp = 0; // Glyph pointer... + uint32_t gp = 0; // Glyph pointer... SetWord(glyph[glyphnum], gp, numberOfPolys); SetWord(glyph[glyphnum], gp, llx); SetWord(glyph[glyphnum], gp, lly); SetWord(glyph[glyphnum], gp, urx); SetWord(glyph[glyphnum], gp, ury); - for(uint32 i=0; i= myMaxp.numGlyphs) @@ -578,10 +578,10 @@ bool TTF::DecodeGlyph(uint16 glyphnum) isCompositeGlyph = false; // Default is no numberOfPolys = GetWord(glyph[glyphnum], dp); // # of polygons - llx = (int16)GetWord(glyph[glyphnum], dp); // Lower left X - lly = (int16)GetWord(glyph[glyphnum], dp); // Lower left Y - urx = (int16)GetWord(glyph[glyphnum], dp); // Upper right X - ury = (int16)GetWord(glyph[glyphnum], dp); // Upper right Y + llx = (int16_t)GetWord(glyph[glyphnum], dp); // Lower left X + lly = (int16_t)GetWord(glyph[glyphnum], dp); // Lower left Y + urx = (int16_t)GetWord(glyph[glyphnum], dp); // Upper right X + ury = (int16_t)GetWord(glyph[glyphnum], dp); // Upper right Y // Need to handle composite glyphs better here. The ways things // are set now is a recipe for disaster... @@ -600,19 +600,19 @@ bool TTF::DecodeGlyph(uint16 glyphnum) { cmpst.flags = GetWord(glyph[glyphnum], dp); cmpst.glyphIndex = GetWord(glyph[glyphnum], dp); - cmpst.arg1 = (cmpst.flags & 0x01 ? (int16)GetWord(glyph[glyphnum], dp) : (int8)GetByte(glyph[glyphnum], dp)); - cmpst.arg2 = (cmpst.flags & 0x01 ? (int16)GetWord(glyph[glyphnum], dp) : (int8)GetByte(glyph[glyphnum], dp)); + cmpst.arg1 = (cmpst.flags & 0x01 ? (int16_t)GetWord(glyph[glyphnum], dp) : (int8_t)GetByte(glyph[glyphnum], dp)); + cmpst.arg2 = (cmpst.flags & 0x01 ? (int16_t)GetWord(glyph[glyphnum], dp) : (int8_t)GetByte(glyph[glyphnum], dp)); if (cmpst.flags & 0x08) - cmpst.xScale = cmpst.yScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)); + cmpst.xScale = cmpst.yScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)); else if (cmpst.flags & 0x40) - cmpst.xScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.yScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)); + cmpst.xScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.yScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)); else if (cmpst.flags & 0x80) - cmpst.xScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.scale01 = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.scale10 = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.yScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)); + cmpst.xScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.scale01 = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.scale10 = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.yScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)); compositeList.AddAtRear(cmpst); } @@ -624,9 +624,9 @@ bool TTF::DecodeGlyph(uint16 glyphnum) //do { // USHORT flags; // USHORT glyphIndex; -// if ( flags & ARG_1_AND_2_ARE_uint16S) { -// (SHORT or Fuint16) argument1; -// (SHORT or Fuint16) argument2; +// if ( flags & ARG_1_AND_2_ARE_uint16_tS) { +// (SHORT or Fuint16_t) argument1; +// (SHORT or Fuint16_t) argument2; // } else { // USHORT arg1and2; /* (arg1 << 8) | arg2 */ // } @@ -644,11 +644,11 @@ bool TTF::DecodeGlyph(uint16 glyphnum) //} while ( flags & MORE_COMPONENTS ) //if (flags & WE_HAVE_INSTR){ // USHORT numInstr -// uint8 instr[numInstr] +// uint8_t instr[numInstr] // //Flags Bit Description -//ARG_1_AND_2_ARE_uint16S 0 If this is set, the arguments are uint16s; -// otherwise, they are uint8s. +//ARG_1_AND_2_ARE_uint16_tS 0 If this is set, the arguments are uint16_ts; +// otherwise, they are uint8_ts. //ARGS_ARE_XY_VALUES 1 If this is set, the arguments are xy values; // otherwise, they are points. //ROUND_XY_TO_GRID 2 For the xy values if the preceding is true. @@ -678,20 +678,20 @@ bool TTF::DecodeGlyph(uint16 glyphnum) // Decode the dots... - uint32 num_pts = poly[numberOfPolys-1] + 1; + uint32_t num_pts = poly[numberOfPolys-1] + 1; numberOfPoints = num_pts; // necessary?? - uint32 xptr, yptr; // pointers to beginning of coord data - uint32 numXs = 0; + uint32_t xptr, yptr; // pointers to beginning of coord data + uint32_t numXs = 0; int xx = 0, yy = 0, repeat; - uint32 numTokens = num_pts, k, numRep; + uint32_t numTokens = num_pts, k, numRep; // We make an educated guess that num_pts = num_tokens; but if there // is repeated data in the tokens, then we need to adjust the # of // tokens down appropriately. - for(uint32 i=0; i 257) { @@ -866,13 +866,13 @@ void TTF::GetCharName(int cNum, uint8 * buf) pTab = macStdNames; } - for(uint32 i=0; i= numberOfPolys) return 0; @@ -1148,7 +1148,7 @@ uint16 TTF::GetPolyEnd(uint16 polynum) return poly[polynum]; } -int TTF::GetPointX(uint16 pointno) +int TTF::GetPointX(uint16_t pointno) { if (pointno >= MAXPOINTS) return 0; @@ -1156,7 +1156,7 @@ int TTF::GetPointX(uint16 pointno) return gx[pointno]; } -int TTF::GetPointY(uint16 pointno) +int TTF::GetPointY(uint16_t pointno) { if (pointno >= MAXPOINTS) return 0; @@ -1164,7 +1164,7 @@ int TTF::GetPointY(uint16 pointno) return gy[pointno]; } -bool TTF::GetOnCurve(uint16 pointno) +bool TTF::GetOnCurve(uint16_t pointno) { if (pointno >= MAXPOINTS) return true; @@ -1172,7 +1172,7 @@ bool TTF::GetOnCurve(uint16 pointno) return onCurve[pointno]; } -bool TTF::SetOnCurve(uint16 pointno, bool state) +bool TTF::SetOnCurve(uint16_t pointno, bool state) { if (pointno >= numberOfPoints) return false; @@ -1183,7 +1183,7 @@ bool TTF::SetOnCurve(uint16 pointno, bool state) return true; } -bool TTF::MovePoint(uint16 pointno, int x, int y) +bool TTF::MovePoint(uint16_t pointno, int x, int y) { if (pointno >= numberOfPoints) return false; @@ -1194,7 +1194,7 @@ bool TTF::MovePoint(uint16 pointno, int x, int y) return true; } -bool TTF::MovePoint(uint16 pointno, GlyphPt p) +bool TTF::MovePoint(uint16_t pointno, GlyphPt p) { if (pointno >= numberOfPoints) return false;