1 /***************************************************************************/
5 /* FreeType synthesizing code for emboldening and slanting (body). */
7 /* Copyright 2000-2001 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
20 #include FT_INTERNAL_OBJECTS_H
21 #include FT_INTERNAL_CALC_H
23 #include FT_TRIGONOMETRY_H
24 #include FT_SYNTHESIS_H
27 #define FT_BOLD_THRESHOLD 0x0100
30 /*************************************************************************/
31 /*************************************************************************/
33 /**** EXPERIMENTAL OBLIQUING SUPPORT ****/
35 /*************************************************************************/
36 /*************************************************************************/
39 FT_GlyphSlot_Oblique( FT_GlyphSlot slot )
42 FT_Outline* outline = &slot->outline;
45 /* only oblique outline glyphs */
46 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
49 /* we don't touch the advance width */
51 /* For italic, simply apply a shear transform, with an angle */
52 /* of about 12 degrees. */
54 transform.xx = 0x10000L;
55 transform.yx = 0x00000L;
57 transform.xy = 0x06000L;
58 transform.yy = 0x10000L;
60 FT_Outline_Transform( outline, &transform );
64 /*************************************************************************/
65 /*************************************************************************/
67 /**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/
69 /*************************************************************************/
70 /*************************************************************************/
75 ft_test_extrema( FT_Outline* outline,
78 FT_Vector *prev, *cur, *next;
80 FT_Int c, first, last;
83 /* we need to compute the `previous' and `next' point */
84 /* for these extrema. */
85 cur = outline->points + n;
90 for ( c = 0; c < outline->n_contours; c++ )
92 last = outline->contours[c];
95 prev = outline->points + last;
98 next = outline->points + first;
103 product = FT_MulDiv( cur->x - prev->x, /* in.x */
104 next->y - cur->y, /* out.y */
107 FT_MulDiv( cur->y - prev->y, /* in.y */
108 next->x - cur->x, /* out.x */
112 product = product > 0 ? 1 : -1;
118 /* Compute the orientation of path filling. It differs between TrueType */
119 /* and Type1 formats. We could use the `FT_OUTLINE_REVERSE_FILL' flag, */
120 /* but it is better to re-compute it directly (it seems that this flag */
121 /* isn't correctly set for some weird composite glyphs currently). */
123 /* We do this by computing bounding box points, and computing their */
126 /* The function returns either 1 or -1. */
129 ft_get_orientation( FT_Outline* outline )
141 box.xMin = box.yMin = 32767;
142 box.xMax = box.yMax = -32768;
145 if ( outline->n_contours < 1 )
148 last = outline->contours[outline->n_contours - 1];
150 for ( n = 0; n <= last; n++ )
155 x = outline->points[n].x;
167 y = outline->points[n].y;
180 /* test orientation of the xmin */
181 n = ft_test_extrema( outline, indices.xMin );
185 n = ft_test_extrema( outline, indices.yMin );
189 n = ft_test_extrema( outline, indices.xMax );
193 n = ft_test_extrema( outline, indices.yMax );
202 FT_EXPORT_DEF( void )
203 FT_GlyphSlot_Embolden( FT_GlyphSlot slot )
206 FT_Vector v_prev, v_first, v_next, v_cur;
208 FT_Outline* outline = &slot->outline;
209 FT_Face face = FT_SLOT_FACE( slot );
210 FT_Angle rotate, angle_in, angle_out;
211 FT_Int c, n, first, orientation;
214 /* only embolden outline glyph images */
215 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
218 /* compute control distance */
219 distance = FT_MulFix( face->units_per_EM / 60,
220 face->size->metrics.y_scale );
222 orientation = ft_get_orientation( outline );
223 rotate = FT_ANGLE_PI2*orientation;
225 points = outline->points;
228 for ( c = 0; c < outline->n_contours; c++ )
230 int last = outline->contours[c];
233 v_first = points[first];
234 v_prev = points[last];
237 for ( n = first; n <= last; n++ )
245 if ( n < last ) v_next = points[n + 1];
246 else v_next = v_first;
248 /* compute the in and out vectors */
249 in.x = v_cur.x - v_prev.x;
250 in.y = v_cur.y - v_prev.y;
252 out.x = v_next.x - v_cur.x;
253 out.y = v_next.y - v_cur.y;
255 angle_in = FT_Atan2( in.x, in.y );
256 angle_out = FT_Atan2( out.x, out.y );
257 angle_diff = FT_Angle_Diff( angle_in, angle_out );
258 scale = FT_Cos( angle_diff/2 );
260 if ( scale < 0x400L && scale > -0x400L )
268 d = FT_DivFix( distance, scale );
270 FT_Vector_From_Polar( &in, d, angle_in + angle_diff/2 - rotate );
272 outline->points[n].x = v_cur.x + distance + in.x;
273 outline->points[n].y = v_cur.y + distance + in.y;
282 slot->metrics.horiAdvance = ( slot->metrics.horiAdvance + distance*4 ) & -64;