Hash :
f0df85ba
Author :
Date :
2000-06-22T00:17:42
- MAJOR INTERNAL REDESIGN:
A lot of internal modifications have been performed lately on the
source in order to provide the following enhancements:
- more generic module support:
The FT_Module type is now defined to represent a handle to a given
module. The file <freetype/ftmodule.h> contains the FT_Module_Class
definition, as well as the module-loading public API
The FT_Driver type is still defined, and still represents a pointer
to a font driver. Note that FT_Add_Driver is replaced by FT_Add_Module,
FT_Get_Driver by FT_Get_Module, etc..
- support for generic glyph image types:
The FT_Renderer type is a pointer to a module used to perform various
operations on glyph image.
Each renderer is capable of handling images in a single format
(e.g. ft_glyph_format_outline). Its functions are used to:
- transform an glyph image
- render a glyph image into a bitmap
- return the control box (dimensions) of a given glyph image
The scan converters "ftraster.c" and "ftgrays.c" have been moved
to the new directory "src/renderer", and are used to provide two
default renderer modules.
One corresponds to the "standard" scan-converter, the other to the
"smooth" one.
The current renderer can be set through the new function
FT_Set_Renderer.
The old raster-related function FT_Set_Raster, FT_Get_Raster and
FT_Set_Raster_Mode have now disappeared, in favor of the new:
FT_Get_Renderer
FT_Set_Renderer
see the file <freetype/ftrender.h> for more details..
These changes were necessary to properly support different scalable
formats in the future, like bi-color glyphs, etc..
- glyph loader object:
A new internal object, called a 'glyph loader' has been introduced
in the base layer. It is used by all scalable format font drivers
to load glyphs and composites.
This object has been created to reduce the code size of each driver,
as each one of them basically re-implemented its functionality.
See <freetype/internal/ftobjs.h> and the FT_GlyphLoader type for
more information..
- FT_GlyphSlot had new fields:
In order to support extended features (see below), the FT_GlyphSlot
structure has a few new fields:
linearHoriAdvance: this field gives the linearly scaled (i.e.
scaled but unhinted) advance width for the glyph,
expressed as a 16.16 fixed pixel value. This
is useful to perform WYSIWYG text.
linearVertAdvance: this field gives the linearly scaled advance
height for the glyph (relevant in vertical glyph
layouts only). This is useful to perform
WYSIWYG text.
Note that the two above field replace the removed "metrics2" field
in the glyph slot.
advance: this field is a vector that gives the transformed
advance for the glyph. By default, it corresponds
to the advance width, unless FT_LOAD_VERTICAL_LAYOUT
was specified when calling FT_Load_Glyph or FT_Load_Char
bitmap_left: this field gives the distance in integer pixels from
the current pen position to the left-most pixel of
a glyph image WHEN IT IS A BITMAP. It is only valid
when the "format" field is set to
"ft_glyph_format_bitmap", for example, after calling
the new function FT_Render_Glyph.
bitmap_top: this field gives the distance in integer pixels from
the current pen position (located on the baseline) to
the top-most pixel of the glyph image WHEN IT IS A
BITMAP. Positive values correspond to upwards Y.
loader: this is a new private field for the glyph slot. Client
applications should not touch it..
- support for transforms and direct rendering in FT_Load_Glyph:
Most of the functionality found in <freetype/ftglyph.h> has been
moved to the core library. Hence, the following:
- a transform can be specified for a face through FT_Set_Transform.
this transform is applied by FT_Load_Glyph to scalable glyph images
(i.e. NOT TO BITMAPS) before the function returns, unless the
bit flag FT_LOAD_IGNORE_TRANSFORM was set in the load flags..
- once a glyph image has been loaded, it can be directly converted to
a bitmap by using the new FT_Render_Glyph function. Note that this
function takes the glyph image from the glyph slot, and converts
it to a bitmap whose properties are returned in "face.glyph.bitmap",
"face.glyph.bitmap_left" and "face.glyph.bitmap_top". The original
native image might be lost after the conversion.
- when using the new bit flag FT_LOAD_RENDER, the FT_Load_Glyph
and FT_Load_Char functions will call FT_Render_Glyph automatically
when needed.
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
/****************************************************************************/
/* */
/* The FreeType project - a Free and Portable Quality TrueType Renderer. */
/* */
/* Copyright 1996-1998 by */
/* D. Turner, R.Wilhelm, and W. Lemberg */
/* */
/* fttimer: A simple performance benchmark. Now with graylevel rendering */
/* with the '-g' option. */
/* */
/* Be aware that the timer program benchmarks different things */
/* in each release of the FreeType library. Thus, performance */
/* should only be compared between similar release numbers. */
/* */
/* */
/* NOTE: This is just a test program that is used to show off and */
/* debug the current engine. In no way does it shows the final */
/* high-level interface that client applications will use. */
/* */
/****************************************************************************/
#include <freetype/freetype.h>
#include <freetype/ftrender.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h> /* for clock() */
#include "graph.h"
#include <freetype/ftgrays.h>
/* SunOS 4.1.* does not define CLOCKS_PER_SEC, so include <sys/param.h> */
/* to get the HZ macro which is the equivalent. */
#if defined(__sun__) && !defined(SVR4) && !defined(__SVR4)
#include <sys/param.h>
#define CLOCKS_PER_SEC HZ
#endif
#define CHARSIZE 400 /* character point size */
#define MAX_GLYPHS 512 /* Maximum number of glyphs rendered at one time */
char Header[128];
FT_Error error;
FT_Library library;
FT_Face face;
FT_Size size;
FT_GlyphSlot glyph;
FT_Outline outline;
FT_Pos* cur_x;
FT_Pos* cur_y;
unsigned short* cur_endContour;
unsigned char* cur_touch;
FT_Outline outlines[MAX_GLYPHS];
int num_glyphs;
int tab_glyphs;
int cur_glyph;
int cur_point;
unsigned short cur_contour;
int pixel_size = CHARSIZE;
int repeat_count = 1;
int use_grays = 0;
FT_Bitmap Bit;
grBitmap bit;
int Fail;
int Num;
int vio_Height, vio_Width;
short visual; /* display glyphs while rendering */
short antialias; /* smooth fonts with gray levels */
short force_low;
#define RASTER_BUFF_SIZE 128000
char raster_buff[ RASTER_BUFF_SIZE ];
static void Clear_Buffer();
static void Panic( const char* message )
{
fprintf( stderr, "%s\n error code = 0x%04x\n", message, error );
}
/*******************************************************************/
/* */
/* Get_Time: */
/* */
/* Returns the current time in milliseconds. */
/* */
/*******************************************************************/
long Get_Time( void )
{
return clock() * 10000 / CLOCKS_PER_SEC;
}
/*******************************************************************/
/* */
/* Init_Engine: */
/* */
/* Allocates bitmap, render pool and other structs... */
/* */
/*******************************************************************/
void Init_Engine( void )
{
Bit.rows = bit.rows;
Bit.width = bit.width;
Bit.pitch = bit.pitch;
Bit.buffer = bit.buffer;
Bit.pixel_mode = antialias ? ft_pixel_mode_grays : ft_pixel_mode_mono;
Bit.num_grays = bit.grays;
Clear_Buffer();
}
/*******************************************************************/
/* */
/* Clear_Buffer: */
/* */
/* Clears current bitmap. */
/* */
/*******************************************************************/
static void Clear_Buffer( void )
{
long size = Bit.rows * Bit.pitch;
memset( Bit.buffer, 0, size );
}
/*******************************************************************/
/* */
/* LoadTrueTypeChar: */
/* */
/* Loads a glyph into memory. */
/* */
/*******************************************************************/
FT_Error LoadChar( int idx )
{
error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT );
if ( error )
return error;
glyph->outline.flags |= ft_outline_single_pass |
ft_outline_ignore_dropouts;
if (force_low)
glyph->outline.flags &= ~ft_outline_high_precision;
/* debugging */
#if 0
if ( idx == 0 && !visual )
{
printf( "points = %d\n", outline.points );
for ( j = 0; j < outline.points; j++ )
printf( "%02x (%01hx,%01hx)\n",
j, outline.xCoord[j], outline.yCoord[j] );
printf( "\n" );
}
#endif
/* create a new outline */
FT_Outline_New( library,
glyph->outline.n_points,
glyph->outline.n_contours,
&outlines[cur_glyph] );
/* copy the glyph outline into it */
glyph->outline.flags |= ft_outline_single_pass;
if (force_low)
glyph->outline.flags &= ~ft_outline_high_precision;
FT_Outline_Copy( &glyph->outline, &outlines[cur_glyph] );
/* center outline around 0 */
{
FT_BBox bbox;
FT_Outline_Get_CBox( &glyph->outline, &bbox );
FT_Outline_Translate( &outlines[cur_glyph],
- ( bbox.xMax - bbox.xMin )/2,
- ( bbox.yMax - bbox.yMin )/2 );
}
/* translate it */
FT_Outline_Translate( &outlines[cur_glyph],
Bit.width * 32 ,
Bit.rows * 32 );
cur_glyph++;
return FT_Err_Ok;
}
/*******************************************************************/
/* */
/* ConvertRaster: */
/* */
/* Performs scan conversion. */
/* */
/*******************************************************************/
FT_Error ConvertRaster( int index )
{
outlines[index].flags |= ~ft_outline_single_pass;
return FT_Outline_Get_Bitmap( library, &outlines[index], &Bit );
}
static void Usage()
{
fprintf( stderr, "fttimer: simple performance timer -- part of the FreeType project\n" );
fprintf( stderr, "-----------------------------------------------------------------\n\n" );
fprintf( stderr, "Usage: fttimer [options] fontname[.ttf|.ttc]\n\n" );
fprintf( stderr, "options:\n");
fprintf( stderr, " -r : repeat count to be used (default is 1)\n" );
fprintf( stderr, " -s : character pixel size (default is 600)\n" );
fprintf( stderr, " -v : display results..\n" );
fprintf( stderr, " -g : render anti-aliased glyphs\n" );
fprintf( stderr, " -a : use smooth anti-aliaser\n" );
fprintf( stderr, " -l : force low quality even at small sizes\n" );
exit(1);
}
int main( int argc, char** argv )
{
int i, total, base, rendered_glyphs;
char filename[128 + 4];
char alt_filename[128 + 4];
char* execname;
grSurface* surface = 0;
long t, t0, tz0;
execname = argv[0];
antialias = 0;
visual = 0;
force_low = 0;
while ( argc > 1 && argv[1][0] == '-' )
{
switch ( argv[1][1] )
{
case 'g':
antialias = 1;
break;
case 'a':
use_grays = 1;
break;
case 'l':
force_low = 1;
break;
case 'v':
visual = 1;
break;
case 's':
argc--;
argv++;
if ( argc < 2 ||
sscanf( argv[1], "%d", &pixel_size ) != 1 )
Usage();
break;
case 'r':
argc--;
argv++;
if ( argc < 2 ||
sscanf( argv[1], "%d", &repeat_count ) != 1 )
Usage();
if (repeat_count < 1)
repeat_count = 1;
break;
default:
fprintf( stderr, "Unknown argument '%s'!\n", argv[1] );
Usage();
}
argc--;
argv++;
}
if ( argc != 2 )
Usage();
i = strlen( argv[1] );
while ( i > 0 && argv[1][i] != '\\' )
{
if ( argv[1][i] == '.' )
i = 0;
i--;
}
filename[128] = '\0';
alt_filename[128] = '\0';
strncpy( filename, argv[1], 128 );
strncpy( alt_filename, argv[1], 128 );
if ( i >= 0 )
{
strncpy( filename + strlen( filename ), ".ttf", 4 );
strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 );
}
/* Initialize engine */
if ( (error = FT_Init_FreeType( &library )) )
Panic( "Error while initializing engine" );
/* set-up smooth anti-aliaser */
if (use_grays)
{
FT_Renderer smooth;
smooth = (FT_Renderer)FT_Get_Module( library, "smooth renderer" );
if (!smooth) Panic( "Could not initialize smooth anti-aliasing renderer" );
FT_Set_Renderer( library, smooth, 0, 0 );
}
/* Load face */
error = FT_New_Face( library, filename, 0, &face );
if ( error == FT_Err_Cannot_Open_Stream )
Panic( "Could not find/open font resource" );
else if ( error )
Panic( "Error while opening font resource" );
/* get face properties and allocate preload arrays */
num_glyphs = face->num_glyphs;
glyph = face->glyph;
tab_glyphs = MAX_GLYPHS;
if ( tab_glyphs > num_glyphs )
tab_glyphs = num_glyphs;
/* create size */
error = FT_Set_Pixel_Sizes( face, pixel_size, pixel_size );
if ( error ) Panic( "Could not reset instance" );
bit.mode = antialias ? gr_pixel_mode_gray : gr_pixel_mode_mono;
bit.width = 640;
bit.rows = 480;
bit.grays = 128;
if ( visual )
{
if ( !grInitDevices() )
Panic( "Could not initialize graphics.\n" );
surface = grNewSurface( 0, &bit );
if (!surface)
Panic( "Could not open graphics window/screen.\n" );
}
else
{
if ( grNewBitmap( bit.mode,
bit.grays,
bit.width,
bit.rows,
&bit ) )
Panic( "Could not create rendering buffer.\n" );
}
Init_Engine();
Num = 0;
Fail = 0;
total = num_glyphs;
base = 0;
rendered_glyphs = 0;
t0 = 0; /* Initial time */
tz0 = Get_Time();
while ( total > 0 )
{
int repeat;
/* First, preload 'tab_glyphs' in memory */
cur_glyph = 0;
cur_point = 0;
cur_contour = 0;
printf( "loading %d glyphs", tab_glyphs );
for ( Num = 0; Num < tab_glyphs; Num++ )
{
error = LoadChar( base + Num );
if ( error )
Fail++;
total--;
}
base += tab_glyphs;
if ( tab_glyphs > total )
tab_glyphs = total;
printf( ", rendering... " );
/* Now, render the loaded glyphs */
t = Get_Time();
for ( repeat = 0; repeat < repeat_count; repeat++ )
{
for ( Num = 0; Num < cur_glyph; Num++ )
{
if ( (error = ConvertRaster( Num )) )
Fail++;
else
{
rendered_glyphs ++;
if ( Num == 0 && visual )
{
sprintf( Header, "Glyph: %5d", Num );
grSetTitle( surface, Header );
grRefreshSurface( surface );
Clear_Buffer();
}
}
}
}
t = Get_Time() - t;
if ( t < 0 )
t += 1000 * 60 * 60;
printf( " = %f s\n", (double)t / 10000 );
t0 += t;
/* Now free all loaded outlines */
for ( Num = 0; Num < cur_glyph; Num++ )
FT_Outline_Done( library, &outlines[Num] );
}
tz0 = Get_Time() - tz0;
FT_Done_Face( face );
printf( "\n" );
printf( "rendered glyphs = %d\n", rendered_glyphs );
printf( "render time = %f s\n", (double)t0 / 10000 );
printf( "fails = %d\n", Fail );
printf( "average glyphs/s = %f\n",
(double)rendered_glyphs / t0 * 10000 );
printf( "total timing = %f s\n", (double)tz0 / 10000 );
printf( "Fails = %d\n", Fail );
FT_Done_FreeType( library );
exit( 0 ); /* for safety reasons */
return 0; /* never reached */
}
/* End */