91 #define FT_COMPONENT trace_smooth 98 #define FT_ERR_XCAT( x, y ) x ## y 99 #define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y ) 106 #ifdef FT_DEBUG_LEVEL_TRACE 115 #define FT_UINT_MAX UINT_MAX 116 #define FT_INT_MAX INT_MAX 118 #define ft_memset memset 120 #define ft_setjmp setjmp 121 #define ft_longjmp longjmp 122 #define ft_jmp_buf jmp_buf 127 #define ErrRaster_Invalid_Mode -2 128 #define ErrRaster_Invalid_Outline -1 129 #define ErrRaster_Invalid_Argument -3 130 #define ErrRaster_Memory_Overflow -4 132 #define FT_BEGIN_HEADER 133 #define FT_END_HEADER 143 #define FT_UNUSED( x ) (x) = (x) 148 #ifdef FT_DEBUG_LEVEL_TRACE 151 FT_Message(
const char* fmt,
158 vfprintf( stderr, fmt, ap );
179 #define FT_TRACE5( varformat ) FT_Message varformat 182 #define FT_TRACE7( varformat ) FT_Message varformat 185 #define FT_ERROR( varformat ) FT_Message varformat 188 #define FT_THROW( e ) \ 189 ( FT_Throw( FT_ERR_CAT( ErrRaster, e ), \ 192 FT_ERR_CAT( ErrRaster, e ) ) 196 #define FT_TRACE5( x ) do { } while ( 0 ) 197 #define FT_TRACE7( x ) do { } while ( 0 ) 198 #define FT_ERROR( x ) do { } while ( 0 ) 199 #define FT_THROW( e ) FT_ERR_CAT( ErrRaster_, e ) 205 #define FT_DEFINE_OUTLINE_FUNCS( class_, \ 206 move_to_, line_to_, \ 207 conic_to_, cubic_to_, \ 209 static const FT_Outline_Funcs class_ = \ 219 #define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_, \ 220 raster_new_, raster_reset_, \ 221 raster_set_mode_, raster_render_, \ 223 const FT_Raster_Funcs class_ = \ 237 #include <ft2build.h> 239 #include FT_INTERNAL_OBJECTS_H 240 #include FT_INTERNAL_DEBUG_H 241 #include FT_OUTLINE_H 247 #define Smooth_Err_Invalid_Mode Smooth_Err_Cannot_Render_Glyph 248 #define Smooth_Err_Memory_Overflow Smooth_Err_Out_Of_Memory 249 #define ErrRaster_Memory_Overflow Smooth_Err_Out_Of_Memory 256 #define FT_MEM_SET( d, s, c ) ft_memset( d, s, c ) 260 #define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count ) 270 #ifndef FT_STATIC_RASTER 272 #define RAS_ARG gray_PWorker worker 273 #define RAS_ARG_ gray_PWorker worker, 275 #define RAS_VAR worker 276 #define RAS_VAR_ worker, 296 #define ONE_PIXEL ( 1L << PIXEL_BITS ) 297 #define PIXEL_MASK ( -1L << PIXEL_BITS ) 298 #define TRUNC( x ) ( (TCoord)( (x) >> PIXEL_BITS ) ) 299 #define SUBPIXELS( x ) ( (TPos)(x) << PIXEL_BITS ) 300 #define FLOOR( x ) ( (x) & -ONE_PIXEL ) 301 #define CEILING( x ) ( ( (x) + ONE_PIXEL - 1 ) & -ONE_PIXEL ) 302 #define ROUND( x ) ( ( (x) + ONE_PIXEL / 2 ) & -ONE_PIXEL ) 305 #define UPSCALE( x ) ( (x) << ( PIXEL_BITS - 6 ) ) 306 #define DOWNSCALE( x ) ( (x) >> ( PIXEL_BITS - 6 ) ) 308 #define UPSCALE( x ) ( (x) >> ( 6 - PIXEL_BITS ) ) 309 #define DOWNSCALE( x ) ( (x) << ( 6 - PIXEL_BITS ) ) 336 #if FT_UINT_MAX == 0xFFFFU 346 #define FT_MAX_GRAY_SPANS 32 351 typedef struct TCell_
361 typedef struct gray_TWorker_
366 TPos count_ex, count_ey;
392 void* render_span_data;
409 #ifndef FT_STATIC_RASTER 410 #define ras (*worker) 416 typedef struct gray_TRaster_
437 ras.buffer_size = byte_size;
463 ras.min_ex =
ras.max_ex = 0;
464 ras.min_ey =
ras.max_ey = 0;
468 ras.min_ex =
ras.max_ex = vec->
x;
469 ras.min_ey =
ras.max_ey = vec->
y;
473 for ( ; vec <
limit; vec++ )
479 if ( x <
ras.min_ex )
ras.min_ex =
x;
480 if ( x >
ras.max_ex )
ras.max_ex =
x;
481 if ( y <
ras.min_ey )
ras.min_ey =
y;
482 if ( y >
ras.max_ey )
ras.max_ey =
y;
486 ras.min_ex =
ras.min_ex >> 6;
487 ras.min_ey =
ras.min_ey >> 6;
488 ras.max_ex = (
ras.max_ex + 63 ) >> 6;
489 ras.max_ey = (
ras.max_ey + 63 ) >> 6;
504 if ( x >
ras.count_ex )
507 pcell = &
ras.ycells[
ras.ey];
511 if ( cell ==
NULL || cell->x > x )
520 if (
ras.num_cells >=
ras.max_cells )
523 cell =
ras.cells +
ras.num_cells++;
539 if ( !
ras.invalid && (
ras.area |
ras.cover ) )
544 cell->area +=
ras.area;
545 cell->cover +=
ras.cover;
572 if ( ex >
ras.max_ex )
580 if ( ex !=
ras.ex || ey !=
ras.ey )
592 ras.invalid = ( (unsigned)ey >= (
unsigned)
ras.count_ey ||
593 ex >=
ras.count_ex );
605 if ( ex >
ras.max_ex )
608 if ( ex <
ras.min_ex )
633 TCoord ex1, ex2, fx1, fx2, delta,
mod, lift, rem;
657 ras.area += (
TArea)(( fx1 + fx2 ) * delta);
671 p = fx1 * ( y2 - y1 );
677 delta = (
TCoord)( p / dx );
685 ras.area += (
TArea)(( fx1 + first ) * delta);
695 lift = (
TCoord)( p / dx );
740 int delta, rem, lift, incr;
766 if ( min >=
ras.max_ey || max <
ras.min_ey )
773 gray_render_scanline(
RAS_VAR_ ey1,
ras.x, fy1, to_x, fy2 );
794 delta = (
int)( first - fy1 );
802 area = (
TArea)two_fx * delta;
832 delta = (
int)( p / dy );
833 mod = (
int)( p % dy );
849 lift = (
int)( p / dy );
850 rem = (
int)( p % dy );
869 gray_render_scanline(
RAS_VAR_ ey1, x,
879 gray_render_scanline(
RAS_VAR_ ey1, x,
896 base[4].
x = base[2].
x;
898 a = base[3].
x = ( base[2].
x +
b ) / 2;
899 b = base[1].
x = ( base[0].
x +
b ) / 2;
900 base[2].
x = ( a +
b ) / 2;
902 base[4].
y = base[2].
y;
904 a = base[3].
y = ( base[2].
y +
b ) / 2;
905 b = base[1].
y = ( base[0].
y +
b ) / 2;
906 base[2].
y = ( a +
b ) / 2;
921 levels =
ras.lev_stack;
932 dx =
FT_ABS( arc[2].
x + arc[0].
x - 2 * arc[1].
x );
933 dy =
FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y );
941 min = max = arc[0].
y;
944 if ( y < min ) min =
y;
945 if ( y > max ) max =
y;
948 if ( y < min ) min =
y;
949 if ( y > max ) max =
y;
968 gray_split_conic( arc );
971 levels[
top] = levels[top - 1] = level - 1;
976 gray_render_line(
RAS_VAR_ arc[0].x, arc[0].y );
980 }
while ( top >= 0 );
990 base[6].
x = base[3].
x;
993 base[1].
x = a = ( base[0].
x +
c ) / 2;
994 base[5].
x = b = ( base[3].
x + d ) / 2;
996 base[2].
x = a = ( a +
c ) / 2;
997 base[4].
x = b = ( b +
c ) / 2;
998 base[3].
x = ( a +
b ) / 2;
1000 base[6].
y = base[3].
y;
1003 base[1].
y = a = ( base[0].
y +
c ) / 2;
1004 base[5].
y = b = ( base[3].
y + d ) / 2;
1006 base[2].
y = a = ( a +
c ) / 2;
1007 base[4].
y = b = ( b +
c ) / 2;
1008 base[3].
y = ( a +
b ) / 2;
1021 arc =
ras.bez_stack;
1032 min = max = arc[0].
y;
1063 TPos dx, dy, dx_, dy_;
1064 TPos dx1, dy1, dx2, dy2;
1069 dx = arc[3].
x - arc[0].
x;
1070 dy = arc[3].
y - arc[0].
y;
1098 L = ( dx_ > dy_ ? 236 * dx_ + 97 * dy_
1099 : 97 * dx_ + 236 * dy_ ) >> 8;
1109 dx1 = arc[1].
x - arc[0].
x;
1110 dy1 = arc[1].
y - arc[0].
y;
1111 s =
FT_ABS( dy * dx1 - dx * dy1 );
1117 dx2 = arc[2].
x - arc[0].
x;
1118 dy2 = arc[2].
y - arc[0].
y;
1119 s =
FT_ABS( dy * dx2 - dx * dy2 );
1127 if ( dx1 * ( dx1 - dx ) + dy1 * ( dy1 - dy ) > 0 ||
1128 dx2 * ( dx2 - dx ) + dy2 * ( dy2 - dy ) > 0 )
1136 gray_split_cubic( arc );
1141 gray_render_line(
RAS_VAR_ arc[0].
x, arc[0].y );
1143 if ( arc ==
ras.bez_stack )
1183 gray_conic_to(
const FT_Vector* control,
1187 gray_render_conic(
RAS_VAR_ control, to );
1193 gray_cubic_to(
const FT_Vector* control1,
1198 gray_render_cubic(
RAS_VAR_ control1, control2, to );
1204 gray_render_span(
int y,
1216 p += (unsigned)( ( map->
rows - 1 ) * map->
pitch );
1220 unsigned char coverage = spans->
coverage;
1229 if ( spans->
len >= 8 )
1233 unsigned char*
q = p + spans->
x;
1236 switch ( spans->
len )
1238 case 7: *q++ = (
unsigned char)coverage;
1239 case 6: *q++ = (
unsigned char)coverage;
1240 case 5: *q++ = (
unsigned char)coverage;
1241 case 4: *q++ = (
unsigned char)coverage;
1242 case 3: *q++ = (
unsigned char)coverage;
1243 case 2: *q++ = (
unsigned char)coverage;
1244 case 1: *q = (
unsigned char)coverage;
1273 coverage = -coverage;
1279 if ( coverage > 256 )
1280 coverage = 512 - coverage;
1281 else if ( coverage == 256 )
1287 if ( coverage >= 256 )
1305 count =
ras.num_gray_spans;
1306 span =
ras.gray_spans + count - 1;
1309 (
int)span->
x + span->
len == (
int)
x &&
1312 span->
len = (
unsigned short)( span->
len + acount );
1318 if (
ras.render_span && count > 0 )
1319 ras.render_span(
ras.span_y, count,
ras.gray_spans,
1320 ras.render_span_data );
1322 #ifdef FT_DEBUG_LEVEL_TRACE 1330 span =
ras.gray_spans;
1331 for ( n = 0; n <
count; n++, span++ )
1339 ras.num_gray_spans = 0;
1343 span =
ras.gray_spans;
1350 span->
len = (
unsigned short)acount;
1351 span->
coverage = (
unsigned char)coverage;
1353 ras.num_gray_spans++;
1358 #ifdef FT_DEBUG_LEVEL_TRACE 1368 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1373 printf(
"%3d:", yindex );
1375 for ( cell =
ras.ycells[yindex]; cell !=
NULL; cell = cell->next )
1376 printf(
" (%3ld, c:%4ld, a:%6d)", cell->x, cell->cover, cell->area );
1392 if (
ras.num_cells == 0 )
1395 ras.num_gray_spans = 0;
1399 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1406 for ( ; cell !=
NULL; cell = cell->next )
1411 if ( cell->x > x && cover != 0 )
1415 cover += cell->cover;
1416 area = cover * (
ONE_PIXEL * 2 ) - cell->area;
1418 if ( area != 0 && cell->x >= 0 )
1419 gray_hline(
RAS_VAR_ cell->x, yindex, area, 1 );
1429 if (
ras.render_span &&
ras.num_gray_spans > 0 )
1430 ras.render_span(
ras.span_y,
ras.num_gray_spans,
1431 ras.gray_spans,
ras.render_span_data );
1433 #ifdef FT_DEBUG_LEVEL_TRACE 1435 if (
ras.num_gray_spans > 0 )
1442 span =
ras.gray_spans;
1443 for ( n = 0; n <
ras.num_gray_spans; n++, span++ )
1498 #define SCALED( x ) ( ( (x) << shift ) - delta ) 1518 if ( !outline || !func_interface )
1519 return FT_THROW( Invalid_Argument );
1521 shift = func_interface->
shift;
1522 delta = func_interface->
delta;
1530 FT_TRACE5((
"FT_Outline_Decompose: Outline %d\n", n ));
1534 goto Invalid_Outline;
1535 limit = outline->
points + last;
1541 v_last = outline->
points[last];
1545 v_control = v_start;
1553 goto Invalid_Outline;
1570 v_start.
x = ( v_start.
x + v_last.
x ) / 2;
1571 v_start.
y = ( v_start.
y + v_last.
y ) / 2;
1580 v_start.
x / 64.0, v_start.
y / 64.0 ));
1581 error = func_interface->
move_to( &v_start, user );
1585 while ( point < limit )
1602 vec.
x / 64.0, vec.
y / 64.0 ));
1603 error = func_interface->
line_to( &vec, user );
1614 if ( point < limit )
1630 " with control (%.2f, %.2f)\n",
1631 vec.
x / 64.0, vec.
y / 64.0,
1632 v_control.
x / 64.0, v_control.
y / 64.0 ));
1633 error = func_interface->
conic_to( &v_control, &vec, user );
1640 goto Invalid_Outline;
1642 v_middle.
x = ( v_control.
x + vec.
x ) / 2;
1643 v_middle.
y = ( v_control.
y + vec.
y ) / 2;
1646 " with control (%.2f, %.2f)\n",
1647 v_middle.
x / 64.0, v_middle.
y / 64.0,
1648 v_control.
x / 64.0, v_control.
y / 64.0 ));
1649 error = func_interface->
conic_to( &v_control, &v_middle, user );
1658 " with control (%.2f, %.2f)\n",
1659 v_start.
x / 64.0, v_start.
y / 64.0,
1660 v_control.
x / 64.0, v_control.
y / 64.0 ));
1661 error = func_interface->
conic_to( &v_control, &v_start, user );
1669 if ( point + 1 > limit ||
1671 goto Invalid_Outline;
1682 if ( point <= limit )
1691 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1692 vec.
x / 64.0, vec.
y / 64.0,
1693 vec1.
x / 64.0, vec1.
y / 64.0,
1694 vec2.
x / 64.0, vec2.
y / 64.0 ));
1695 error = func_interface->
cubic_to( &vec1, &vec2, &vec, user );
1702 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1703 v_start.
x / 64.0, v_start.
y / 64.0,
1704 vec1.
x / 64.0, vec1.
y / 64.0,
1705 vec2.
x / 64.0, vec2.
y / 64.0 ));
1706 error = func_interface->
cubic_to( &vec1, &vec2, &v_start, user );
1714 v_start.
x / 64.0, v_start.
y / 64.0 ));
1715 error = func_interface->
line_to( &v_start, user );
1724 FT_TRACE5((
"FT_Outline_Decompose: Done\n", n ));
1728 FT_TRACE5((
"FT_Outline_Decompose: Error %d\n", error ));
1732 return FT_THROW( Invalid_Outline );
1738 typedef struct gray_TBand_
1754 gray_convert_glyph_inner(
RAS_ARG )
1757 volatile int error = 0;
1759 #ifdef FT_CONFIG_OPTION_PIC 1761 Init_Class_func_interface(&func_interface);
1770 error =
FT_THROW( Memory_Overflow );
1781 int volatile n, num_bands;
1790 clip = &
ras.clip_box;
1806 num_bands = (
int)( (
ras.max_ey -
ras.min_ey ) /
ras.band_size );
1807 if ( num_bands == 0 )
1809 if ( num_bands >= 39 )
1817 for ( n = 0; n < num_bands; n++, min =
max )
1819 max = min +
ras.band_size;
1820 if ( n == num_bands - 1 || max > max_y )
1827 while ( band >= bands )
1835 long cell_start, cell_end, cell_mod;
1839 ras.ycount = band->max - band->min;
1842 cell_mod = cell_start %
sizeof (
TCell );
1844 cell_start +=
sizeof (
TCell ) - cell_mod;
1846 cell_end =
ras.buffer_size;
1847 cell_end -= cell_end %
sizeof (
TCell );
1849 cells_max = (
PCell)( (
char*)
ras.buffer + cell_end );
1850 ras.cells = (
PCell)( (
char*)
ras.buffer + cell_start );
1851 if (
ras.cells >= cells_max )
1854 ras.max_cells = cells_max -
ras.cells;
1855 if (
ras.max_cells < 2 )
1858 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1864 ras.min_ey = band->min;
1865 ras.max_ey = band->max;
1866 ras.count_ey = band->max - band->min;
1868 error = gray_convert_glyph_inner(
RAS_VAR );
1883 middle = bottom + ( ( top -
bottom ) >> 1 );
1887 if ( middle == bottom )
1889 #ifdef FT_DEBUG_LEVEL_TRACE 1890 FT_TRACE7((
"gray_convert_glyph: rotten glyph\n" ));
1895 if ( bottom-top >=
ras.band_size )
1899 band[1].max = middle;
1900 band[0].min = middle;
1906 if (
ras.band_shoot > 8 &&
ras.band_size > 16 )
1907 ras.band_size =
ras.band_size / 2;
1922 if ( !raster || !raster->buffer || !raster->buffer_size )
1923 return FT_THROW( Invalid_Argument );
1926 return FT_THROW( Invalid_Outline );
1933 return FT_THROW( Invalid_Outline );
1937 return FT_THROW( Invalid_Outline );
1939 worker = raster->worker;
1945 return FT_THROW( Invalid_Argument );
1948 if ( !target_map->width || !target_map->rows )
1951 if ( !target_map->buffer )
1952 return FT_THROW( Invalid_Argument );
1963 ras.clip_box.xMin = 0;
1964 ras.clip_box.yMin = 0;
1965 ras.clip_box.xMax = target_map->width;
1966 ras.clip_box.yMax = target_map->rows;
1972 ras.clip_box.xMin = -32768L;
1973 ras.clip_box.yMin = -32768L;
1974 ras.clip_box.xMax = 32767L;
1975 ras.clip_box.yMax = 32767L;
1978 gray_init_cells(
RAS_VAR_ raster->buffer, raster->buffer_size );
1980 ras.outline = *outline;
1983 ras.band_size = raster->band_size;
1984 ras.num_gray_spans = 0;
1989 ras.render_span_data = params->
user;
1993 ras.target = *target_map;
1995 ras.render_span_data = &
ras;
1998 return gray_convert_glyph(
RAS_VAR );
2008 gray_raster_new(
void* memory,
2017 FT_MEM_ZERO( &the_raster,
sizeof ( the_raster ) );
2043 raster->memory = memory;
2073 if ( pool_base && pool_size >= (
long)
sizeof (
gray_TWorker ) + 2048 )
2078 rast->worker = worker;
2079 rast->buffer = pool_base +
2081 sizeof (
TCell ) - 1 ) &
2082 ~(
sizeof (
TCell ) - 1 ) );
2083 rast->buffer_size = (
long)( ( pool_base + pool_size ) -
2084 (
char*)rast->buffer ) &
2085 ~(
sizeof (
TCell ) - 1 );
2086 rast->band_size = (
int)( rast->buffer_size /
2091 rast->buffer =
NULL;
2092 rast->buffer_size = 0;
2093 rast->worker =
NULL;
#define FT_ALLOC(ptr, size)
FT_Outline_LineToFunc line_to
struct gray_TWorker_ * gray_PWorker
#define FT_Raster_Done_Func
FT_DEFINE_OUTLINE_FUNCS(func_interface,(FT_Outline_MoveTo_Func) gray_move_to,(FT_Outline_LineTo_Func) gray_line_to,(FT_Outline_ConicTo_Func) gray_conic_to,(FT_Outline_CubicTo_Func) gray_cubic_to, 0, 0) static int gray_convert_glyph_inner(RAS_ARG)
GLboolean GLboolean GLboolean GLboolean a
fvec2 vec2
Defined as: 'typedef fvec2 vec2'. See also VL_PIPELINE_PRECISION.
struct FT_RasterRec_ * FT_Raster
#define FT_CURVE_TAG_CUBIC
GLint GLint GLint GLint GLint GLint y
#define FT_Raster_Set_Mode_Func
#define FT_Raster_New_Func
GLdouble GLdouble GLdouble GLdouble q
return FT_THROW(Missing_Property)
#define FT_MEM_SET(d, s, c)
#define FT_RASTER_FLAG_AA
GLenum GLenum GLvoid GLvoid GLvoid * span
GLint GLint GLint GLint GLint x
#define FT_Outline_ConicTo_Func
GLboolean GLboolean GLboolean b
struct gray_TWorker_ gray_TWorker
#define FT_RASTER_FLAG_CLIP
#define FT_OUTLINE_EVEN_ODD_FILL
#define FT_Outline_MoveTo_Func
#define FT_Raster_Render_Func
struct gray_TBand_ gray_TBand
FT_Outline_CubicToFunc cubic_to
float min(float a, float b)
#define ErrRaster_Memory_Overflow
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
FT_Outline_MoveToFunc move_to
#define FT_TRACE7(varformat)
#define FT_Outline_LineTo_Func
FT_BEGIN_HEADER FT_Outline_Decompose(FT_Outline *outline, const FT_Outline_Funcs *func_interface, void *user)
struct gray_TRaster_ * gray_PRaster
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_RASTER_FLAG_DIRECT
if(!abbox) return FT_THROW(Invalid_Argument)
#define FT_Raster_Reset_Func
GLenum const GLfloat * params
GLdouble GLdouble GLdouble GLdouble top
#define FT_MAX_GRAY_SPANS
#define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_, raster_new_, raster_reset_, raster_set_mode_, raster_render_, raster_done_)
png_infop png_bytep png_size_t buffer_size
#define FT_TRACE5(varformat)
#define FT_Outline_CubicTo_Func
GLuint GLuint GLsizei count
#define FT_CURVE_TAG_CONIC
FT_Outline_ConicToFunc conic_to
#define FT_Raster_Span_Func
#define FT_CURVE_TAG(flag)
struct gray_TRaster_ gray_TRaster
FT_Module_Constructor FT_GLYPH_FORMAT_OUTLINE
#define FT_MEM_ZERO(dest, count)