still more updates to the TrueType driver to make it more "extensible"..
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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
diff --git a/demos/Makefile b/demos/Makefile
index 5e239bb..e50decd 100644
--- a/demos/Makefile
+++ b/demos/Makefile
@@ -160,7 +160,8 @@ else
#
# The list of demonstration programs to build.
#
- EXES := ftlint ftview fttimer compos ftstring memtest ftmulti
+# EXES := ftlint ftview fttimer compos ftstring memtest ftmulti
+ EXES := ftlint ftview
ifneq ($(findstring $(PLATFORM),os2 unix win32),)
EXES += ttdebug
diff --git a/docs/tutorial/index.html b/docs/tutorial/index.html
index cbba6ec..a9e04ed 100644
--- a/docs/tutorial/index.html
+++ b/docs/tutorial/index.html
@@ -92,9 +92,10 @@
the handle <tt>library</tt> to it.</p>
</li>
<li>
- <p>Load each font driver that FreeType knows about in the library.
+ <p>Load each modules that FreeType knows about in the library.
This means that by default, your new <tt>library</tt> object is able
- to handle TrueType and Type 1 fonts gracefully.</p>
+ to handle TrueType, Type 1, CID-keyed & OpenType/CFF fonts
+ gracefully.</p>
</li>
</ul>
@@ -238,6 +239,8 @@
font driver when creating the object. We advise you to refer to the
FreeType 2 reference manual in order to learn how to use it.</p>
+ <p>Note that providing a custom stream might also be used to access a
+ TrueType font embedded in a Postscript Type42 wrapper..</p>
<hr>
<h3>
@@ -435,7 +438,7 @@
<p>Note that this is one of the rare FreeType functions that do not
return an error code. However, when a given character code has no
- glyph image in the face, the value&nbso;0 is returned. By convention,
+ glyph image in the face, the value 0 is returned. By convention,
it always correspond to a special glyph image called the <b>missing
glyph</b>, which usually is represented as a box or a space.</p>
@@ -483,16 +486,29 @@
higher-quality images of the same glyph).</p>
</li>
<li>
- <p>If there is an outline for the corresponding glyph, load it
- unless <tt>FT_LOAD_NO_OUTLINE</tt> is set. Otherwise, scale it to
- the current size, unless the <tt>FT_LOAD_NO_SCALE</tt> flag is
- set.</p>
+ <p>If there is a glyph image in another format (e.g. a vectorial
+ outline), load it in the glyph slot. Then, scale it to the
+ current size, unless the <tt>FT_LOAD_NO_SCALE</tt> flag is
+ set.</p>
</li>
<li>
- <p>If the outline was loaded and scaled, try to grid-fit it (which
+ <p>If the glyph image was loaded and scaled, try to grid-fit it (which
dramatically improves its quality) unless the flag
<tt>FT_LOAD_NO_HINTING</tt> is set.</p>
</li>
+
+ <li>
+ <p>If the glyph image is scalable, transform it through the current
+ transform (that can be set with <tt>FT_Set_Transform</tt>).</p>
+ </li>
+
+ <li>
+ <p>Finally, if the <tt>FT_LOAD_RENDER</tt> flag is set, convert the
+ glyph image into a bitmap. By default, this means a 1-bit
+ monochrome bitmap, unless <tt>FT_LOAD_ANTI_ALIAS</tt> is set,
+ where an 8-bit 256-gray-levels anti-aliased bitmap is generated.
+ </p>
+ </li>
</ul>
<p>There are a few others <tt>FT_LOAD_xxx</tt> flags defined. For
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 66e3841..023e0f1 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -1814,7 +1814,7 @@
/* FT_Render_Glyph. */
/* */
/* */
-#define FT_LOAD_LINEAR_ANTI_ALIAS 4096
+#define FT_LOAD_ANTI_ALIAS 4096
/*************************************************************************/
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index f5b5a0b..8ad78e4 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -1410,6 +1410,7 @@
FT_Stream stream;
FT_Int byte_len;
+ FT_Short n_contours;
FT_BBox bbox;
FT_Int left_bearing;
FT_Int advance;
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 4d8ad4b..c048ae7 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -194,17 +194,63 @@
/*************************************************************************/
/* */
- /* <Function> */
- /* TT_Load_Simple_Glyph */
- /* */
- /* <Description> */
- /* Loads a simple (i.e, non-composite) glyph. This function is used */
- /* for the `Load_Simple' state of TT_Load_Glyph(). All composite */
- /* glyphs elements will be loaded with this routine. */
+ /* The following functions are used by default with TrueType fonts. */
+ /* However, they can be replaced by alternatives if we need to support */
+ /* TrueType-compressed formats (like MicroType) in the future.. */
/* */
+
+ static
+ FT_Error TT_Access_Glyph_Frame( TT_Loader* loader,
+ FT_UInt glyph_index,
+ FT_ULong offset,
+ FT_UInt byte_count )
+ {
+ FT_Error error;
+ FT_Stream stream = loader->stream;
+
+ /* the following line sets the 'error' variable through macros !! */
+ (void)( FILE_Seek( offset ) || ACCESS_Frame( byte_count ) );
+
+ FT_TRACE5(( "Glyph %ld\n", glyph_index ));
+ return error;
+ }
+
+
+
+ static
+ void TT_Forget_Glyph_Frame( TT_Loader* loader )
+ {
+ FT_Stream stream = loader->stream;
+ FORGET_Frame();
+ }
+
+
+
+ static
+ FT_Error TT_Load_Glyph_Header( TT_Loader* loader )
+ {
+ FT_Stream stream = loader->stream;
+
+ loader->n_contours = GET_Short();
+
+ loader->bbox.xMin = GET_Short();
+ loader->bbox.yMin = GET_Short();
+ loader->bbox.xMax = GET_Short();
+ loader->bbox.yMax = GET_Short();
+
+ FT_TRACE5(( " # of contours: %d\n", loader->n_contours ));
+ FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin,
+ loader->bbox.xMax ));
+ FT_TRACE5(( " yMin: %4d yMax: %4d\n", loader->bbox.yMin,
+ loader->bbox.yMax ));
+
+ return FT_Err_Ok;
+ }
+
+
+
static
FT_Error TT_Load_Simple_Glyph( TT_Loader* load,
- FT_UInt byte_count,
FT_Int n_contours )
{
FT_Error error;
@@ -217,9 +263,6 @@
FT_Int n, n_points;
- if ( ACCESS_Frame( byte_count ) )
- return error;
-
/* reading the contours endpoints & number of points */
{
short* cur = gloader->current.outline.contours;
@@ -357,17 +400,99 @@
outline->n_points = n_points;
outline->n_contours = n_contours;
-
+
+ Fail:
return error;
+ }
+
+
+ static
+ FT_Error TT_Load_Composite_Glyph( TT_Loader* loader,
+ FT_UInt byte_count )
+ {
+ FT_Error error;
+ FT_Stream stream = loader->stream;
+ FT_GlyphLoader* gloader = loader->gloader;
+ FT_SubGlyph* subglyph;
+ FT_UInt num_subglyphs;
+
+ num_subglyphs = 0;
+ do
+ {
+ FT_Fixed xx, xy, yy, yx;
+
+ /* check that we can load a new subglyph */
+ error = FT_GlyphLoader_Check_Subglyphs( gloader, num_subglyphs+1 );
+ if (error) goto Fail;
+
+ subglyph = gloader->current.subglyphs + num_subglyphs;
+
+ subglyph->arg1 = subglyph->arg2 = 0;
+
+ subglyph->flags = GET_UShort();
+ subglyph->index = GET_UShort();
+
+ /* read arguments */
+ if ( subglyph->flags & ARGS_ARE_WORDS )
+ {
+ subglyph->arg1 = GET_Short();
+ subglyph->arg2 = GET_Short();
+ }
+ else
+ {
+ subglyph->arg1 = GET_Char();
+ subglyph->arg2 = GET_Char();
+ }
+
+ /* read transform */
+ xx = yy = 0x10000L;
+ xy = yx = 0;
+
+ if ( subglyph->flags & WE_HAVE_A_SCALE )
+ {
+ xx = (FT_Fixed)GET_Short() << 2;
+ yy = xx;
+ }
+ else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE )
+ {
+ xx = (FT_Fixed)GET_Short() << 2;
+ yy = (FT_Fixed)GET_Short() << 2;
+ }
+ else if ( subglyph->flags & WE_HAVE_A_2X2 )
+ {
+ xx = (FT_Fixed)GET_Short() << 2;
+ xy = (FT_Fixed)GET_Short() << 2;
+ yx = (FT_Fixed)GET_Short() << 2;
+ yy = (FT_Fixed)GET_Short() << 2;
+ }
+
+ subglyph->transform.xx = xx;
+ subglyph->transform.xy = xy;
+ subglyph->transform.yx = yx;
+ subglyph->transform.yy = yy;
+
+ num_subglyphs++;
+ }
+ while (subglyph->flags & MORE_COMPONENTS);
+
+ gloader->current.num_subglyphs = num_subglyphs;
+
+#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+ {
+ /* we must undo the ACCESS_Frame in order to point to the */
+ /* composite instructions, if we find some. */
+ /* we will process them later... */
+ /* */
+ loader->ins_pos = FILE_Pos() + stream->cursor - stream->limit;
+ }
+#endif
Fail:
- FORGET_Frame();
return error;
}
-
/*************************************************************************/
/* */
/* <Function> */
@@ -488,104 +613,6 @@
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Composite_Glyph */
- /* */
- /* <Description> */
- /* Loads a composite glyph. */
- /* */
- static
- FT_Error TT_Load_Composite_Glyph( TT_Loader* loader,
- FT_UInt byte_count )
- {
- FT_Error error;
- FT_Stream stream = loader->stream;
- FT_GlyphLoader* gloader = loader->gloader;
- FT_SubGlyph* subglyph;
- FT_UInt num_subglyphs;
-
- if ( ACCESS_Frame( byte_count ) )
- goto Fail;
-
- num_subglyphs = 0;
- do
- {
- FT_Fixed xx, xy, yy, yx;
-
- /* check that we can load a new subglyph */
- error = FT_GlyphLoader_Check_Subglyphs( gloader, num_subglyphs+1 );
- if (error) goto Fail;
-
- subglyph = gloader->current.subglyphs + num_subglyphs;
-
- subglyph->arg1 = subglyph->arg2 = 0;
-
- subglyph->flags = GET_UShort();
- subglyph->index = GET_UShort();
-
- /* read arguments */
- if ( subglyph->flags & ARGS_ARE_WORDS )
- {
- subglyph->arg1 = GET_Short();
- subglyph->arg2 = GET_Short();
- }
- else
- {
- subglyph->arg1 = GET_Char();
- subglyph->arg2 = GET_Char();
- }
-
- /* read transform */
- xx = yy = 0x10000L;
- xy = yx = 0;
-
- if ( subglyph->flags & WE_HAVE_A_SCALE )
- {
- xx = (FT_Fixed)GET_Short() << 2;
- yy = xx;
- }
- else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE )
- {
- xx = (FT_Fixed)GET_Short() << 2;
- yy = (FT_Fixed)GET_Short() << 2;
- }
- else if ( subglyph->flags & WE_HAVE_A_2X2 )
- {
- xx = (FT_Fixed)GET_Short() << 2;
- xy = (FT_Fixed)GET_Short() << 2;
- yx = (FT_Fixed)GET_Short() << 2;
- yy = (FT_Fixed)GET_Short() << 2;
- }
-
- subglyph->transform.xx = xx;
- subglyph->transform.xy = xy;
- subglyph->transform.yx = yx;
- subglyph->transform.yy = yy;
-
- num_subglyphs++;
- }
- while (subglyph->flags & MORE_COMPONENTS);
-
- gloader->current.num_subglyphs = num_subglyphs;
-
-#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
- {
- /* we must undo the ACCESS_Frame in order to point to the */
- /* composite instructions, if we find some. */
- /* we will process them later... */
- /* */
- loader->ins_pos = FILE_Pos() + stream->cursor - stream->limit;
- }
-#endif
-
- FORGET_Frame();
-
- Fail:
- return error;
- }
-
@@ -611,6 +638,7 @@
FT_Fixed x_scale, y_scale;
FT_ULong ins_offset;
FT_GlyphLoader* gloader = loader->gloader;
+ FT_Bool opened_frame = 0;
/* check glyph index */
@@ -618,7 +646,7 @@
if ( index >= (FT_UInt)face->root.num_glyphs )
{
error = TT_Err_Invalid_Glyph_Index;
- goto Fail;
+ goto Exit;
}
loader->glyph_index = glyph_index;
@@ -650,7 +678,6 @@
loader->advance = advance_width;
}
- /* load glyph header */
offset = face->glyph_locations[index];
count = 0;
@@ -676,30 +703,23 @@
if ( loader->exec )
loader->exec->glyphSize = 0;
#endif
- goto Load_End;
+ error = FT_Err_Ok;
+ goto Exit;
}
offset = loader->glyf_offset + offset;
- /* read first glyph header */
- if ( FILE_Seek( offset ) || ACCESS_Frame( 10L ) )
- goto Fail;
+ /* access glyph frame */
+ error = TT_Access_Glyph_Frame( loader, glyph_index, offset, count );
+ if (error) goto Exit;
- contours_count = GET_Short();
+ opened_frame = 1;
- loader->bbox.xMin = GET_Short();
- loader->bbox.yMin = GET_Short();
- loader->bbox.xMax = GET_Short();
- loader->bbox.yMax = GET_Short();
-
- FORGET_Frame();
+ /* read first glyph header */
+ error = TT_Load_Glyph_Header( loader );
+ if (error) goto Fail;
- FT_TRACE5(( "Glyph %ld\n", index ));
- FT_TRACE5(( " # of contours: %d\n", contours_count ));
- FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin,
- loader->bbox.xMax ));
- FT_TRACE5(( " yMin: %4d yMax: %4d\n", loader->bbox.yMin,
- loader->bbox.yMax ));
+ contours_count = loader->n_contours;
count -= 10;
@@ -726,7 +746,7 @@
error = FT_GlyphLoader_Check_Points( gloader, 0, contours_count );
if (error) goto Fail;
- error = TT_Load_Simple_Glyph( loader, count, contours_count );
+ error = TT_Load_Simple_Glyph( loader, contours_count );
if (error) goto Fail;
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
@@ -764,6 +784,9 @@
error = TT_Load_Composite_Glyph( loader, count );
if (error) goto Fail;
+ TT_Forget_Glyph_Frame( loader );
+ opened_frame = 0;
+
/* 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)... */
@@ -777,7 +800,7 @@
glyph->format = ft_glyph_format_composite;
glyph->subglyphs = gloader->base.subglyphs;
- goto Load_End;
+ goto Exit;
}
@@ -1008,10 +1031,11 @@
/***********************************************************************/
/***********************************************************************/
- Load_End:
- error = FT_Err_Ok;
-
Fail:
+ if (opened_frame)
+ TT_Forget_Glyph_Frame( loader );
+
+ Exit:
return error;
}