Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
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-2006, 2010, 2012 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  /**** ****/
40  /**** EXPERIMENTAL OBLIQUING SUPPORT ****/
41  /**** ****/
42  /*************************************************************************/
43  /*************************************************************************/
44 
45  /* documentation is in ftsynth.h */
46 
47  FT_EXPORT_DEF( void )
49  {
51  FT_Outline* outline = &slot->outline;
52 
53 
54  /* only oblique outline glyphs */
55  if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
56  return;
57 
58  /* we don't touch the advance width */
59 
60  /* For italic, simply apply a shear transform, with an angle */
61  /* of about 12 degrees. */
62 
63  transform.xx = 0x10000L;
64  transform.yx = 0x00000L;
65 
66  transform.xy = 0x0366AL;
67  transform.yy = 0x10000L;
68 
69  FT_Outline_Transform( outline, &transform );
70  }
71 
72 
73  /*************************************************************************/
74  /*************************************************************************/
75  /**** ****/
76  /**** EXPERIMENTAL EMBOLDENING SUPPORT ****/
77  /**** ****/
78  /*************************************************************************/
79  /*************************************************************************/
80 
81 
82  /* documentation is in ftsynth.h */
83 
84  FT_EXPORT_DEF( void )
86  {
87  FT_Library library = slot->library;
88  FT_Face face = slot->face;
90  FT_Pos xstr, ystr;
91 
92 
93  if ( slot->format != FT_GLYPH_FORMAT_OUTLINE &&
94  slot->format != FT_GLYPH_FORMAT_BITMAP )
95  return;
96 
97  /* some reasonable strength */
98  xstr = FT_MulFix( face->units_per_EM,
99  face->size->metrics.y_scale ) / 24;
100  ystr = xstr;
101 
102  if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
103  {
104  /* ignore error */
105  (void)FT_Outline_EmboldenXY( &slot->outline, xstr, ystr );
106  }
107  else /* slot->format == FT_GLYPH_FORMAT_BITMAP */
108  {
109  /* round to full pixels */
110  xstr &= ~63;
111  if ( xstr == 0 )
112  xstr = 1 << 6;
113  ystr &= ~63;
114 
115  /*
116  * XXX: overflow check for 16-bit system, for compatibility
117  * with FT_GlyphSlot_Embolden() since freetype-2.1.10.
118  * unfortunately, this function return no informations
119  * about the cause of error.
120  */
121  if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN )
122  {
123  FT_TRACE1(( "FT_GlyphSlot_Embolden:" ));
124  FT_TRACE1(( "too strong embolding parameter ystr=%d\n", ystr ));
125  return;
126  }
127  error = FT_GlyphSlot_Own_Bitmap( slot );
128  if ( error )
129  return;
130 
131  error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
132  if ( error )
133  return;
134  }
135 
136  if ( slot->advance.x )
137  slot->advance.x += xstr;
138 
139  if ( slot->advance.y )
140  slot->advance.y += ystr;
141 
142  slot->metrics.width += xstr;
143  slot->metrics.height += ystr;
144  slot->metrics.horiAdvance += xstr;
145  slot->metrics.vertAdvance += ystr;
146 
147  /* XXX: 16-bit overflow case must be excluded before here */
148  if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
149  slot->bitmap_top += (FT_Int)( ystr >> 6 );
150  }
151 
152 
153 /* END */
FT_UShort units_per_EM
Definition: freetype.h:945
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:216
FT_Fixed xy
Definition: fttypes.h:383
signed int FT_Int
Definition: fttypes.h:216
FT_Library library
Definition: cffdrivr.c:414
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
FT_GlyphSlot_Embolden(FT_GlyphSlot slot)
Definition: ftsynth.c:85
#define FT_TRACE1(varformat)
Definition: ftdebug.h:158
GLenum GLuint GLint GLenum face
FT_GlyphSlot_Oblique(FT_GlyphSlot slot)
Definition: ftsynth.c:48
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:703
FT_GlyphSlot_Own_Bitmap(FT_GlyphSlot slot)
Definition: ftbitmap.c:623
#define FT_EXPORT_DEF(x)
Definition: ftconfig.h:32
FT_Error error
Definition: cffdrivr.c:411
#define FT_INT_MIN
Definition: ftstdlib.h:65
FT_Outline_EmboldenXY(FT_Outline *outline, FT_Pos xstrength, FT_Pos ystrength)
Definition: ftoutln.c:900
FT_Size size
Definition: freetype.h:957
FT_Fixed xx
Definition: fttypes.h:383
FT_MulFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:485
FT_Fixed yx
Definition: fttypes.h:384
FT_Fixed y_scale
Definition: freetype.h:1373
GLuint GLenum GLenum transform
#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:284
FT_Size_Metrics metrics
Definition: freetype.h:1406