1 /**************************************************************************** 2 * 3 * ftsynth.c 4 * 5 * FreeType synthesizing code for emboldening and slanting (body). 6 * 7 * Copyright (C) 2000-2023 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 <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> 24 25 26 /************************************************************************** 27 * 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. 31 */ 32 #undef FT_COMPONENT 33 #define FT_COMPONENT synth 34 35 36 /*************************************************************************/ 37 /*************************************************************************/ 38 /**** ****/ 39 /**** EXPERIMENTAL OBLIQUING SUPPORT ****/ 40 /**** ****/ 41 /*************************************************************************/ 42 /*************************************************************************/ 43 44 /* documentation is in ftsynth.h */ 45 46 FT_EXPORT_DEF( void ) FT_GlyphSlot_Oblique(FT_GlyphSlot slot)47 FT_GlyphSlot_Oblique( FT_GlyphSlot slot ) 48 { 49 /* Value '0x0366A' corresponds to a shear angle of about 12 degrees. */ 50 FT_GlyphSlot_Slant( slot, 0x0366A, 0 ); 51 } 52 53 54 /* documentation is in ftsynth.h */ 55 56 FT_EXPORT_DEF( void ) FT_GlyphSlot_Slant(FT_GlyphSlot slot,FT_Fixed xslant,FT_Fixed yslant)57 FT_GlyphSlot_Slant( FT_GlyphSlot slot, 58 FT_Fixed xslant, 59 FT_Fixed yslant ) 60 { 61 FT_Matrix transform; 62 FT_Outline* outline; 63 64 65 if ( !slot ) 66 return; 67 68 outline = &slot->outline; 69 70 /* only oblique outline glyphs */ 71 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) 72 return; 73 74 /* we don't touch the advance width */ 75 76 /* For italic, simply apply a shear transform */ 77 transform.xx = 0x10000L; 78 transform.yx = -yslant; 79 80 transform.xy = xslant; 81 transform.yy = 0x10000L; 82 83 FT_Outline_Transform( outline, &transform ); 84 } 85 86 87 /*************************************************************************/ 88 /*************************************************************************/ 89 /**** ****/ 90 /**** EXPERIMENTAL EMBOLDENING SUPPORT ****/ 91 /**** ****/ 92 /*************************************************************************/ 93 /*************************************************************************/ 94 95 96 /* documentation is in ftsynth.h */ 97 98 FT_EXPORT_DEF( void ) FT_GlyphSlot_Embolden(FT_GlyphSlot slot)99 FT_GlyphSlot_Embolden( FT_GlyphSlot slot ) 100 { 101 FT_Library library; 102 FT_Face face; 103 FT_Error error; 104 FT_Pos xstr, ystr; 105 106 107 if ( !slot ) 108 return; 109 110 library = slot->library; 111 face = slot->face; 112 113 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE && 114 slot->format != FT_GLYPH_FORMAT_BITMAP ) 115 return; 116 117 /* some reasonable strength */ 118 xstr = FT_MulFix( face->units_per_EM, 119 face->size->metrics.y_scale ) / 24; 120 ystr = xstr; 121 122 if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) 123 FT_Outline_EmboldenXY( &slot->outline, xstr, ystr ); 124 125 else /* slot->format == FT_GLYPH_FORMAT_BITMAP */ 126 { 127 /* round to full pixels */ 128 xstr &= ~63; 129 if ( xstr == 0 ) 130 xstr = 1 << 6; 131 ystr &= ~63; 132 133 /* 134 * XXX: overflow check for 16-bit system, for compatibility 135 * with FT_GlyphSlot_Embolden() since FreeType 2.1.10. 136 * unfortunately, this function return no informations 137 * about the cause of error. 138 */ 139 if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN ) 140 { 141 FT_TRACE1(( "FT_GlyphSlot_Embolden:" )); 142 FT_TRACE1(( "too strong emboldening parameter ystr=%ld\n", ystr )); 143 return; 144 } 145 error = FT_GlyphSlot_Own_Bitmap( slot ); 146 if ( error ) 147 return; 148 149 error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr ); 150 if ( error ) 151 return; 152 } 153 154 if ( slot->advance.x ) 155 slot->advance.x += xstr; 156 157 if ( slot->advance.y ) 158 slot->advance.y += ystr; 159 160 slot->metrics.width += xstr; 161 slot->metrics.height += ystr; 162 slot->metrics.horiAdvance += xstr; 163 slot->metrics.vertAdvance += ystr; 164 slot->metrics.horiBearingY += ystr; 165 166 /* XXX: 16-bit overflow case must be excluded before here */ 167 if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) 168 slot->bitmap_top += (FT_Int)( ystr >> 6 ); 169 } 170 171 172 /* END */ 173