Add support for Apple composite glyphs. * include/freetype/config/ftoption.h (TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED): New macro. * src/truetype/ttgload.c (OVERLAP_COMPOUND, SCALED_COMPONENT_OFFSET, UNSCALED_COMPONENT_OFFSET): New macros for additional OpenType glyph loading flags. (load_truetype_glyph): Implement it.
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
diff --git a/ChangeLog b/ChangeLog
index 410c195..206f0b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2002-08-16 George Williams <gww@silcom.com>
+
+ Add support for Apple composite glyphs.
+
+ * include/freetype/config/ftoption.h
+ (TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED): New macro.
+
+ * src/truetype/ttgload.c (OVERLAP_COMPOUND, SCALED_COMPONENT_OFFSET,
+ UNSCALED_COMPONENT_OFFSET): New macros for additional OpenType
+ glyph loading flags.
+ (load_truetype_glyph): Implement it.
+
2002-08-16 Werner Lemberg <wl@gnu.org>
* src/cff/cffgload.c (cff_free_glyph_data),
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index bed42b8..4659025 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -402,6 +402,25 @@ FT_BEGIN_HEADER
/*************************************************************************/
+ /* */
+ /* Define TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED to compile the */
+ /* TrueType glyph loader to use Apple's definition of how to handle */
+ /* component offsets in composite glyphs. */
+ /* */
+ /* Apple and MS disagree on the default behavior of component offsets */
+ /* in composites. Apple says that they should be scaled by the scale */
+ /* factors in the transformation matrix (roughly, it's more complex) */
+ /* while MS says they should not. OpenType defines two bits in the */
+ /* composite flags array which can be used to disambiguate, but old */
+ /* fonts will not have them. */
+ /* */
+ /* http://partners.adobe.com/asn/developer/opentype/glyf.html */
+ /* http://fonts.apple.com/TTRefMan/RM06/Chap6glyf.html */
+ /* */
+#undef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED
+
+
+ /*************************************************************************/
/*************************************************************************/
/**** ****/
/**** T Y P E 1 D R I V E R C O N F I G U R A T I O N ****/
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index efbe88e..7fb1a0f 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -43,17 +43,19 @@
/* */
/* Composite font flags. */
/* */
-#define ARGS_ARE_WORDS 0x001
-#define ARGS_ARE_XY_VALUES 0x002
-#define ROUND_XY_TO_GRID 0x004
-#define WE_HAVE_A_SCALE 0x008
-/* reserved 0x010 */
-#define MORE_COMPONENTS 0x020
-#define WE_HAVE_AN_XY_SCALE 0x040
-#define WE_HAVE_A_2X2 0x080
-#define WE_HAVE_INSTR 0x100
-#define USE_MY_METRICS 0x200
-
+#define ARGS_ARE_WORDS 0x0001
+#define ARGS_ARE_XY_VALUES 0x0002
+#define ROUND_XY_TO_GRID 0x0004
+#define WE_HAVE_A_SCALE 0x0008
+/* reserved 0x0010 */
+#define MORE_COMPONENTS 0x0020
+#define WE_HAVE_AN_XY_SCALE 0x0040
+#define WE_HAVE_A_2X2 0x0080
+#define WE_HAVE_INSTR 0x0100
+#define USE_MY_METRICS 0x0200
+#define OVERLAP_COMPOUND 0x0400
+#define SCALED_COMPONENT_OFFSET 0x0800
+#define UNSCALED_COMPONENT_OFFSET 0x1000
/*************************************************************************/
@@ -1005,7 +1007,7 @@
/* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */
/* `as is' in the glyph slot (the client application will be */
- /* responsible for interpreting this data)... */
+ /* responsible for interpreting these data)... */
/* */
if ( loader->load_flags & FT_LOAD_NO_RECURSE )
{
@@ -1123,6 +1125,68 @@
x = subglyph->arg1;
y = subglyph->arg2;
+ /* Use a default value dependent on */
+ /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old TT */
+ /* fonts which don't set the xxx_COMPONENT_OFFSET bit. */
+
+#ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED
+ if ( !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) &&
+#else
+ if ( ( subglyph->flags & SCALED_COMPONENT_OFFSET ) &&
+#endif
+ ( subglyph->flags & ( WE_HAVE_A_SCALE |
+ WE_HAVE_AN_XY_SCALE |
+ WE_HAVE_A_2X2 )) )
+ {
+#if 0
+
+ /*************************************************************************/
+ /* */
+ /* This algorithm is what Apple documents. But it doesn't work. */
+ /* */
+ int a = subglyph->transform.xx > 0 ? subglyph->transform.xx
+ : -subglyph->transform.xx;
+ int b = subglyph->transform.yx > 0 ? subglyph->transform.yx
+ : -subglyph->transform.yx;
+ int c = subglyph->transform.xy > 0 ? subglyph->transform.xy
+ : -subglyph->transform.xy;
+ int d = subglyph->transform.yy > 0 ? subglyph->transform.yy
+ : -subglyph->transform.yy;
+ int m = a > b ? a : b;
+ int n = c > d ? c : d;
+
+
+ if ( a - b <= 33 && a - b >= -33 )
+ m *= 2;
+ if ( c - d <= 33 && c - d >= -33 )
+ n *= 2;
+ x = FT_MulFix( x, m );
+ y = FT_MulFix( y, n );
+
+#else /* 0 */
+
+ /*************************************************************************/
+ /* */
+ /* This algorithm is a guess and works much better than the above. */
+ /* */
+ int mac_xscale = FT_SqrtFixed(
+ FT_MulFix( subglyph->transform.xx,
+ subglyph->transform.xx ) +
+ FT_MulFix( subglyph->transform.xy,
+ subglyph->transform.xy) );
+ int mac_yscale = FT_SqrtFixed(
+ FT_MulFix( subglyph->transform.yy,
+ subglyph->transform.yy ) +
+ FT_MulFix( subglyph->transform.yx,
+ subglyph->transform.yx ) );
+
+
+ x = FT_MulFix( x, mac_xscale );
+ y = FT_MulFix( y, mac_yscale );
+#endif /* 0 */
+
+ }
+
if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )
{
x = FT_MulFix( x, x_scale );