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