1 /****************************************************************************
5 * FreeType synthesizing code for emboldening and slanting (body).
7 * Copyright (C) 2000-2023 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.
19 #include <freetype/ftsynth.h>
20 #include <freetype/internal/ftdebug.h>
21 #include <freetype/internal/ftobjs.h>
22 #include <freetype/ftoutln.h>
23 #include <freetype/ftbitmap.h>
26 /**************************************************************************
28 * The macro FT_COMPONENT is used in trace mode. It is an implicit
29 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
30 * messages during execution.
33 #define FT_COMPONENT synth
36 /*************************************************************************/
37 /*************************************************************************/
39 /**** EXPERIMENTAL OBLIQUING SUPPORT ****/
41 /*************************************************************************/
42 /*************************************************************************/
44 /* documentation is in ftsynth.h */
47 FT_GlyphSlot_Oblique( FT_GlyphSlot slot )
49 /* Value '0x0366A' corresponds to a shear angle of about 12 degrees. */
50 FT_GlyphSlot_Slant( slot, 0x0366A, 0 );
54 /* documentation is in ftsynth.h */
57 FT_GlyphSlot_Slant( FT_GlyphSlot slot,
68 outline = &slot->outline;
70 /* only oblique outline glyphs */
71 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
74 /* we don't touch the advance width */
76 /* For italic, simply apply a shear transform */
77 transform.xx = 0x10000L;
78 transform.yx = -yslant;
80 transform.xy = xslant;
81 transform.yy = 0x10000L;
83 FT_Outline_Transform( outline, &transform );
87 /*************************************************************************/
88 /*************************************************************************/
90 /**** EXPERIMENTAL EMBOLDENING SUPPORT ****/
92 /*************************************************************************/
93 /*************************************************************************/
96 /* documentation is in ftsynth.h */
99 FT_GlyphSlot_Embolden( FT_GlyphSlot slot )
101 FT_GlyphSlot_AdjustWeight( slot, 0x0AAA, 0x0AAA );
105 FT_EXPORT_DEF( void )
106 FT_GlyphSlot_AdjustWeight( FT_GlyphSlot slot,
119 library = slot->library;
120 size = slot->face->size;
122 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE &&
123 slot->format != FT_GLYPH_FORMAT_BITMAP )
126 /* express deltas in pixels in 26.6 format */
127 xstr = (FT_Pos)size->metrics.x_ppem * xdelta / 1024;
128 ystr = (FT_Pos)size->metrics.y_ppem * ydelta / 1024;
130 if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
131 FT_Outline_EmboldenXY( &slot->outline, xstr, ystr );
133 else /* slot->format == FT_GLYPH_FORMAT_BITMAP */
135 /* round to full pixels */
142 * XXX: overflow check for 16-bit system, for compatibility
143 * with FT_GlyphSlot_Embolden() since FreeType 2.1.10.
144 * unfortunately, this function return no informations
145 * about the cause of error.
147 if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN )
149 FT_TRACE1(( "FT_GlyphSlot_Embolden:" ));
150 FT_TRACE1(( "too strong emboldening parameter ystr=%ld\n", ystr ));
153 error = FT_GlyphSlot_Own_Bitmap( slot );
157 error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
162 if ( slot->advance.x )
163 slot->advance.x += xstr;
165 if ( slot->advance.y )
166 slot->advance.y += ystr;
168 slot->metrics.width += xstr;
169 slot->metrics.height += ystr;
170 slot->metrics.horiAdvance += xstr;
171 slot->metrics.vertAdvance += ystr;
172 slot->metrics.horiBearingY += ystr;
174 /* XXX: 16-bit overflow case must be excluded before here */
175 if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
176 slot->bitmap_top += (FT_Int)( ystr >> 6 );