|
|
|
@ -4,7 +4,7 @@ |
|
|
|
|
/* */ |
|
|
|
|
/* FreeType synthesizing code for emboldening and slanting (body). */ |
|
|
|
|
/* */ |
|
|
|
|
/* Copyright 2000-2001, 2002, 2003, 2004 by */ |
|
|
|
|
/* Copyright 2000-2001, 2002, 2003, 2004, 2005 by */ |
|
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
|
|
|
|
/* */ |
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */ |
|
|
|
@ -17,11 +17,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <ft2build.h> |
|
|
|
|
#include FT_SYNTHESIS_H |
|
|
|
|
#include FT_INTERNAL_OBJECTS_H |
|
|
|
|
#include FT_INTERNAL_CALC_H |
|
|
|
|
#include FT_OUTLINE_H |
|
|
|
|
#include FT_TRIGONOMETRY_H |
|
|
|
|
#include FT_SYNTHESIS_H |
|
|
|
|
#include FT_BITMAP_H |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define FT_BOLD_THRESHOLD 0x0100 |
|
|
|
@ -77,86 +76,50 @@ |
|
|
|
|
FT_EXPORT_DEF( void ) |
|
|
|
|
FT_GlyphSlot_Embolden( FT_GlyphSlot slot ) |
|
|
|
|
{ |
|
|
|
|
FT_Vector* points; |
|
|
|
|
FT_Vector v_prev, v_first, v_next, v_cur; |
|
|
|
|
FT_Pos distance; |
|
|
|
|
FT_Outline* outline = &slot->outline; |
|
|
|
|
FT_Face face = FT_SLOT_FACE( slot ); |
|
|
|
|
FT_Angle rotate, angle_in, angle_out; |
|
|
|
|
FT_Int c, n, first; |
|
|
|
|
FT_Library library = slot->library; |
|
|
|
|
FT_Face face = FT_SLOT_FACE( slot ); |
|
|
|
|
FT_Pos xstr, ystr; |
|
|
|
|
FT_Error error; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* only embolden outline glyph images */ |
|
|
|
|
if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
/* compute control distance */ |
|
|
|
|
distance = FT_MulFix( face->units_per_EM / 60, |
|
|
|
|
face->size->metrics.y_scale ); |
|
|
|
|
/* some reasonable strength */ |
|
|
|
|
xstr = FT_MulFix( face->units_per_EM, |
|
|
|
|
face->size->metrics.y_scale ) / 32; |
|
|
|
|
ystr = xstr; |
|
|
|
|
|
|
|
|
|
if ( FT_Outline_Get_Orientation( outline ) == FT_ORIENTATION_TRUETYPE ) |
|
|
|
|
rotate = -FT_ANGLE_PI2; |
|
|
|
|
else |
|
|
|
|
rotate = FT_ANGLE_PI2; |
|
|
|
|
|
|
|
|
|
points = outline->points; |
|
|
|
|
|
|
|
|
|
first = 0; |
|
|
|
|
for ( c = 0; c < outline->n_contours; c++ ) |
|
|
|
|
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) |
|
|
|
|
{ |
|
|
|
|
int last = outline->contours[c]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v_first = points[first]; |
|
|
|
|
v_prev = points[last]; |
|
|
|
|
v_cur = v_first; |
|
|
|
|
|
|
|
|
|
for ( n = first; n <= last; n++ ) |
|
|
|
|
{ |
|
|
|
|
FT_Pos d; |
|
|
|
|
FT_Vector in, out; |
|
|
|
|
FT_Fixed scale; |
|
|
|
|
FT_Angle angle_diff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( n < last ) v_next = points[n + 1]; |
|
|
|
|
else v_next = v_first; |
|
|
|
|
|
|
|
|
|
/* compute the in and out vectors */ |
|
|
|
|
in.x = v_cur.x - v_prev.x; |
|
|
|
|
in.y = v_cur.y - v_prev.y; |
|
|
|
|
|
|
|
|
|
out.x = v_next.x - v_cur.x; |
|
|
|
|
out.y = v_next.y - v_cur.y; |
|
|
|
|
|
|
|
|
|
angle_in = FT_Atan2( in.x, in.y ); |
|
|
|
|
angle_out = FT_Atan2( out.x, out.y ); |
|
|
|
|
angle_diff = FT_Angle_Diff( angle_in, angle_out ); |
|
|
|
|
scale = FT_Cos( angle_diff/2 ); |
|
|
|
|
|
|
|
|
|
if ( scale < 0x4000L && scale > -0x4000L ) |
|
|
|
|
{ |
|
|
|
|
in.x = in.y = 0; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
d = FT_DivFix( distance, scale ); |
|
|
|
|
|
|
|
|
|
FT_Vector_From_Polar( &in, d, angle_in + angle_diff/2 - rotate ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
outline->points[n].x = v_cur.x + distance + in.x; |
|
|
|
|
outline->points[n].y = v_cur.y + distance + in.y; |
|
|
|
|
error = FT_Outline_Embolden( &slot->outline, xstr ); |
|
|
|
|
xstr = ( xstr * 4 ) & ~63; |
|
|
|
|
ystr = xstr; |
|
|
|
|
} |
|
|
|
|
else if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) |
|
|
|
|
{ |
|
|
|
|
xstr = FT_PIX_FLOOR( xstr ); |
|
|
|
|
if ( xstr == 0 ) |
|
|
|
|
xstr = 1 << 6; |
|
|
|
|
ystr = FT_PIX_FLOOR( ystr ); |
|
|
|
|
|
|
|
|
|
v_prev = v_cur; |
|
|
|
|
v_cur = v_next; |
|
|
|
|
} |
|
|
|
|
error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr ); |
|
|
|
|
|
|
|
|
|
first = last + 1; |
|
|
|
|
/* XXX should we set these? */ |
|
|
|
|
if ( !error ) |
|
|
|
|
slot->bitmap_top += ystr >> 6; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
error = FT_Err_Invalid_Argument; |
|
|
|
|
|
|
|
|
|
slot->metrics.horiAdvance = |
|
|
|
|
( slot->metrics.horiAdvance + distance*4 ) & ~63; |
|
|
|
|
/* XXX should we set these? */ |
|
|
|
|
if ( !error ) |
|
|
|
|
{ |
|
|
|
|
#if 0 |
|
|
|
|
slot->advance.x += xstr; |
|
|
|
|
slot->metrics.width += xstr; |
|
|
|
|
slot->metrics.height += ystr; |
|
|
|
|
slot->metrics.horiBearingY += ystr; |
|
|
|
|
#endif |
|
|
|
|
slot->metrics.horiAdvance += xstr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|