91 #define FT_COMPONENT trace_smooth
101 #ifdef FT_DEBUG_LEVEL_TRACE
110 #define FT_UINT_MAX UINT_MAX
111 #define FT_INT_MAX INT_MAX
113 #define ft_memset memset
115 #define ft_setjmp setjmp
116 #define ft_longjmp longjmp
117 #define ft_jmp_buf jmp_buf
122 #define ErrRaster_Invalid_Mode -2
123 #define ErrRaster_Invalid_Outline -1
124 #define ErrRaster_Invalid_Argument -3
125 #define ErrRaster_Memory_Overflow -4
127 #define FT_BEGIN_HEADER
128 #define FT_END_HEADER
138 #define FT_UNUSED( x ) (x) = (x)
143 #ifdef FT_DEBUG_LEVEL_TRACE
146 FT_Message(
const char* fmt,
153 vfprintf( stderr, fmt, ap );
159 #define FT_TRACE5( varformat ) FT_Message varformat
162 #define FT_TRACE7( varformat ) FT_Message varformat
165 #define FT_ERROR( varformat ) FT_Message varformat
170 #define FT_TRACE5( x ) do { } while ( 0 )
171 #define FT_TRACE7( x ) do { } while ( 0 )
172 #define FT_ERROR( x ) do { } while ( 0 )
177 #define FT_DEFINE_OUTLINE_FUNCS( class_, \
178 move_to_, line_to_, \
179 conic_to_, cubic_to_, \
181 static const FT_Outline_Funcs class_ = \
191 #define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_, \
192 raster_new_, raster_reset_, \
193 raster_set_mode_, raster_render_, \
195 const FT_Raster_Funcs class_ = \
210 #include FT_INTERNAL_OBJECTS_H
211 #include FT_INTERNAL_DEBUG_H
212 #include FT_OUTLINE_H
218 #define ErrRaster_Invalid_Mode Smooth_Err_Cannot_Render_Glyph
219 #define ErrRaster_Invalid_Outline Smooth_Err_Invalid_Outline
220 #define ErrRaster_Memory_Overflow Smooth_Err_Out_Of_Memory
221 #define ErrRaster_Invalid_Argument Smooth_Err_Invalid_Argument
226 #define FT_MEM_SET( d, s, c ) ft_memset( d, s, c )
230 #define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
240 #ifndef FT_STATIC_RASTER
242 #define RAS_ARG gray_PWorker worker
243 #define RAS_ARG_ gray_PWorker worker,
245 #define RAS_VAR worker
246 #define RAS_VAR_ worker,
266 #define ONE_PIXEL ( 1L << PIXEL_BITS )
267 #define PIXEL_MASK ( -1L << PIXEL_BITS )
268 #define TRUNC( x ) ( (TCoord)( (x) >> PIXEL_BITS ) )
269 #define SUBPIXELS( x ) ( (TPos)(x) << PIXEL_BITS )
270 #define FLOOR( x ) ( (x) & -ONE_PIXEL )
271 #define CEILING( x ) ( ( (x) + ONE_PIXEL - 1 ) & -ONE_PIXEL )
272 #define ROUND( x ) ( ( (x) + ONE_PIXEL / 2 ) & -ONE_PIXEL )
275 #define UPSCALE( x ) ( (x) << ( PIXEL_BITS - 6 ) )
276 #define DOWNSCALE( x ) ( (x) >> ( PIXEL_BITS - 6 ) )
278 #define UPSCALE( x ) ( (x) >> ( 6 - PIXEL_BITS ) )
279 #define DOWNSCALE( x ) ( (x) << ( 6 - PIXEL_BITS ) )
306 #if FT_UINT_MAX == 0xFFFFU
316 #define FT_MAX_GRAY_SPANS 32
321 typedef struct TCell_
331 typedef struct gray_TWorker_
336 TPos count_ex, count_ey;
362 void* render_span_data;
379 #ifndef FT_STATIC_RASTER
380 #define ras (*worker)
386 typedef struct gray_TRaster_
407 ras.buffer_size = byte_size;
433 ras.min_ex =
ras.max_ex = 0;
434 ras.min_ey =
ras.max_ey = 0;
438 ras.min_ex =
ras.max_ex = vec->
x;
439 ras.min_ey =
ras.max_ey = vec->
y;
443 for ( ; vec <
limit; vec++ )
449 if ( x <
ras.min_ex )
ras.min_ex =
x;
450 if ( x >
ras.max_ex )
ras.max_ex =
x;
451 if ( y <
ras.min_ey )
ras.min_ey =
y;
452 if ( y >
ras.max_ey )
ras.max_ey =
y;
456 ras.min_ex =
ras.min_ex >> 6;
457 ras.min_ey =
ras.min_ey >> 6;
458 ras.max_ex = (
ras.max_ex + 63 ) >> 6;
459 ras.max_ey = (
ras.max_ey + 63 ) >> 6;
474 if ( x >
ras.count_ex )
477 pcell = &
ras.ycells[
ras.ey];
481 if ( cell ==
NULL || cell->x > x )
490 if (
ras.num_cells >=
ras.max_cells )
493 cell =
ras.cells +
ras.num_cells++;
509 if ( !
ras.invalid && (
ras.area |
ras.cover ) )
514 cell->area +=
ras.area;
515 cell->cover +=
ras.cover;
542 if ( ex >
ras.max_ex )
550 if ( ex !=
ras.ex || ey !=
ras.ey )
562 ras.invalid = ( (unsigned)ey >= (
unsigned)
ras.count_ey ||
563 ex >=
ras.count_ex );
575 if ( ex >
ras.max_ex )
578 if ( ex <
ras.min_ex )
603 TCoord ex1, ex2, fx1, fx2, delta, mod, lift, rem;
627 ras.area += (
TArea)(( fx1 + fx2 ) * delta);
641 p = fx1 * ( y2 -
y1 );
647 delta = (
TCoord)( p / dx );
655 ras.area += (
TArea)(( fx1 + first ) * delta);
665 lift = (
TCoord)( p / dx );
707 TCoord ey1, ey2, fy1, fy2, mod;
710 int delta, rem, lift, incr;
736 if ( min >=
ras.max_ey || max <
ras.min_ey )
764 delta = (
int)( first - fy1 );
772 area = (
TArea)two_fx * delta;
802 delta = (
int)( p / dy );
803 mod = (
int)( p % dy );
819 lift = (
int)( p / dy );
820 rem = (
int)( p % dy );
866 base[4].
x = base[2].
x;
868 a = base[3].
x = ( base[2].
x +
b ) / 2;
869 b = base[1].
x = ( base[0].
x +
b ) / 2;
870 base[2].
x = ( a +
b ) / 2;
872 base[4].
y = base[2].
y;
874 a = base[3].
y = ( base[2].
y +
b ) / 2;
875 b = base[1].
y = ( base[0].
y +
b ) / 2;
876 base[2].
y = ( a +
b ) / 2;
891 levels =
ras.lev_stack;
902 dx =
FT_ABS( arc[2].
x + arc[0].
x - 2 * arc[1].
x );
903 dy =
FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y );
911 min = max = arc[0].
y;
914 if ( y < min ) min =
y;
915 if ( y > max ) max =
y;
918 if ( y < min ) min =
y;
919 if ( y > max ) max =
y;
941 levels[
top] = levels[top - 1] = level - 1;
950 }
while ( top >= 0 );
960 base[6].
x = base[3].
x;
963 base[1].
x = a = ( base[0].
x +
c ) / 2;
964 base[5].
x = b = ( base[3].
x +
d ) / 2;
966 base[2].
x = a = ( a +
c ) / 2;
967 base[4].
x = b = ( b +
c ) / 2;
968 base[3].
x = ( a +
b ) / 2;
970 base[6].
y = base[3].
y;
973 base[1].
y = a = ( base[0].
y +
c ) / 2;
974 base[5].
y = b = ( base[3].
y +
d ) / 2;
976 base[2].
y = a = ( a +
c ) / 2;
977 base[4].
y = b = ( b +
c ) / 2;
978 base[3].
y = ( a +
b ) / 2;
1002 min = max = arc[0].
y;
1033 TPos dx, dy, dx_, dy_;
1034 TPos dx1, dy1, dx2, dy2;
1039 dx = arc[3].
x - arc[0].
x;
1040 dy = arc[3].
y - arc[0].
y;
1068 L = ( dx_ > dy_ ? 236 * dx_ + 97 * dy_
1069 : 97 * dx_ + 236 * dy_ ) >> 8;
1079 dx1 = arc[1].
x - arc[0].
x;
1080 dy1 = arc[1].
y - arc[0].
y;
1081 s =
FT_ABS( dy * dx1 - dx * dy1 );
1087 dx2 = arc[2].
x - arc[0].
x;
1088 dy2 = arc[2].
y - arc[0].
y;
1089 s =
FT_ABS( dy * dx2 - dx * dy2 );
1095 if ( dy * dy1 + dx * dx1 < 0 ||
1096 dy * dy2 + dx * dx2 < 0 ||
1097 dy * (arc[3].y - arc[1].y) + dx * (arc[3].
x - arc[1].
x) < 0 ||
1098 dy * (arc[3].y - arc[2].y) + dx * (arc[3].x - arc[2].x) < 0 )
1113 if ( arc ==
ras.bez_stack )
1186 p += (unsigned)( ( map->
rows - 1 ) * map->
pitch );
1188 for ( ; count > 0; count--, spans++ )
1190 unsigned char coverage = spans->
coverage;
1199 if ( spans->
len >= 8 )
1203 unsigned char*
q = p + spans->
x;
1206 switch ( spans->
len )
1208 case 7: *q++ = (
unsigned char)coverage;
1209 case 6: *q++ = (
unsigned char)coverage;
1210 case 5: *q++ = (
unsigned char)coverage;
1211 case 4: *q++ = (
unsigned char)coverage;
1212 case 3: *q++ = (
unsigned char)coverage;
1213 case 2: *q++ = (
unsigned char)coverage;
1214 case 1: *q = (
unsigned char)coverage;
1243 coverage = -coverage;
1249 if ( coverage > 256 )
1250 coverage = 512 - coverage;
1251 else if ( coverage == 256 )
1257 if ( coverage >= 256 )
1275 count =
ras.num_gray_spans;
1276 span =
ras.gray_spans + count - 1;
1279 (
int)span->
x + span->
len == (
int)x &&
1282 span->
len = (
unsigned short)( span->
len + acount );
1288 if (
ras.render_span && count > 0 )
1289 ras.render_span(
ras.span_y, count,
ras.gray_spans,
1290 ras.render_span_data );
1292 #ifdef FT_DEBUG_LEVEL_TRACE
1300 span =
ras.gray_spans;
1301 for ( n = 0; n <
count; n++, span++ )
1309 ras.num_gray_spans = 0;
1313 span =
ras.gray_spans;
1320 span->
len = (
unsigned short)acount;
1321 span->
coverage = (
unsigned char)coverage;
1323 ras.num_gray_spans++;
1328 #ifdef FT_DEBUG_LEVEL_TRACE
1338 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1343 printf(
"%3d:", yindex );
1345 for ( cell =
ras.ycells[yindex]; cell !=
NULL; cell = cell->next )
1346 printf(
" (%3ld, c:%4ld, a:%6d)", cell->x, cell->cover, cell->area );
1362 if (
ras.num_cells == 0 )
1365 ras.num_gray_spans = 0;
1369 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1376 for ( ; cell !=
NULL; cell = cell->next )
1381 if ( cell->x > x && cover != 0 )
1385 cover += cell->cover;
1386 area = cover * (
ONE_PIXEL * 2 ) - cell->area;
1388 if ( area != 0 && cell->x >= 0 )
1399 if (
ras.render_span &&
ras.num_gray_spans > 0 )
1400 ras.render_span(
ras.span_y,
ras.num_gray_spans,
1401 ras.gray_spans,
ras.render_span_data );
1449 #define SCALED( x ) ( ( (x) << shift ) - delta )
1469 if ( !outline || !func_interface )
1472 shift = func_interface->
shift;
1473 delta = func_interface->
delta;
1481 FT_TRACE5((
"FT_Outline_Decompose: Outline %d\n", n ));
1485 goto Invalid_Outline;
1486 limit = outline->
points + last;
1492 v_last = outline->
points[last];
1496 v_control = v_start;
1504 goto Invalid_Outline;
1521 v_start.
x = ( v_start.
x + v_last.
x ) / 2;
1522 v_start.
y = ( v_start.
y + v_last.
y ) / 2;
1531 v_start.
x / 64.0, v_start.
y / 64.0 ));
1532 error = func_interface->
move_to( &v_start, user );
1536 while ( point < limit )
1553 vec.
x / 64.0, vec.
y / 64.0 ));
1554 error = func_interface->
line_to( &vec, user );
1565 if ( point < limit )
1581 " with control (%.2f, %.2f)\n",
1582 vec.
x / 64.0, vec.
y / 64.0,
1583 v_control.
x / 64.0, v_control.
y / 64.0 ));
1584 error = func_interface->
conic_to( &v_control, &vec, user );
1591 goto Invalid_Outline;
1593 v_middle.
x = ( v_control.
x + vec.
x ) / 2;
1594 v_middle.
y = ( v_control.
y + vec.
y ) / 2;
1597 " with control (%.2f, %.2f)\n",
1598 v_middle.
x / 64.0, v_middle.
y / 64.0,
1599 v_control.
x / 64.0, v_control.
y / 64.0 ));
1600 error = func_interface->
conic_to( &v_control, &v_middle, user );
1609 " with control (%.2f, %.2f)\n",
1610 v_start.
x / 64.0, v_start.
y / 64.0,
1611 v_control.
x / 64.0, v_control.
y / 64.0 ));
1612 error = func_interface->
conic_to( &v_control, &v_start, user );
1620 if ( point + 1 > limit ||
1622 goto Invalid_Outline;
1633 if ( point <= limit )
1642 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1643 vec.
x / 64.0, vec.
y / 64.0,
1644 vec1.
x / 64.0, vec1.
y / 64.0,
1645 vec2.
x / 64.0, vec2.
y / 64.0 ));
1646 error = func_interface->
cubic_to( &vec1, &vec2, &vec, user );
1653 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1654 v_start.
x / 64.0, v_start.
y / 64.0,
1655 vec1.
x / 64.0, vec1.
y / 64.0,
1656 vec2.
x / 64.0, vec2.
y / 64.0 ));
1657 error = func_interface->
cubic_to( &vec1, &vec2, &v_start, user );
1665 v_start.
x / 64.0, v_start.
y / 64.0 ));
1666 error = func_interface->
line_to( &v_start, user );
1675 FT_TRACE5((
"FT_Outline_Decompose: Done\n", n ));
1679 FT_TRACE5((
"FT_Outline_Decompose: Error %d\n", error ));
1689 typedef struct gray_TBand_
1705 gray_convert_glyph_inner(
RAS_ARG )
1708 volatile int error = 0;
1710 #ifdef FT_CONFIG_OPTION_PIC
1712 Init_Class_func_interface(&func_interface);
1732 int volatile n, num_bands;
1741 clip = &
ras.clip_box;
1757 num_bands = (
int)( (
ras.max_ey -
ras.min_ey ) /
ras.band_size );
1758 if ( num_bands == 0 )
1760 if ( num_bands >= 39 )
1768 for ( n = 0; n < num_bands; n++, min =
max )
1770 max = min +
ras.band_size;
1771 if ( n == num_bands - 1 || max > max_y )
1778 while ( band >= bands )
1786 long cell_start, cell_end, cell_mod;
1790 ras.ycount = band->max - band->min;
1793 cell_mod = cell_start %
sizeof (
TCell );
1795 cell_start +=
sizeof (
TCell ) - cell_mod;
1797 cell_end =
ras.buffer_size;
1798 cell_end -= cell_end %
sizeof (
TCell );
1800 cells_max = (
PCell)( (
char*)
ras.buffer + cell_end );
1801 ras.cells = (
PCell)( (
char*)
ras.buffer + cell_start );
1802 if (
ras.cells >= cells_max )
1805 ras.max_cells = cells_max -
ras.cells;
1806 if (
ras.max_cells < 2 )
1809 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1815 ras.min_ey = band->min;
1816 ras.max_ey = band->max;
1817 ras.count_ey = band->max - band->min;
1819 error = gray_convert_glyph_inner(
RAS_VAR );
1834 middle = bottom + ( ( top -
bottom ) >> 1 );
1838 if ( middle == bottom )
1840 #ifdef FT_DEBUG_LEVEL_TRACE
1841 FT_TRACE7((
"gray_convert_glyph: rotten glyph\n" ));
1846 if ( bottom-top >=
ras.band_size )
1850 band[1].max = middle;
1851 band[0].min = middle;
1857 if (
ras.band_shoot > 8 &&
ras.band_size > 16 )
1858 ras.band_size =
ras.band_size / 2;
1873 if ( !raster || !raster->buffer || !raster->buffer_size )
1890 worker = raster->worker;
1899 if ( !target_map->width || !target_map->rows )
1902 if ( !target_map->buffer )
1914 ras.clip_box.xMin = 0;
1915 ras.clip_box.yMin = 0;
1916 ras.clip_box.xMax = target_map->width;
1917 ras.clip_box.yMax = target_map->rows;
1923 ras.clip_box.xMin = -32768L;
1924 ras.clip_box.yMin = -32768L;
1925 ras.clip_box.xMax = 32767L;
1926 ras.clip_box.yMax = 32767L;
1931 ras.outline = *outline;
1934 ras.band_size = raster->band_size;
1935 ras.num_gray_spans = 0;
1940 ras.render_span_data = params->
user;
1944 ras.target = *target_map;
1946 ras.render_span_data = &
ras;
1968 FT_MEM_ZERO( &the_raster,
sizeof ( the_raster ) );
1994 raster->memory = memory;
2024 if ( pool_base && pool_size >= (
long)
sizeof (
gray_TWorker ) + 2048 )
2029 rast->worker = worker;
2030 rast->buffer = pool_base +
2032 sizeof (
TCell ) - 1 ) &
2033 ~(
sizeof (
TCell ) - 1 ) );
2034 rast->buffer_size = (long)( ( pool_base + pool_size ) -
2035 (
char*)rast->buffer ) &
2036 ~(
sizeof (
TCell ) - 1 );
2037 rast->band_size = (
int)( rast->buffer_size /
2042 rast->buffer =
NULL;
2043 rast->buffer_size = 0;
2044 rast->worker =
NULL;
#define FT_ALLOC(ptr, size)
FT_Outline_LineToFunc line_to
struct gray_TWorker_ * gray_PWorker
#define FT_Raster_Done_Func
static int gray_convert_glyph(RAS_ARG)
struct FT_RasterRec_ * FT_Raster
#define FT_CURVE_TAG_CUBIC
static void gray_sweep(RAS_ARG_ const FT_Bitmap *target)
#define FT_Raster_Set_Mode_Func
#define FT_Raster_New_Func
static int gray_conic_to(const FT_Vector *control, const FT_Vector *to, gray_PWorker worker)
static void gray_compute_cbox(RAS_ARG)
static void gray_render_scanline(RAS_ARG_ TCoord ey, TPos x1, TCoord y1, TPos x2, TCoord y2)
#define FT_MEM_SET(d, s, c)
static int gray_move_to(const FT_Vector *to, gray_PWorker worker)
#define FT_RASTER_FLAG_AA
static int gray_line_to(const FT_Vector *to, gray_PWorker worker)
GLboolean GLboolean GLboolean GLboolean a
#define FT_Outline_ConicTo_Func
#define FT_DEFINE_RASTER_FUNCS(class_, glyph_format_, raster_new_,raster_reset_, raster_set_mode_,raster_render_, raster_done_)
static void gray_init_cells(RAS_ARG_ void *buffer, long byte_size)
return Display return Display Bool Bool int d
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLfixed GLfixed GLfixed y2
struct gray_TWorker_ gray_TWorker
#define FT_RASTER_FLAG_CLIP
static void gray_render_cubic(RAS_ARG_ const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to)
#define FT_OUTLINE_EVEN_ODD_FILL
static void gray_start_cell(RAS_ARG_ TCoord ex, TCoord ey)
#define FT_Outline_MoveTo_Func
static void gray_render_conic(RAS_ARG_ const FT_Vector *control, const FT_Vector *to)
EGLContext EGLenum target
EGLContext EGLenum EGLClientBuffer buffer
static int gray_raster_render(gray_PRaster raster, const FT_Raster_Params *params)
#define FT_Raster_Render_Func
struct gray_TBand_ gray_TBand
FT_Outline_CubicToFunc cubic_to
#define ErrRaster_Invalid_Mode
static int gray_cubic_to(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, gray_PWorker worker)
static void gray_split_cubic(FT_Vector *base)
static void gray_set_cell(RAS_ARG_ TCoord ex, TCoord ey)
#define ErrRaster_Memory_Overflow
FT_Outline_MoveToFunc move_to
static void gray_render_line(RAS_ARG_ TPos to_x, TPos to_y)
#define FT_TRACE7(varformat)
static int gray_raster_new(FT_Memory memory, FT_Raster *araster)
#define FT_Outline_LineTo_Func
FT_BEGIN_HEADER FT_Outline_Decompose(FT_Outline *outline, const FT_Outline_Funcs *func_interface, void *user)
#define ErrRaster_Invalid_Outline
GLfloat GLfloat GLfloat top
struct gray_TRaster_ * gray_PRaster
static void gray_record_cell(RAS_ARG)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
static void gray_raster_done(FT_Raster raster)
GLuint GLfloat GLfloat GLfloat x1
#define FT_RASTER_FLAG_DIRECT
static void gray_render_span(int y, int count, const FT_Span *spans, gray_PWorker worker)
static void gray_raster_reset(FT_Raster raster, char *pool_base, long pool_size)
EGLSurface EGLint EGLint y
#define FT_Raster_Reset_Func
#define ErrRaster_Invalid_Argument
#define FT_MAX_GRAY_SPANS
GLdouble GLdouble GLdouble GLdouble q
#define FT_TRACE5(varformat)
GLdouble GLdouble GLdouble b
#define FT_DEFINE_OUTLINE_FUNCS(class_, move_to_, line_to_, conic_to_,cubic_to_, shift_, delta_)
#define FT_Outline_CubicTo_Func
#define FT_CURVE_TAG_CONIC
static void gray_hline(RAS_ARG_ TCoord x, TCoord y, TPos area, TCoord acount)
FT_Outline_ConicToFunc conic_to
#define FT_Raster_Span_Func
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLfloat *params GLenum GLint GLenum GLenum GLvoid *pixels GLenum GLint GLenum GLint *params GLenum GLenum GLint *params GLenum GLsizei const GLvoid *pointer GLenum GLenum const GLint *params GLenum GLfloat GLfloat GLint GLint const GLfloat *points GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat *points GLint GLfloat GLfloat GLint GLfloat GLfloat v2 GLenum GLenum const GLint *params GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum map
#define FT_CURVE_TAG(flag)
struct gray_TRaster_ gray_TRaster
GLenum GLenum GLvoid GLvoid GLvoid * span
FT_Module_Constructor FT_GLYPH_FORMAT_OUTLINE
static void gray_split_conic(FT_Vector *base)
#define FT_MEM_ZERO(dest, count)
static PCell gray_find_cell(RAS_ARG)