fixing hinted advance width bug in all font drivers
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
diff --git a/ChangeLog b/ChangeLog
index fcd8dda..d7ff3a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2001-12-14 David Turner <david@freetype.org>
+
+ * src/truetype/ttgload.c (TT_Load_Glyph), src/type1/t1gload.c
+ (T1_Load_Glyph), src/cid/cidgload.c (CID_Load_Glyph), src/cff/cffgload.c
+ (CFF_Load_Glyph): fixed an important bug common to all font drivers (the
+ advance width was never hinted when it should)
+
+
2001-12-12 David Turner <david@freetype.org>
* src/pshint/pshglob.c: adding correct BlueScale/BlueShift support,
@@ -24,7 +32,7 @@
* docs/FTL.TXT: Simple fix (change "LICENSE.TXT" to "FTL.TXT").
- * builds/unix/freetype2.m4: New file for checking configure paths.
+ * builds/unix/freetype2.m4: New file for checking configure paths.
We need to install it in $(prefix)/share/aclocal/freetype2.m4 but I
didn't modify builds/unix/install.mk yet.
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index c9a5c28..81b29e2 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -35,6 +35,7 @@
/* */
#define FREETYPE_MAJOR 2
#define FREETYPE_MINOR 0
+#define FREETYPE_PATCH 5
#include <ft2build.h>
diff --git a/include/freetype/ftglyph.h b/include/freetype/ftglyph.h
index f966653..b51e959 100644
--- a/include/freetype/ftglyph.h
+++ b/include/freetype/ftglyph.h
@@ -65,6 +65,24 @@ FT_BEGIN_HEADER
/*************************************************************************/
/* */
+ /* <Type> */
+ /* FT_Glyph */
+ /* */
+ /* <Description> */
+ /* Handle to an object used to model generic glyph images. It's a */
+ /* pointer to the @FT_GlyphRec structure and can contain a glyph */
+ /* bitmap or pointer.. */
+ /* */
+ /* <Note> */
+ /* glyph objects are not owned by the library. You must thus release */
+ /* them manually (through @FT_Done_Glyph) _before_ calling */
+ /* @FT_Done_FreeType. */
+ /* */
+ typedef struct FT_GlyphRec_* FT_Glyph;
+
+
+ /*************************************************************************/
+ /* */
/* <Struct> */
/* FT_GlyphRec */
/* */
@@ -88,7 +106,19 @@ FT_BEGIN_HEADER
FT_Glyph_Format format;
FT_Vector advance;
- } FT_GlyphRec, *FT_Glyph;
+ } FT_GlyphRec;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Type> */
+ /* FT_BitmapGlyph */
+ /* */
+ /* <Description> */
+ /* Handle to an object used to model a bitmap glyph image. This is */
+ /* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec */
+ /* */
+ typedef struct FT_BitmapGlyphRec_* FT_BitmapGlyph;
/*************************************************************************/
@@ -128,7 +158,19 @@ FT_BEGIN_HEADER
FT_Int top;
FT_Bitmap bitmap;
- } FT_BitmapGlyphRec, *FT_BitmapGlyph;
+ } FT_BitmapGlyphRec;
+
+
+ /*************************************************************************/
+ /* */
+ /* <Type> */
+ /* FT_OutlineGlyph */
+ /* */
+ /* <Description> */
+ /* Handle to an object used to model an outline glyph image. This is */
+ /* a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec */
+ /* */
+ typedef struct FT_OutlineGlyphRec_* FT_OutlineGlyph;
/*************************************************************************/
@@ -162,7 +204,7 @@ FT_BEGIN_HEADER
FT_GlyphRec root;
FT_Outline outline;
- } FT_OutlineGlyphRec, *FT_OutlineGlyph;
+ } FT_OutlineGlyphRec;
/*************************************************************************/
diff --git a/src/base/ftdbgmem.c b/src/base/ftdbgmem.c
index bca789b..324d848 100644
--- a/src/base/ftdbgmem.c
+++ b/src/base/ftdbgmem.c
@@ -163,7 +163,7 @@
{
FT_Memory memory = table->memory;
FT_Pointer block;
-
+
memory->user = table->memory_user;
block = table->alloc( memory, size );
@@ -178,7 +178,7 @@
FT_Pointer block )
{
FT_Memory memory = table->memory;
-
+
memory->user = table->memory_user;
table->free( memory, block );
@@ -297,7 +297,7 @@
if ( node->size > 0 )
{
- printf(
+ printf(
"leaked memory block at address %p, size %8ld in (%s:%ld)\n",
node->address, node->size,
FT_FILENAME( node->alloc_file_name ),
@@ -485,7 +485,7 @@
return (FT_Pointer) block;
}
-
+
extern void
ft_mem_debug_free( FT_Memory memory,
@@ -505,7 +505,7 @@
table->file_name = NULL;
table->line_no = 0;
}
-
+
extern FT_Pointer
ft_mem_debug_realloc( FT_Memory memory,
@@ -520,7 +520,7 @@
const char* file_name = FT_FILENAME( table->file_name );
FT_Long line_no = table->line_no;
-
+
if ( block == NULL || cur_size == 0 )
ft_mem_debug_panic( "trying to reallocate NULL in (%s:%ld)",
file_name, line_no );
@@ -620,7 +620,7 @@
table->line_no = line_no;
}
return FT_Alloc( memory, size, P );
- }
+ }
FT_BASE_DEF( FT_Error )
@@ -640,7 +640,7 @@
table->line_no = line_no;
}
return FT_Realloc( memory, current, size, P );
- }
+ }
FT_BASE_DEF( void )
@@ -662,9 +662,9 @@
#else /* !FT_DEBUG_MEMORY */
-
+
/* ANSI C doesn't like empty source files */
- extern const FT_Byte _debug_mem_dummy = 0;
+ const FT_Byte _debug_mem_dummy = 0;
#endif /* !FT_DEBUG_MEMORY */
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index 2e8c55a..8ea8c53 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -1065,17 +1065,17 @@
FT_TRACE4(( op == cff_op_hstem ? " hstem" :
( op == cff_op_vstem ? " vstem" :
( op == cff_op_hstemhm ? " hstemhm" : " vstemhm" )) ));
-
+
if ( hinter )
hinter->stems( hinter->hints,
( op == cff_op_vstem || op == cff_op_vstemhm ),
num_args/2,
args );
-
+
decoder->num_hints += num_args / 2;
args = stack;
break;
-
+
case cff_op_hintmask:
case cff_op_cntrmask:
@@ -1095,7 +1095,7 @@
(decoder->num_hints+7) >> 3,
ip );
}
-
+
#ifdef FT_DEBUG_LEVEL_TRACE
{
FT_UInt maskbyte;
@@ -1647,7 +1647,7 @@
{
if (hinter->close( hinter->hints, builder->current->n_points ))
goto Syntax_Error;
-
+
/* apply hints to the loaded glyph outline now */
hinter->apply( hinter->hints,
builder->current,
@@ -2301,6 +2301,15 @@
metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
+
+ if ( hinting )
+ {
+ metrics->horiAdvance = (metrics->horiAdvance+32) & -64;
+ metrics->vertAdvance = (metrics->vertAdvance+32) & -64;
+
+ metrics->vertBearingX = (metrics->vertBearingX+32) & -64;
+ metrics->vertBearingY = (metrics->vertBearingY+32) & -64;
+ }
}
/* compute the other metrics */
diff --git a/src/cid/cidgload.c b/src/cid/cidgload.c
index e07c702..c37dd1c 100644
--- a/src/cid/cidgload.c
+++ b/src/cid/cidgload.c
@@ -330,6 +330,15 @@
metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
+
+ if ( hinting )
+ {
+ metrics->horiAdvance = (metrics->horiAdvance+32) & -64;
+ metrics->vertAdvance = (metrics->vertAdvance+32) & -64;
+
+ metrics->vertBearingX = (metrics->vertBearingX+32) & -64;
+ metrics->vertBearingY = (metrics->vertBearingY+32) & -64;
+ }
}
/* compute the other metrics */
diff --git a/src/pshinter/pshglob.c b/src/pshinter/pshglob.c
index 406ca11..36f7759 100644
--- a/src/pshinter/pshglob.c
+++ b/src/pshinter/pshglob.c
@@ -383,10 +383,10 @@
/* */
{
FT_Int threshold = blues->blue_shift;
-
+
while ( threshold > 0 && FT_MulFix( threshold, scale ) > 32 )
threshold --;
-
+
blues->blue_threshold = threshold;
}
@@ -434,23 +434,23 @@
/* process the families now */
for ( num = 0; num < 2; num++ )
- {
+ {
PSH_Blue_Zone zone1, zone2;
FT_UInt count1, count2;
PSH_Blue_Table normal, family;
-
+
switch (num)
{
case 0:
normal = &blues->normal_top;
family = &blues->family_top;
break;
-
+
default:
normal = &blues->normal_bottom;
family = &blues->family_bottom;
}
-
+
zone1 = normal->zones;
count1 = normal->count;
for ( ; count1 > 0; count1--, zone1++ )
@@ -640,8 +640,9 @@
globals->blues.blue_scale = priv->blue_scale ? priv->blue_scale
: (0.039625*0x400000L);
-
- globals->blues.blue_shift = priv->blue_shift;
+
+ globals->blues.blue_shift = priv->blue_shift ? priv->blue_shift
+ : 7;
globals->dimension[0].scale_mult = 0;
globals->dimension[0].scale_delta = 0;
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 3f89fa7..588ec41 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -1174,6 +1174,10 @@
glyph->metrics.horiBearingY = bbox.yMax;
glyph->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
+ /* don't forget to hint the advance when we need to */
+ if ( IS_HINTED( loader->load_flags ) )
+ glyph->metrics.horiAdvance = (glyph->metrics.horiAdvance+32) & -64;
+
/* Now take care of vertical metrics. In the case where there is */
/* no vertical information within the font (relatively common), make */
/* up some metrics by `hand'... */
diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index a801032..6885645 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -277,6 +277,15 @@
metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
+
+ if ( hinting )
+ {
+ metrics->horiAdvance = (metrics->horiAdvance+32) & -64;
+ metrics->vertAdvance = (metrics->vertAdvance+32) & -64;
+
+ metrics->vertBearingX = (metrics->vertBearingX+32) & -64;
+ metrics->vertBearingY = (metrics->vertBearingY+32) & -64;
+ }
}
/* compute the other metrics */