4 |
/* */ |
/* */ |
5 |
/* FreeType synthesizing code for emboldening and slanting (body). */ |
/* FreeType synthesizing code for emboldening and slanting (body). */ |
6 |
/* */ |
/* */ |
7 |
/* Copyright 2000-2001, 2002, 2003, 2004 by */ |
/* Copyright 2000-2001, 2002, 2003, 2004, 2005 by */ |
8 |
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
9 |
/* */ |
/* */ |
10 |
/* This file is part of the FreeType project, and may only be used, */ |
/* This file is part of the FreeType project, and may only be used, */ |
17 |
|
|
18 |
|
|
19 |
#include <ft2build.h> |
#include <ft2build.h> |
20 |
|
#include FT_SYNTHESIS_H |
21 |
#include FT_INTERNAL_OBJECTS_H |
#include FT_INTERNAL_OBJECTS_H |
|
#include FT_INTERNAL_CALC_H |
|
22 |
#include FT_OUTLINE_H |
#include FT_OUTLINE_H |
23 |
#include FT_TRIGONOMETRY_H |
#include FT_BITMAP_H |
|
#include FT_SYNTHESIS_H |
|
24 |
|
|
25 |
|
|
26 |
#define FT_BOLD_THRESHOLD 0x0100 |
#define FT_BOLD_THRESHOLD 0x0100 |
76 |
FT_EXPORT_DEF( void ) |
FT_EXPORT_DEF( void ) |
77 |
FT_GlyphSlot_Embolden( FT_GlyphSlot slot ) |
FT_GlyphSlot_Embolden( FT_GlyphSlot slot ) |
78 |
{ |
{ |
79 |
FT_Vector* points; |
FT_Library library = slot->library; |
80 |
FT_Vector v_prev, v_first, v_next, v_cur; |
FT_Face face = FT_SLOT_FACE( slot ); |
81 |
FT_Pos distance; |
FT_Pos xstr, ystr; |
82 |
FT_Outline* outline = &slot->outline; |
FT_Error error; |
|
FT_Face face = FT_SLOT_FACE( slot ); |
|
|
FT_Angle rotate, angle_in, angle_out; |
|
|
FT_Int c, n, first; |
|
83 |
|
|
84 |
|
|
85 |
/* only embolden outline glyph images */ |
/* some reasonable strength */ |
86 |
if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) |
xstr = FT_MulFix( face->units_per_EM, |
87 |
return; |
face->size->metrics.y_scale ) / 32; |
88 |
|
ystr = xstr; |
|
/* compute control distance */ |
|
|
distance = FT_MulFix( face->units_per_EM / 60, |
|
|
face->size->metrics.y_scale ); |
|
89 |
|
|
90 |
if ( FT_Outline_Get_Orientation( outline ) == FT_ORIENTATION_TRUETYPE ) |
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) |
91 |
rotate = -FT_ANGLE_PI2; |
{ |
92 |
|
error = FT_Outline_Embolden( &slot->outline, xstr ); |
93 |
|
xstr = ( xstr * 4 ) & ~63; |
94 |
|
ystr = xstr; |
95 |
|
} |
96 |
|
else if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) |
97 |
|
{ |
98 |
|
xstr = FT_PIX_FLOOR( xstr ); |
99 |
|
if ( xstr == 0 ) |
100 |
|
xstr = 1 << 6; |
101 |
|
ystr = FT_PIX_FLOOR( ystr ); |
102 |
|
|
103 |
|
error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr ); |
104 |
|
|
105 |
|
/* XXX should we set these? */ |
106 |
|
if ( !error ) |
107 |
|
slot->bitmap_top += ystr >> 6; |
108 |
|
} |
109 |
else |
else |
110 |
rotate = FT_ANGLE_PI2; |
error = FT_Err_Invalid_Argument; |
111 |
|
|
112 |
points = outline->points; |
/* XXX should we set these? */ |
113 |
|
if ( !error ) |
|
first = 0; |
|
|
for ( c = 0; c < outline->n_contours; c++ ) |
|
114 |
{ |
{ |
115 |
int last = outline->contours[c]; |
#if 0 |
116 |
|
slot->advance.x += xstr; |
117 |
|
slot->metrics.width += xstr; |
118 |
v_first = points[first]; |
slot->metrics.height += ystr; |
119 |
v_prev = points[last]; |
slot->metrics.horiBearingY += ystr; |
120 |
v_cur = v_first; |
#endif |
121 |
|
slot->metrics.horiAdvance += xstr; |
|
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; |
|
|
|
|
|
v_prev = v_cur; |
|
|
v_cur = v_next; |
|
|
} |
|
|
|
|
|
first = last + 1; |
|
122 |
} |
} |
|
|
|
|
slot->metrics.horiAdvance = |
|
|
( slot->metrics.horiAdvance + distance*4 ) & ~63; |
|
123 |
} |
} |
124 |
|
|
125 |
|
|