17 |
|
|
18 |
/*************************************************************************/ |
/*************************************************************************/ |
19 |
/* */ |
/* */ |
20 |
|
/* This file can be compiled without the rest of the FreeType engine, by */ |
21 |
|
/* defining the _STANDALONE_ macro when compiling it. You also need to */ |
22 |
|
/* put the files `ftimage.h' and `ftmisc.h' into the $(incdir) */ |
23 |
|
/* directory. Typically, you should do something like */ |
24 |
|
/* */ |
25 |
|
/* - copy `src/raster/ftraster.c' (this file) to your current directory */ |
26 |
|
/* */ |
27 |
|
/* - copy `include/freetype/ftimage.h' and `src/raster/ftmisc.h' */ |
28 |
|
/* to your current directory */ |
29 |
|
/* */ |
30 |
|
/* - compile `ftraster' with the _STANDALONE_ macro defined, as in */ |
31 |
|
/* */ |
32 |
|
/* cc -c -D_STANDALONE_ ftraster.c */ |
33 |
|
/* */ |
34 |
|
/* The renderer can be initialized with a call to */ |
35 |
|
/* `ft_standard_raster.raster_new'; a bitmap can be generated */ |
36 |
|
/* with a call to `ft_standard_raster.raster_render'. */ |
37 |
|
/* */ |
38 |
|
/* See the comments and documentation in the file `ftimage.h' for more */ |
39 |
|
/* details on how the raster works. */ |
40 |
|
/* */ |
41 |
|
/*************************************************************************/ |
42 |
|
|
43 |
|
|
44 |
|
/*************************************************************************/ |
45 |
|
/* */ |
46 |
/* This is a rewrite of the FreeType 1.x scan-line converter */ |
/* This is a rewrite of the FreeType 1.x scan-line converter */ |
47 |
/* */ |
/* */ |
48 |
/*************************************************************************/ |
/*************************************************************************/ |
49 |
|
|
50 |
|
#ifdef _STANDALONE_ |
51 |
|
|
52 |
|
#include "ftmisc.h" |
53 |
|
#include "ftimage.h" |
54 |
|
|
55 |
|
#else /* !_STANDALONE_ */ |
56 |
|
|
57 |
#include <ft2build.h> |
#include <ft2build.h> |
58 |
#include "ftraster.h" |
#include "ftraster.h" |
59 |
#include FT_INTERNAL_CALC_H /* for FT_MulDiv only */ |
#include FT_INTERNAL_CALC_H /* for FT_MulDiv only */ |
60 |
|
|
61 |
|
#endif /* !_STANDALONE_ */ |
62 |
|
|
63 |
|
|
64 |
/*************************************************************************/ |
/*************************************************************************/ |
65 |
/* */ |
/* */ |
187 |
#endif |
#endif |
188 |
|
|
189 |
#ifndef FT_TRACE |
#ifndef FT_TRACE |
190 |
#define FT_TRACE( x ) do ; while ( 0 ) /* nothing */ |
#define FT_TRACE( x ) do ; while ( 0 ) /* nothing */ |
191 |
|
#define FT_TRACE1( x ) do ; while ( 0 ) /* nothing */ |
192 |
|
#define FT_TRACE6( x ) do ; while ( 0 ) /* nothing */ |
193 |
#endif |
#endif |
194 |
|
|
195 |
#define Raster_Err_None 0 |
#define Raster_Err_None 0 |
199 |
#define Raster_Err_Invalid -4 |
#define Raster_Err_Invalid -4 |
200 |
#define Raster_Err_Unsupported -5 |
#define Raster_Err_Unsupported -5 |
201 |
|
|
202 |
|
#define ft_memset memset |
203 |
|
|
204 |
#else /* _STANDALONE_ */ |
#else /* _STANDALONE_ */ |
205 |
|
|
224 |
#define FT_MEM_SET( d, s, c ) ft_memset( d, s, c ) |
#define FT_MEM_SET( d, s, c ) ft_memset( d, s, c ) |
225 |
#endif |
#endif |
226 |
|
|
227 |
|
#ifndef FT_MEM_ZERO |
228 |
|
#define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count ) |
229 |
|
#endif |
230 |
|
|
231 |
/* FMulDiv means `Fast MulDiv'; it is used in case where `b' is */ |
/* FMulDiv means `Fast MulDiv'; it is used in case where `b' is */ |
232 |
/* typically a small value and the result of a*b is known to fit into */ |
/* typically a small value and the result of a*b is known to fit into */ |
363 |
( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( long ) ) |
( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( long ) ) |
364 |
|
|
365 |
|
|
366 |
#ifdef TT_STATIC_RASTER |
#ifdef FT_STATIC_RASTER |
367 |
|
|
368 |
|
|
369 |
#define RAS_ARGS /* void */ |
#define RAS_ARGS /* void */ |
375 |
#define FT_UNUSED_RASTER do ; while ( 0 ) |
#define FT_UNUSED_RASTER do ; while ( 0 ) |
376 |
|
|
377 |
|
|
378 |
#else /* TT_STATIC_RASTER */ |
#else /* FT_STATIC_RASTER */ |
379 |
|
|
380 |
|
|
381 |
#define RAS_ARGS TRaster_Instance* raster, |
#define RAS_ARGS TRaster_Instance* raster, |
387 |
#define FT_UNUSED_RASTER FT_UNUSED( raster ) |
#define FT_UNUSED_RASTER FT_UNUSED( raster ) |
388 |
|
|
389 |
|
|
390 |
#endif /* TT_STATIC_RASTER */ |
#endif /* FT_STATIC_RASTER */ |
391 |
|
|
392 |
|
|
393 |
typedef struct TRaster_Instance_ TRaster_Instance; |
typedef struct TRaster_Instance_ TRaster_Instance; |
535 |
}; |
}; |
536 |
|
|
537 |
|
|
538 |
#ifdef FT_CONFIG_OPTION_STATIC_RASTER |
#ifdef FT_STATIC_RASTER |
539 |
|
|
540 |
static TRaster_Instance cur_ras; |
static TRaster_Instance cur_ras; |
541 |
#define ras cur_ras |
#define ras cur_ras |
544 |
|
|
545 |
#define ras (*raster) |
#define ras (*raster) |
546 |
|
|
547 |
#endif /* FT_CONFIG_OPTION_STATIC_RASTER */ |
#endif /* FT_STATIC_RASTER */ |
548 |
|
|
549 |
|
|
550 |
/*************************************************************************/ |
/*************************************************************************/ |
2290 |
Short* max ) |
Short* max ) |
2291 |
{ |
{ |
2292 |
/* nothing, really */ |
/* nothing, really */ |
2293 |
FT_UNUSED( raster ); |
FT_UNUSED_RASTER; |
2294 |
FT_UNUSED( min ); |
FT_UNUSED( min ); |
2295 |
FT_UNUSED( max ); |
FT_UNUSED( max ); |
2296 |
} |
} |
2439 |
Horizontal_Sweep_Step( RAS_ARG ) |
Horizontal_Sweep_Step( RAS_ARG ) |
2440 |
{ |
{ |
2441 |
/* Nothing, really */ |
/* Nothing, really */ |
2442 |
FT_UNUSED( raster ); |
FT_UNUSED_RASTER; |
2443 |
} |
} |
2444 |
|
|
2445 |
|
|
2586 |
PProfile right ) |
PProfile right ) |
2587 |
{ |
{ |
2588 |
/* nothing, really */ |
/* nothing, really */ |
2589 |
FT_UNUSED( raster ); |
FT_UNUSED_RASTER; |
2590 |
FT_UNUSED( y ); |
FT_UNUSED( y ); |
2591 |
FT_UNUSED( x1 ); |
FT_UNUSED( x1 ); |
2592 |
FT_UNUSED( x2 ); |
FT_UNUSED( x2 ); |
3060 |
return error; |
return error; |
3061 |
} |
} |
3062 |
|
|
3063 |
return Raster_Err_Ok; |
return Raster_Err_None; |
3064 |
} |
} |
3065 |
|
|
3066 |
|
|
3136 |
return error; |
return error; |
3137 |
} |
} |
3138 |
|
|
3139 |
return Raster_Err_Ok; |
return Raster_Err_None; |
3140 |
} |
} |
3141 |
|
|
3142 |
#else /* !FT_RASTER_OPTION_ANTI_ALIASING */ |
#else /* !FT_RASTER_OPTION_ANTI_ALIASING */ |
3146 |
{ |
{ |
3147 |
FT_UNUSED_RASTER; |
FT_UNUSED_RASTER; |
3148 |
|
|
3149 |
return Raster_Err_Cannot_Render_Glyph; |
return Raster_Err_Unsupported; |
3150 |
} |
} |
3151 |
|
|
3152 |
#endif /* !FT_RASTER_OPTION_ANTI_ALIASING */ |
#endif /* !FT_RASTER_OPTION_ANTI_ALIASING */ |
3169 |
( ( c << 2 ) & 0x0030 ) | |
( ( c << 2 ) & 0x0030 ) | |
3170 |
(c & 0x0003 ); |
(c & 0x0003 ); |
3171 |
|
|
3172 |
raster->count_table[n] = (UInt)c; |
ras.count_table[n] = (UInt)c; |
3173 |
} |
} |
3174 |
|
|
3175 |
#ifdef FT_RASTER_OPTION_ANTI_ALIASING |
#ifdef FT_RASTER_OPTION_ANTI_ALIASING |
3178 |
for ( n = 0; n < 5; n++ ) |
for ( n = 0; n < 5; n++ ) |
3179 |
raster->grays[n] = n * 255 / 4; |
raster->grays[n] = n * 255 / 4; |
3180 |
|
|
3181 |
raster->gray_width = RASTER_GRAY_LINES / 2; |
ras.gray_width = RASTER_GRAY_LINES / 2; |
3182 |
|
|
3183 |
#endif |
#endif |
3184 |
} |
} |
3195 |
ft_black_new( void* memory, |
ft_black_new( void* memory, |
3196 |
FT_Raster *araster ) |
FT_Raster *araster ) |
3197 |
{ |
{ |
3198 |
static FT_RasterRec_ the_raster; |
static TRaster_Instance the_raster; |
3199 |
|
|
3200 |
|
|
3201 |
*araster = &the_raster; |
*araster = (FT_Raster)&the_raster; |
3202 |
FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) ); |
FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) ); |
3203 |
ft_black_init( &the_raster ); |
ft_black_init( &the_raster ); |
3204 |
|
|
3210 |
ft_black_done( FT_Raster raster ) |
ft_black_done( FT_Raster raster ) |
3211 |
{ |
{ |
3212 |
/* nothing */ |
/* nothing */ |
3213 |
raster->init = 0; |
FT_UNUSED( raster ); |
3214 |
} |
} |
3215 |
|
|
3216 |
|
|
3254 |
const char* pool_base, |
const char* pool_base, |
3255 |
long pool_size ) |
long pool_size ) |
3256 |
{ |
{ |
3257 |
if ( raster && pool_base && pool_size >= 4096 ) |
if ( (&ras) && pool_base && pool_size >= 4096 ) |
3258 |
{ |
{ |
3259 |
/* save the pool */ |
/* save the pool */ |
3260 |
raster->buff = (PLong)pool_base; |
ras.buff = (PLong)pool_base; |
3261 |
raster->sizeBuff = raster->buff + pool_size / sizeof ( Long ); |
ras.sizeBuff = ras.buff + pool_size / sizeof ( Long ); |
3262 |
} |
} |
3263 |
} |
} |
3264 |
|
|
3273 |
if ( mode == FT_MAKE_TAG( 'p', 'a', 'l', '5' ) ) |
if ( mode == FT_MAKE_TAG( 'p', 'a', 'l', '5' ) ) |
3274 |
{ |
{ |
3275 |
/* set 5-levels gray palette */ |
/* set 5-levels gray palette */ |
3276 |
raster->grays[0] = palette[0]; |
ras.grays[0] = palette[0]; |
3277 |
raster->grays[1] = palette[1]; |
ras.grays[1] = palette[1]; |
3278 |
raster->grays[2] = palette[2]; |
ras.grays[2] = palette[2]; |
3279 |
raster->grays[3] = palette[3]; |
ras.grays[3] = palette[3]; |
3280 |
raster->grays[4] = palette[4]; |
ras.grays[4] = palette[4]; |
3281 |
} |
} |
3282 |
|
|
3283 |
#else |
#else |
3298 |
const FT_Bitmap* target_map = params->target; |
const FT_Bitmap* target_map = params->target; |
3299 |
|
|
3300 |
|
|
3301 |
if ( !raster || !raster->buff || !raster->sizeBuff ) |
if ( !(&ras) || !ras.buff || !ras.sizeBuff ) |
3302 |
return Raster_Err_Not_Ini; |
return Raster_Err_Not_Ini; |
3303 |
|
|
3304 |
/* return immediately if the outline is empty */ |
/* return immediately if the outline is empty */ |
3322 |
ras.target = *target_map; |
ras.target = *target_map; |
3323 |
|
|
3324 |
return ( ( params->flags & FT_RASTER_FLAG_AA ) |
return ( ( params->flags & FT_RASTER_FLAG_AA ) |
3325 |
? Render_Gray_Glyph( raster ) |
? Render_Gray_Glyph( RAS_VAR ) |
3326 |
: Render_Glyph( raster ) ); |
: Render_Glyph( RAS_VAR ) ); |
3327 |
} |
} |
3328 |
|
|
3329 |
|
|