--- truetype.cpp 2021-08-08 22:09:39.000000000 -0400 +++ truetype.cpp 2023-04-07 09:05:58.829873766 -0400 @@ -1998,18 +1998,61 @@ if (flags & ARG_1_AND_2_ARE_WORDS) { #ifdef TTF_DEBUG - Debug_Info("ARG_1_AND_2_ARE_WORDS "); + Debug_Info("ARG_1_AND_2_ARE_WORDS\n"); #endif - arg1 = READSHORT(ffile->fp); - arg2 = READSHORT(ffile->fp); + if (flags & ARGS_ARE_XY_VALUES) + { // Values are int16_t + arg1 = READSHORT(ffile->fp); + arg2 = READSHORT(ffile->fp); + } + else + { // Values are uint16_t + arg1 = READUSHORT(ffile->fp); + arg1 = READUSHORT(ffile->fp); + } } else { - arg1 = READUSHORT(ffile->fp); - arg2 = arg1 & 0xFF; - arg1 = (arg1 >> 8) & 0xFF; +#ifdef TTF_DEBUG + Debug_Info("ARG_1_AND_2_ARE_BYTES\n"); +#endif + if (flags & ARGS_ARE_XY_VALUES) + { // Values are int8_t * 2 + + union uC { + int8_t buffer[2]; + uint16_t value; + } u; + u.value = READUSHORT(ffile->fp); + + // Determine this machine's endianness. Method used herein + // derived from netpbm's pamtopfm converter by: Bryan + // Henderson, San Jose, CA April 2004. Code was contributed + // to the public domain. + short const testNumber = 0x0001; + unsigned char* const storedNumber = (unsigned char *)&testNumber; + int BigEndian = (storedNumber[0] == 0x01) ? 0 : 1; + + if (BigEndian) + { + arg1 = (SHORT)u.buffer[0]; + arg2 = (SHORT)u.buffer[1]; + } + else + { + arg1 = (SHORT)u.buffer[1]; + arg2 = (SHORT)u.buffer[0]; + } + } + else + { // Values are uint8_t * 2 + arg1 = READUSHORT(ffile->fp); + arg2 = arg1 & 0xFF; + arg1 = (arg1 >> 8) & 0xFF; + } } + #ifdef TTF_DEBUG if (flags & ROUND_XY_TO_GRID) {