finally fixed that crazy Type 1 hinter.. it still sucks though .. ;-)
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
diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index 921ecc5..aac176b 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -52,6 +52,39 @@
*
*********************************************************************/
+ static
+ void T1_Reset_Builder( T1_Builder* builder, FT_Bool reset_base )
+ {
+ builder->pos_x = 0;
+ builder->pos_y = 0;
+
+ builder->left_bearing.x = 0;
+ builder->left_bearing.y = 0;
+ builder->advance.x = 0;
+ builder->advance.y = 0;
+
+ builder->pass = 0;
+ builder->hint_point = 0;
+
+ if (reset_base)
+ {
+ builder->base.n_points = 0;
+ builder->base.n_contours = 0;
+ }
+
+ {
+ FT_Outline* base = &builder->base;
+ FT_Outline* cur = &builder->current;
+
+ cur->n_points = 0;
+ cur->n_contours = 0;
+ cur->points = base->points + base->n_points;
+ cur->tags = base->tags + base->n_points;
+ cur->contours = base->contours + base->n_contours;
+ }
+ }
+
+
LOCAL_FUNC
void T1_Init_Builder( T1_Builder* builder,
T1_Face face,
@@ -81,20 +114,7 @@
builder->scale_y = size->root.metrics.y_scale;
}
- builder->pos_x = 0;
- builder->pos_y = 0;
-
- builder->left_bearing.x = 0;
- builder->left_bearing.y = 0;
- builder->advance.x = 0;
- builder->advance.y = 0;
-
- builder->base.n_points = 0;
- builder->base.n_contours = 0;
- builder->current = builder->base;
-
- builder->pass = 0;
- builder->hint_point = 0;
+ T1_Reset_Builder( builder, 1 );
}
@@ -142,6 +162,7 @@
*
*********************************************************************/
+
LOCAL_FUNC
void T1_Init_Decoder( T1_Decoder* decoder,
const T1_Hinter_Funcs* funcs )
@@ -250,24 +271,6 @@
return T1_Err_Syntax_Error;
}
- /* First load "bchar" in builder */
- /* now load the unscaled outline */
- cur->n_points = 0;
- cur->n_contours = 0;
- cur->points = base->points + base->n_points;
- cur->tags = base->tags + base->n_points;
- cur->contours = base->contours + base->n_contours;
-
- error = T1_Parse_CharStrings( decoder,
- type1->charstrings [bchar_index],
- type1->charstrings_len[bchar_index],
- type1->num_subrs,
- type1->subrs,
- type1->subrs_len );
- if (error) return error;
-
- n_base_points = cur->n_points;
-
if ( decoder->builder.no_recurse )
{
/* if we're trying to load a composite glyph, do not load the */
@@ -309,6 +312,24 @@
}
else
{
+ /* First load "bchar" in builder */
+ /* now load the unscaled outline */
+ cur->n_points = 0;
+ cur->n_contours = 0;
+ cur->points = base->points + base->n_points;
+ cur->tags = base->tags + base->n_points;
+ cur->contours = base->contours + base->n_contours;
+
+ error = T1_Parse_CharStrings( decoder,
+ type1->charstrings [bchar_index],
+ type1->charstrings_len[bchar_index],
+ type1->num_subrs,
+ type1->subrs,
+ type1->subrs_len );
+ if (error) return error;
+
+ n_base_points = cur->n_points;
+
/* save the left bearing and width of the base character */
/* as they will be erased by the next load.. */
left_bearing = decoder->builder.left_bearing;
@@ -1442,6 +1463,136 @@
+ /*****************************************************************/
+ /* */
+ /* Hinter overview : */
+ /* */
+ /* This is a two-pass hinter. On the first pass, the hints */
+ /* are all recorded by the hinter, and no point is loaded */
+ /* in the outline. */
+ /* */
+ /* When the first pass is finished, all stems hints are */
+ /* grid-fitted at once. */
+ /* */
+ /* Then, a second pass is performed to load the outline */
+ /* points as well as hint/scale them correctly. */
+ /* */
+
+#ifndef T1_CONFIG_OPTION_DISABLE_HINTER
+
+ static
+ FT_Error t1_load_hinted_glyph( T1_Decoder* decoder,
+ FT_UInt glyph_index,
+ FT_Bool recurse )
+ {
+ T1_Builder* builder = &decoder->builder;
+ T1_GlyphSlot glyph = builder->glyph;
+ T1_Font* type1 = &builder->face->type1;
+ FT_Outline old_base;
+ FT_Error error;
+
+ /* Pass 1 - try to load first glyph, simply recording points */
+ old_base = builder->base;
+ T1_Reset_Builder( builder, 0 );
+
+ builder->no_recurse = recurse;
+ builder->pass = 0;
+ glyph->hints->hori_stems.num_stems = 0;
+ glyph->hints->vert_stems.num_stems = 0;
+
+ error = T1_Parse_CharStrings( decoder,
+ type1->charstrings [glyph_index],
+ type1->charstrings_len[glyph_index],
+ type1->num_subrs,
+ type1->subrs,
+ type1->subrs_len );
+ if (error) goto Exit;
+
+ /* check for composite (i.e. "seac" operator) */
+ if ( glyph->root.format == ft_glyph_format_composite )
+ {
+ /* this is a composite glyph, we must then load the first one, */
+ /* then load the second one on top of it and translate it by a */
+ /* fixed amount.. */
+ FT_Outline* cur = &builder->current;
+ FT_UInt n_base_points;
+ FT_SubGlyph* subglyph = glyph->root.subglyphs;
+ T1_Size size = builder->size;
+ FT_Pos dx, dy;
+ FT_Vector left_bearing, advance;
+
+ /* clean glyph format */
+ glyph->root.format = ft_glyph_format_none;
+
+ /* First load "bchar" in builder */
+ builder->no_recurse = 0;
+ error = t1_load_hinted_glyph( decoder, subglyph->index, 0 );
+ if (error) goto Exit;
+
+ /* save the left bearing and width of the base character */
+ /* as they will be erased by the next load.. */
+ left_bearing = builder->left_bearing;
+ advance = builder->advance;
+
+ /* Then load "achar" in builder */
+ n_base_points = builder->base.n_points;
+ subglyph++;
+ error = t1_load_hinted_glyph( decoder, subglyph->index, 0 );
+ if (error) goto Exit;
+
+ /* adjust contours in accented character outline */
+ {
+ T1_Int n;
+
+ for ( n = 0; n < cur->n_contours; n++ )
+ cur->contours[n] += n_base_points;
+ }
+
+ /* Finally, move the accent */
+ dx = FT_MulFix( subglyph->arg1, size->root.metrics.x_scale );
+ dy = FT_MulFix( subglyph->arg2, size->root.metrics.y_scale );
+ dx = (dx+32) & -64;
+ dy = (dy+32) & -64;
+ FT_Outline_Translate( cur, dx, dy );
+
+ /* restore the left side bearing and */
+ /* advance width of the base character */
+ builder->left_bearing = left_bearing;
+ builder->advance = advance;
+ }
+ else
+ {
+ /* All right, pass 1 is finished, now grid-fit all stem hints */
+ T1_Hint_Stems( &decoder->builder );
+
+ /* undo the end-char */
+ builder->base.n_points -= builder->current.n_points;
+ builder->base.n_contours -= builder->current.n_contours;
+
+ /* Pass 2 - record and scale/hint the points */
+ T1_Reset_Builder( &decoder->builder, 0 );
+
+ builder->pass = 1;
+ builder->no_recurse = 0;
+
+ error = T1_Parse_CharStrings( decoder,
+ type1->charstrings [glyph_index],
+ type1->charstrings_len[glyph_index],
+ type1->num_subrs,
+ type1->subrs,
+ type1->subrs_len );
+ }
+
+ /* save new glyph tables */
+ if (recurse)
+ T1_Done_Builder( builder );
+
+ Exit:
+ return error;
+ }
+#endif
+
+
LOCAL_FUNC
T1_Error T1_Load_Glyph( T1_GlyphSlot glyph,
@@ -1469,60 +1620,16 @@
hinting = 0;
#ifndef T1_CONFIG_OPTION_DISABLE_HINTER
- /*****************************************************************/
- /* */
- /* Hinter overview : */
- /* */
- /* This is a two-pass hinter. On the first pass, the hints */
- /* are all recorded by the hinter, and no point is loaded */
- /* in the outline. */
- /* */
- /* When the first pass is finished, all stems hints are */
- /* grid-fitted at once. */
- /* */
- /* Then, a second pass is performed to load the outline */
- /* points as well as hint/scale them correctly. */
- /* */
hinting = (load_flags & (FT_LOAD_NO_SCALE|FT_LOAD_NO_HINTING)) == 0;
if ( hinting )
{
- /* Pass 1 - don't record points, simply stem hints */
- T1_Init_Decoder( &decoder, &t1_hinter_funcs );
- T1_Init_Builder( &decoder.builder, face, size, glyph,
- &gload_builder_interface_null );
-
- glyph->hints->hori_stems.num_stems = 0;
- glyph->hints->vert_stems.num_stems = 0;
-
- error = T1_Parse_CharStrings( &decoder,
- type1->charstrings [glyph_index],
- type1->charstrings_len[glyph_index],
- type1->num_subrs,
- type1->subrs,
- type1->subrs_len );
-
- /* All right, pass 1 is finished, now grid-fit all stem hints */
- T1_Hint_Stems( &decoder.builder );
-
- /* Pass 2 - record and scale/hint the points */
T1_Init_Decoder( &decoder, &t1_hinter_funcs );
T1_Init_Builder( &decoder.builder, face, size, glyph,
&gload_builder_interface );
-
- decoder.builder.pass = 1;
- decoder.builder.no_recurse = 0;
-
- error = T1_Parse_CharStrings( &decoder,
- type1->charstrings [glyph_index],
- type1->charstrings_len[glyph_index],
- type1->num_subrs,
- type1->subrs,
- type1->subrs_len );
-
- /* save new glyph tables */
- T1_Done_Builder( &decoder.builder );
+
+ error = t1_load_hinted_glyph( &decoder, glyph_index, 1 );
}
else
#endif
diff --git a/src/type1/t1hinter.c b/src/type1/t1hinter.c
index bdae693..861b0c6 100644
--- a/src/type1/t1hinter.c
+++ b/src/type1/t1hinter.c
@@ -629,7 +629,7 @@
stems = stem_table->stems;
num_stems = stem_table->num_stems;
- /* Compute minimum and maximum orus for the stem */
+ /* Compute minimum and maximum coord for the stem */
min = pos + ( vertical
? builder->left_bearing.x
: builder->left_bearing.y );
@@ -638,7 +638,7 @@
max = min + width;
else
{
- /* a negative width indicates a ghost stem */
+ /* a negative width indicates a "ghost" stem */
if ( width == -21 )
min += width;