aboutsummaryrefslogtreecommitdiff
path: root/freetype/src/smooth
diff options
context:
space:
mode:
Diffstat (limited to 'freetype/src/smooth')
-rw-r--r--freetype/src/smooth/ftgrays.c63
-rw-r--r--freetype/src/smooth/ftsmooth.c147
2 files changed, 90 insertions, 120 deletions
diff --git a/freetype/src/smooth/ftgrays.c b/freetype/src/smooth/ftgrays.c
index b1611625d..ea7eaaad3 100644
--- a/freetype/src/smooth/ftgrays.c
+++ b/freetype/src/smooth/ftgrays.c
@@ -98,6 +98,9 @@
#define FT_ERR_XCAT( x, y ) x ## y
#define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y )
+#define FT_BEGIN_STMNT do {
+#define FT_END_STMNT } while ( 0 )
+
/* define this to dump debugging information */
/* #define FT_DEBUG_LEVEL_TRACE */
@@ -402,6 +405,8 @@ typedef ptrdiff_t FT_PtrDist;
typedef struct gray_TWorker_
{
+ ft_jmp_buf jump_buffer;
+
TCoord ex, ey;
TPos min_ex, max_ex;
TPos min_ey, max_ey;
@@ -437,8 +442,6 @@ typedef ptrdiff_t FT_PtrDist;
int band_size;
int band_shoot;
- ft_jmp_buf jump_buffer;
-
void* buffer;
long buffer_size;
@@ -1088,37 +1091,10 @@ typedef ptrdiff_t FT_PtrDist;
/* dx and dy are x and y components of the P0-P3 chord vector. */
- dx = arc[3].x - arc[0].x;
- dy = arc[3].y - arc[0].y;
-
- /* L is an (under)estimate of the Euclidean distance P0-P3. */
- /* */
- /* If dx >= dy, then r = sqrt(dx^2 + dy^2) can be overestimated */
- /* with least maximum error by */
- /* */
- /* r_upperbound = dx + (sqrt(2) - 1) * dy , */
- /* */
- /* where sqrt(2) - 1 can be (over)estimated by 107/256, giving an */
- /* error of no more than 8.4%. */
- /* */
- /* Similarly, some elementary calculus shows that r can be */
- /* underestimated with least maximum error by */
- /* */
- /* r_lowerbound = sqrt(2 + sqrt(2)) / 2 * dx */
- /* + sqrt(2 - sqrt(2)) / 2 * dy . */
- /* */
- /* 236/256 and 97/256 are (under)estimates of the two algebraic */
- /* numbers, giving an error of no more than 8.1%. */
-
- dx_ = FT_ABS( dx );
- dy_ = FT_ABS( dy );
-
- /* This is the same as */
- /* */
- /* L = ( 236 * FT_MAX( dx_, dy_ ) */
- /* + 97 * FT_MIN( dx_, dy_ ) ) >> 8; */
- L = ( dx_ > dy_ ? 236 * dx_ + 97 * dy_
- : 97 * dx_ + 236 * dy_ ) >> 8;
+ dx = dx_ = arc[3].x - arc[0].x;
+ dy = dy_ = arc[3].y - arc[0].y;
+
+ L = FT_HYPOT( dx_, dy_ );
/* Avoid possible arithmetic overflow below by splitting. */
if ( L > 32767 )
@@ -1539,7 +1515,10 @@ typedef ptrdiff_t FT_PtrDist;
TPos delta;
- if ( !outline || !func_interface )
+ if ( !outline )
+ return FT_THROW( Invalid_Outline );
+
+ if ( !func_interface )
return FT_THROW( Invalid_Argument );
shift = func_interface->shift;
@@ -2121,12 +2100,26 @@ typedef ptrdiff_t FT_PtrDist;
}
+ static int
+ gray_raster_set_mode( FT_Raster raster,
+ unsigned long mode,
+ void* args )
+ {
+ FT_UNUSED( raster );
+ FT_UNUSED( mode );
+ FT_UNUSED( args );
+
+
+ return 0; /* nothing to do */
+ }
+
+
FT_DEFINE_RASTER_FUNCS(ft_grays_raster,
FT_GLYPH_FORMAT_OUTLINE,
(FT_Raster_New_Func) gray_raster_new,
(FT_Raster_Reset_Func) gray_raster_reset,
- (FT_Raster_Set_Mode_Func)0,
+ (FT_Raster_Set_Mode_Func)gray_raster_set_mode,
(FT_Raster_Render_Func) gray_raster_render,
(FT_Raster_Done_Func) gray_raster_done
)
diff --git a/freetype/src/smooth/ftsmooth.c b/freetype/src/smooth/ftsmooth.c
index f2fcdede8..4dff563fc 100644
--- a/freetype/src/smooth/ftsmooth.c
+++ b/freetype/src/smooth/ftsmooth.c
@@ -102,25 +102,24 @@
FT_Render_Mode required_mode )
{
FT_Error error;
- FT_Outline* outline = NULL;
+ FT_Outline* outline = &slot->outline;
+ FT_Bitmap* bitmap = &slot->bitmap;
+ FT_Memory memory = render->root.memory;
FT_BBox cbox;
+ FT_Pos x_shift = 0;
+ FT_Pos y_shift = 0;
+ FT_Pos x_left, y_top;
FT_Pos width, height, pitch;
#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
FT_Pos height_org, width_org;
#endif
- FT_Bitmap* bitmap = &slot->bitmap;
- FT_Memory memory = render->root.memory;
FT_Int hmul = mode == FT_RENDER_MODE_LCD;
FT_Int vmul = mode == FT_RENDER_MODE_LCD_V;
- FT_Pos x_shift = 0;
- FT_Pos y_shift = 0;
- FT_Pos x_left, y_top;
FT_Raster_Params params;
- FT_Bool have_translated_origin = FALSE;
- FT_Bool have_outline_shifted = FALSE;
- FT_Bool have_buffer = FALSE;
+ FT_Bool have_outline_shifted = FALSE;
+ FT_Bool have_buffer = FALSE;
/* check glyph image format */
@@ -137,73 +136,45 @@
goto Exit;
}
- outline = &slot->outline;
-
- /* translate the outline to the new origin if needed */
if ( origin )
{
- FT_Outline_Translate( outline, origin->x, origin->y );
- have_translated_origin = TRUE;
+ x_shift = origin->x;
+ y_shift = origin->y;
}
/* compute the control box, and grid fit it */
+ /* taking into account the origin shift */
FT_Outline_Get_CBox( outline, &cbox );
- cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
- cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
- cbox.xMax = FT_PIX_CEIL( cbox.xMax );
- cbox.yMax = FT_PIX_CEIL( cbox.yMax );
+ cbox.xMin = FT_PIX_FLOOR( cbox.xMin + x_shift );
+ cbox.yMin = FT_PIX_FLOOR( cbox.yMin + y_shift );
+ cbox.xMax = FT_PIX_CEIL( cbox.xMax + x_shift );
+ cbox.yMax = FT_PIX_CEIL( cbox.yMax + y_shift );
- if ( cbox.xMin < 0 && cbox.xMax > FT_INT_MAX + cbox.xMin )
- {
- FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
- " xMin = %d, xMax = %d\n",
- cbox.xMin >> 6, cbox.xMax >> 6 ));
- error = FT_THROW( Raster_Overflow );
- goto Exit;
- }
- else
- width = ( cbox.xMax - cbox.xMin ) >> 6;
+ x_shift -= cbox.xMin;
+ y_shift -= cbox.yMin;
- if ( cbox.yMin < 0 && cbox.yMax > FT_INT_MAX + cbox.yMin )
- {
- FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
- " yMin = %d, yMax = %d\n",
- cbox.yMin >> 6, cbox.yMax >> 6 ));
- error = FT_THROW( Raster_Overflow );
- goto Exit;
- }
- else
- height = ( cbox.yMax - cbox.yMin ) >> 6;
+ x_left = cbox.xMin >> 6;
+ y_top = cbox.yMax >> 6;
+
+ width = (FT_ULong)( cbox.xMax - cbox.xMin ) >> 6;
+ height = (FT_ULong)( cbox.yMax - cbox.yMin ) >> 6;
#ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
width_org = width;
height_org = height;
#endif
- /* release old bitmap buffer */
- if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
- {
- FT_FREE( bitmap->buffer );
- slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
- }
-
- /* allocate new one */
pitch = width;
if ( hmul )
{
- width = width * 3;
- pitch = FT_PAD_CEIL( width, 4 );
+ width *= 3;
+ pitch = FT_PAD_CEIL( width, 4 );
}
if ( vmul )
height *= 3;
- x_shift = (FT_Int) cbox.xMin;
- y_shift = (FT_Int) cbox.yMin;
- x_left = (FT_Int)( cbox.xMin >> 6 );
- y_top = (FT_Int)( cbox.yMax >> 6 );
-
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
if ( slot->library->lcd_filter_func )
@@ -213,23 +184,32 @@
if ( hmul )
{
- x_shift -= 64 * ( extra >> 1 );
+ x_shift += 64 * ( extra >> 1 );
+ x_left -= extra >> 1;
width += 3 * extra;
pitch = FT_PAD_CEIL( width, 4 );
- x_left -= extra >> 1;
}
if ( vmul )
{
- y_shift -= 64 * ( extra >> 1 );
- height += 3 * extra;
+ y_shift += 64 * ( extra >> 1 );
y_top += extra >> 1;
+ height += 3 * extra;
}
}
#endif
-#if FT_UINT_MAX > 0xFFFFU
+ /*
+ * XXX: on 16bit system, we return an error for huge bitmap
+ * to prevent an overflow.
+ */
+ if ( x_left > FT_INT_MAX || y_top > FT_INT_MAX ||
+ x_left < FT_INT_MIN || y_top < FT_INT_MIN )
+ {
+ error = FT_THROW( Invalid_Pixel_Size );
+ goto Exit;
+ }
/* Required check is (pitch * height < FT_ULONG_MAX), */
/* but we care realistic cases only. Always pitch <= width. */
@@ -241,7 +221,24 @@
goto Exit;
}
-#endif
+ /* release old bitmap buffer */
+ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+ {
+ FT_FREE( bitmap->buffer );
+ slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
+ }
+
+ /* allocate new one */
+ if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
+ goto Exit;
+ else
+ have_buffer = TRUE;
+
+ slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
+
+ slot->format = FT_GLYPH_FORMAT_BITMAP;
+ slot->bitmap_left = (FT_Int)x_left;
+ slot->bitmap_top = (FT_Int)y_top;
bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
bitmap->num_grays = 256;
@@ -250,15 +247,11 @@
bitmap->pitch = pitch;
/* translate outline to render it into the bitmap */
- FT_Outline_Translate( outline, -x_shift, -y_shift );
- have_outline_shifted = TRUE;
-
- if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
- goto Exit;
- else
- have_buffer = TRUE;
-
- slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
+ if ( x_shift || y_shift )
+ {
+ FT_Outline_Translate( outline, x_shift, y_shift );
+ have_outline_shifted = TRUE;
+ }
/* set up parameters */
params.target = bitmap;
@@ -365,20 +358,6 @@
#endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
- /*
- * XXX: on 16bit system, we return an error for huge bitmap
- * to prevent an overflow.
- */
- if ( x_left > FT_INT_MAX || y_top > FT_INT_MAX )
- {
- error = FT_THROW( Invalid_Pixel_Size );
- goto Exit;
- }
-
- slot->format = FT_GLYPH_FORMAT_BITMAP;
- slot->bitmap_left = (FT_Int)x_left;
- slot->bitmap_top = (FT_Int)y_top;
-
/* everything is fine; don't deallocate buffer */
have_buffer = FALSE;
@@ -386,9 +365,7 @@
Exit:
if ( have_outline_shifted )
- FT_Outline_Translate( outline, x_shift, y_shift );
- if ( have_translated_origin )
- FT_Outline_Translate( outline, -origin->x, -origin->y );
+ FT_Outline_Translate( outline, -x_shift, -y_shift );
if ( have_buffer )
{
FT_FREE( bitmap->buffer );