ref: 71d7628175c1130e2d698ef558641279de70d553
parent: 25500f8cca1eb38cff4f29e2fc50e9e50a947166
author: Werner Lemberg <[email protected]>
date: Mon May 30 03:54:20 EDT 2005
* src/base/ftbitmap.c (FT_Bitmap_Embolden): Fix emboldening bitmap of mode FT_PIXEL_MODE_GRAY. Also add support for mode FT_PIXEL_MODE_LCD and FT_PIXEL_MODE_LCD_V. (ft_bitmap_assure_buffer): FT_PIXEL_MODE_LCD and FT_PIXEL_MODE_LCD_V should have ppb (pixel per byte) 1. Zero the padding when there's no need to allocate memory. * src/base/ftsynth.c (FT_GlyphSlot_Embolden): Handle slot->advance too. More suited emboldening strength.
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -115,8 +115,6 @@
switch ( bitmap->pixel_mode )
{
case FT_PIXEL_MODE_MONO:
- case FT_PIXEL_MODE_LCD:
- case FT_PIXEL_MODE_LCD_V:
ppb = 8;
break;
case FT_PIXEL_MODE_GRAY2:
@@ -126,6 +124,8 @@
ppb = 2;
break;
case FT_PIXEL_MODE_GRAY:
+ case FT_PIXEL_MODE_LCD:
+ case FT_PIXEL_MODE_LCD_V:
ppb = 1;
break;
default:
@@ -132,9 +132,36 @@
return FT_Err_Invalid_Glyph_Format;
}
- /* check whether we must allocate memory */
+ /* if no need to allocate memory */
if ( ypixels == 0 && pitch * ppb >= bitmap->width + xpixels )
+ {
+ /* zero the padding */
+ for ( i = 0; i < bitmap->rows; i++ )
+ {
+ unsigned char* last_byte;
+ int bits = xpixels * ( 8 / ppb );
+ int mask = 0;
+
+
+ last_byte = bitmap->buffer + i * pitch + ( bitmap->width - 1 ) / ppb;
+
+ if ( bits >= 8 )
+ {
+ FT_MEM_ZERO( last_byte + 1, bits / 8 );
+ bits %= 8;
+ }
+
+ if ( bits > 0 )
+ {
+ while ( bits-- > 0 )
+ mask |= 1 << bits;
+
+ *last_byte &= ~mask;
+ }
+ }
+
return FT_Err_Ok;
+ }
new_pitch = ( bitmap->width + xpixels + ppb - 1 ) / ppb;
@@ -187,16 +214,22 @@
if ( !bitmap )
return FT_Err_Invalid_Argument;
+ xstr = FT_PIX_ROUND( xStrength ) >> 6;
+ ystr = FT_PIX_ROUND( yStrength ) >> 6;
+
switch ( bitmap->pixel_mode )
{
case FT_PIXEL_MODE_GRAY2:
case FT_PIXEL_MODE_GRAY4:
return FT_Err_Invalid_Glyph_Format;
+ case FT_PIXEL_MODE_LCD:
+ xstr *= 3;
+ break;
+ case FT_PIXEL_MODE_LCD_V:
+ ystr *= 3;
+ break;
}
- xstr = FT_PIX_ROUND( xStrength ) >> 6;
- ystr = FT_PIX_ROUND( yStrength ) >> 6;
-
if ( xstr == 0 && ystr == 0 )
return FT_Err_Ok;
else if ( xstr < 0 || ystr < 0 || xstr > 8 )
@@ -245,19 +278,19 @@
break;
#endif
}
- else if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )
+ else
{
if ( x - i >= 0 )
{
- if ( p[x] + p[x - i] > bitmap->num_grays )
+ if ( p[x] + p[x - i] > bitmap->num_grays - 1 )
{
- p[x] = bitmap->num_grays;
+ p[x] = bitmap->num_grays - 1;
break;
}
else
{
p[x] += p[x - i];
- if ( p[x] == bitmap->num_grays )
+ if ( p[x] == bitmap->num_grays - 1 )
break;
}
}
--- a/src/base/ftsynth.c
+++ b/src/base/ftsynth.c
@@ -81,7 +81,7 @@
/* some reasonable strength */
xstr = FT_MulFix( face->units_per_EM,
- face->size->metrics.y_scale ) / 32;
+ face->size->metrics.y_scale ) / 42;
ystr = xstr;
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
@@ -122,6 +122,9 @@
/* modify the metrics accordingly */
if ( !error )
{
+ slot->advance.x += xstr;
+ slot->advance.y += ystr;
+
slot->metrics.width += xstr;
slot->metrics.height += ystr;
slot->metrics.horiBearingY += ystr;