zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ftsynth.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* ftsynth.c */
4 /* */
5 /* FreeType synthesizing code for emboldening and slanting (body). */
6 /* */
7 /* Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2010 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
17 
18 
19 #include <ft2build.h>
20 #include FT_SYNTHESIS_H
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_OBJECTS_H
23 #include FT_OUTLINE_H
24 #include FT_BITMAP_H
25 
26 
27  /*************************************************************************/
28  /* */
29  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
30  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
31  /* messages during execution. */
32  /* */
33 #undef FT_COMPONENT
34 #define FT_COMPONENT trace_synth
35 
36  /*************************************************************************/
37  /*************************************************************************/
38  /**** ****/
39  /**** EXPERIMENTAL OBLIQUING SUPPORT ****/
40  /**** ****/
41  /*************************************************************************/
42  /*************************************************************************/
43 
44  /* documentation is in ftsynth.h */
45 
46  FT_EXPORT_DEF( void )
48  {
50  FT_Outline* outline = &slot->outline;
51 
52 
53  /* only oblique outline glyphs */
54  if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
55  return;
56 
57  /* we don't touch the advance width */
58 
59  /* For italic, simply apply a shear transform, with an angle */
60  /* of about 12 degrees. */
61 
62  transform.xx = 0x10000L;
63  transform.yx = 0x00000L;
64 
65  transform.xy = 0x06000L;
66  transform.yy = 0x10000L;
67 
68  FT_Outline_Transform( outline, &transform );
69  }
70 
71 
72  /*************************************************************************/
73  /*************************************************************************/
74  /**** ****/
75  /**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/
76  /**** ****/
77  /*************************************************************************/
78  /*************************************************************************/
79 
80 
81  /* documentation is in ftsynth.h */
82 
83  FT_EXPORT_DEF( void )
85  {
86  FT_Library library = slot->library;
87  FT_Face face = slot->face;
89  FT_Pos xstr, ystr;
90 
91 
92  if ( slot->format != FT_GLYPH_FORMAT_OUTLINE &&
93  slot->format != FT_GLYPH_FORMAT_BITMAP )
94  return;
95 
96  /* some reasonable strength */
97  xstr = FT_MulFix( face->units_per_EM,
98  face->size->metrics.y_scale ) / 24;
99  ystr = xstr;
100 
101  if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
102  {
103  /* ignore error */
104  (void)FT_Outline_Embolden( &slot->outline, xstr );
105 
106  /* this is more than enough for most glyphs; if you need accurate */
107  /* values, you have to call FT_Outline_Get_CBox */
108  xstr = xstr * 2;
109  ystr = xstr;
110  }
111  else /* slot->format == FT_GLYPH_FORMAT_BITMAP */
112  {
113  /* round to full pixels */
114  xstr &= ~63;
115  if ( xstr == 0 )
116  xstr = 1 << 6;
117  ystr &= ~63;
118 
119  /*
120  * XXX: overflow check for 16-bit system, for compatibility
121  * with FT_GlyphSlot_Embolden() since freetype-2.1.10.
122  * unfortunately, this function return no informations
123  * about the cause of error.
124  */
125  if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN )
126  {
127  FT_TRACE1(( "FT_GlyphSlot_Embolden:" ));
128  FT_TRACE1(( "too strong embolding parameter ystr=%d\n", ystr ));
129  return;
130  }
131  error = FT_GlyphSlot_Own_Bitmap( slot );
132  if ( error )
133  return;
134 
135  error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
136  if ( error )
137  return;
138  }
139 
140  if ( slot->advance.x )
141  slot->advance.x += xstr;
142 
143  if ( slot->advance.y )
144  slot->advance.y += ystr;
145 
146  slot->metrics.width += xstr;
147  slot->metrics.height += ystr;
148  slot->metrics.horiBearingY += ystr;
149  slot->metrics.horiAdvance += xstr;
150  slot->metrics.vertBearingX -= xstr / 2;
151  slot->metrics.vertBearingY += ystr;
152  slot->metrics.vertAdvance += ystr;
153 
154  /* XXX: 16-bit overflow case must be excluded before here */
155  if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
156  slot->bitmap_top += (FT_Int)( ystr >> 6 );
157  }
158 
159 
160 /* END */
FT_UShort units_per_EM
Definition: freetype.h:938
int FT_Error
Definition: fttypes.h:296
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:59
FT_Bitmap_Embolden(FT_Library library, FT_Bitmap *bitmap, FT_Pos xStrength, FT_Pos yStrength)
Definition: ftbitmap.c:214
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1824
FT_Fixed xy
Definition: fttypes.h:383
signed int FT_Int
Definition: fttypes.h:216
FT_Outline_Embolden(FT_Outline *outline, FT_Pos strength)
Definition: ftoutln.c:882
FT_Library library
Definition: cffdrivr.c:409
#define FT_TRACE1(varformat)
Definition: ftdebug.h:158
FT_BEGIN_HEADER FT_GlyphSlot_Embolden(FT_GlyphSlot slot)
Definition: ftsynth.c:84
FT_GlyphSlot_Oblique(FT_GlyphSlot slot)
Definition: ftsynth.c:47
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:695
FT_GlyphSlot_Own_Bitmap(FT_GlyphSlot slot)
Definition: ftbitmap.c:621
FT_Error error
Definition: cffdrivr.c:407
GLenum face
Definition: gl2ext.h:1490
#define FT_INT_MIN
Definition: ftstdlib.h:65
#define xstr(s)
FT_Size size
Definition: freetype.h:950
FT_Fixed xx
Definition: fttypes.h:383
FT_MulFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:435
FT_Fixed yx
Definition: fttypes.h:384
FT_Fixed y_scale
Definition: freetype.h:1366
#define FT_EXPORT_DEF(x)
Definition: ftconfig.h:511
GLuint GLenum GLenum transform
Definition: glew.h:13408
#define FT_INT_MAX
Definition: ftstdlib.h:64
FT_Fixed yy
Definition: fttypes.h:384
FT_Module_Constructor FT_GLYPH_FORMAT_OUTLINE
Definition: ftrend1.c:283
FT_Size_Metrics metrics
Definition: freetype.h:1399