the SFNT Kerning table loader now ensures that the table is correctly sorted.
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
diff --git a/ChangeLog b/ChangeLog
index 59949c9..145a8af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2001-06-27 David Turner <david@freetype.org>
+ * src/sfnt/ttload.c (TT_Load_Kern): the kern table loader now ensures
+ that the kerning table is correctly sorted (some problem fonts don't
+ have a correct kern table !!)
+
* builds/unix/ftconfig.in: changed the definition of the
FT_CALLBACK_DEF macro
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index 8f4e366..e81e475 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -26,6 +26,7 @@
#include "sferrors.h"
+#include <stdlib.h> /* for qsort */
/*************************************************************************/
/* */
@@ -1537,6 +1538,10 @@
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
+
+ FT_CALLBACK_DEF(int)
+ tt_kern_pair_compare( const void* a, const void* b );
+
FT_LOCAL_DEF
FT_Error TT_Load_Kern( TT_Face face,
FT_Stream stream )
@@ -1610,6 +1615,26 @@
face->num_kern_pairs = num_pairs;
face->kern_table_index = n;
+
+ /* ensure that the kerning pair table is sorted (yes, some */
+ /* fonts have unsorted tables !!) */
+ {
+ FT_UInt i;
+ TT_Kern_0_Pair* pair;
+
+ pair = face->kern_pairs;
+
+ for ( i=1; i < num_pairs; i++, pair++ )
+ {
+ if ( tt_kern_pair_compare( pair, pair+1 ) != -1 )
+ {
+ qsort( (void*)face->kern_pairs, (int)num_pairs,
+ sizeof(TT_Kern_0_Pair), tt_kern_pair_compare );
+ break;
+ }
+ }
+ }
+
goto Exit;
}
@@ -1626,6 +1651,23 @@
return error;
}
+#undef TT_KERN_INDEX
+#define TT_KERN_INDEX(g1,g2) (((FT_ULong)g1 << 16) | g2)
+
+ FT_CALLBACK_DEF(int)
+ tt_kern_pair_compare( const void* a, const void* b )
+ {
+ TT_Kern_0_Pair* pair1 = (TT_Kern_0_Pair*)a;
+ TT_Kern_0_Pair* pair2 = (TT_Kern_0_Pair*)b;
+
+ FT_ULong index1 = TT_KERN_INDEX( pair1->left, pair1->right );
+ FT_ULong index2 = TT_KERN_INDEX( pair2->left, pair2->right );
+
+ return ( index1 < index2 ? -1 :
+ ( index1 > index2 ? 1 : 0 ));
+ }
+
+#undef TT_KERN_INDEX
/*************************************************************************/
/* */