* src/base/ftmac.c: Add byteorder workaround for Intel Mac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
diff --git a/ChangeLog b/ChangeLog
index 24aea14..ea53ece 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2006-06-22 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
+
+ Insert EndianS16_BtoN and EndianS32_BtoN as workaround for
+ Intel Mac. The original patch was written by David Sachitano
+ and Lawrence Coopet, modified by Sean McBride for MPW
+ compatibility. Only required data are converted, unused data
+ are left in big endian.
+
+ * src/base/ftmac.c:
+ Undefine existing OS_INLINE before definition.
+ Include <Endian.h> for byteorder macros for non Mac OS X
+ platforms.
+ (count_faces_sfnt): Insert EndianS16_BtoN to parse the header
+ of FontAssociation table in FOND resource.
+ (count_faces_scalable): Insert EndianS16_BtoN to parse the
+ header and fontSize at each entry of FontAssociation table
+ in FOND resource.
+ (parse_fond): Insert EndianS16_BtoN and EndianS32_BtoN to
+ parse ffStylOff of FamilyRecord header of FOND resource,
+ the header, fontSize, fontID at each entry of FontAssociation
+ table, and StyleMapping table.
+ (count_faces): HUnlock is suspended after all FOND utilization.
+
2006-06-08 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
Public API of TrueTypeGX, OpenType, and classic kern table validator
diff --git a/src/base/ftmac.c b/src/base/ftmac.c
index e8c24d8..d08cac8 100644
--- a/src/base/ftmac.c
+++ b/src/base/ftmac.c
@@ -64,11 +64,13 @@
/* This is for Mac OS X. Without redefinition, OS_INLINE */
/* expands to `static inline' which doesn't survive the */
/* -ansi compilation flag of GCC. */
+#undef OS_INLINE
#define OS_INLINE static __inline__
#include <Carbon/Carbon.h>
#else
#include <Resources.h>
#include <Fonts.h>
+#include <Endian.h>
#include <Errors.h>
#include <Files.h>
#include <TextUtils.h>
@@ -536,7 +538,7 @@
/* The count is 1 greater than the value in the FOND. */
/* Isn't that cute? :-) */
- return 1 + *( (short*)( fond_data + sizeof ( FamRec ) ) );
+ return EndianS16_BtoN( *( (short*)( fond_data + sizeof ( FamRec ) ) ) ) + 1;
}
@@ -549,13 +551,13 @@
fond = (FamRec*)fond_data;
- face_all = *( (short *)( fond_data + sizeof ( FamRec ) ) ) + 1;
+ face_all = EndianS16_BtoN( *( (short *)( fond_data + sizeof ( FamRec ) ) ) ) + 1;
assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 );
face = 0;
for ( i = 0; i < face_all; i++ )
{
- if ( 0 == assoc[i].fontSize )
+ if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) )
face++;
}
return face;
@@ -597,19 +599,19 @@
/* if the face at this index is not scalable,
fall back to the first one (old behavior) */
- if ( assoc->fontSize == 0 )
+ if ( EndianS16_BtoN( assoc->fontSize ) == 0 )
{
*have_sfnt = 1;
- *sfnt_id = assoc->fontID;
+ *sfnt_id = EndianS16_BtoN( assoc->fontID );
}
else if ( base_assoc->fontSize == 0 )
{
*have_sfnt = 1;
- *sfnt_id = base_assoc->fontID;
+ *sfnt_id = EndianS16_BtoN( base_assoc->fontID );
}
}
- if ( fond->ffStylOff )
+ if ( EndianS32_BtoN( fond->ffStylOff ) )
{
unsigned char* p = (unsigned char*)fond_data;
StyleTable* style;
@@ -619,10 +621,10 @@
int i;
- p += fond->ffStylOff;
+ p += EndianS32_BtoN( fond->ffStylOff );
style = (StyleTable*)p;
p += sizeof ( StyleTable );
- string_count = *(unsigned short*)(p);
+ string_count = EndianS16_BtoN( *(short*)(p) );
p += sizeof ( short );
for ( i = 0; i < string_count && i < 64; i++ )
@@ -770,13 +772,13 @@
Str255 lwfn_file_name;
UInt8 buff[HFS_MAXPATHLEN];
FT_Error err;
+ short num_faces;
have_sfnt = have_lwfn = 0;
HLock( fond );
parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 );
- HUnlock( fond );
if ( lwfn_file_name[0] )
{
@@ -787,9 +789,12 @@
}
if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
- return 1;
+ num_faces = 1;
else
- return count_faces_scalable( *fond );
+ num_faces = count_faces_scalable( *fond );
+
+ HUnlock( fond );
+ return num_faces;
}