| 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 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_OBJECTS_H |
|---|
| 22 | #include FT_OUTLINE_H |
|---|
| 23 | #include FT_BITMAP_H |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | /*************************************************************************/ |
|---|
| 27 | /*************************************************************************/ |
|---|
| 28 | /**** ****/ |
|---|
| 29 | /**** EXPERIMENTAL OBLIQUING SUPPORT ****/ |
|---|
| 30 | /**** ****/ |
|---|
| 31 | /*************************************************************************/ |
|---|
| 32 | /*************************************************************************/ |
|---|
| 33 | |
|---|
| 34 | /* documentation is in ftsynth.h */ |
|---|
| 35 | |
|---|
| 36 | FT_EXPORT_DEF( void ) |
|---|
| 37 | FT_GlyphSlot_Oblique( FT_GlyphSlot slot ) |
|---|
| 38 | { |
|---|
| 39 | FT_Matrix transform; |
|---|
| 40 | FT_Outline* outline = &slot->outline; |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | /* only oblique outline glyphs */ |
|---|
| 44 | if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) |
|---|
| 45 | return; |
|---|
| 46 | |
|---|
| 47 | /* we don't touch the advance width */ |
|---|
| 48 | |
|---|
| 49 | /* For italic, simply apply a shear transform, with an angle */ |
|---|
| 50 | /* of about 12 degrees. */ |
|---|
| 51 | |
|---|
| 52 | transform.xx = 0x10000L; |
|---|
| 53 | transform.yx = 0x00000L; |
|---|
| 54 | |
|---|
| 55 | transform.xy = 0x06000L; |
|---|
| 56 | transform.yy = 0x10000L; |
|---|
| 57 | |
|---|
| 58 | FT_Outline_Transform( outline, &transform ); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | /*************************************************************************/ |
|---|
| 63 | /*************************************************************************/ |
|---|
| 64 | /**** ****/ |
|---|
| 65 | /**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/ |
|---|
| 66 | /**** ****/ |
|---|
| 67 | /*************************************************************************/ |
|---|
| 68 | /*************************************************************************/ |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | /* documentation is in ftsynth.h */ |
|---|
| 72 | |
|---|
| 73 | FT_EXPORT_DEF( void ) |
|---|
| 74 | FT_GlyphSlot_Embolden( FT_GlyphSlot slot ) |
|---|
| 75 | { |
|---|
| 76 | FT_Library library = slot->library; |
|---|
| 77 | FT_Face face = slot->face; |
|---|
| 78 | FT_Error error; |
|---|
| 79 | FT_Pos xstr, ystr; |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | if ( slot->format != FT_GLYPH_FORMAT_OUTLINE && |
|---|
| 83 | slot->format != FT_GLYPH_FORMAT_BITMAP ) |
|---|
| 84 | return; |
|---|
| 85 | |
|---|
| 86 | /* some reasonable strength */ |
|---|
| 87 | xstr = FT_MulFix( face->units_per_EM, |
|---|
| 88 | face->size->metrics.y_scale ) / 24; |
|---|
| 89 | ystr = xstr; |
|---|
| 90 | |
|---|
| 91 | if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) |
|---|
| 92 | { |
|---|
| 93 | error = FT_Outline_Embolden( &slot->outline, xstr ); |
|---|
| 94 | /* ignore error */ |
|---|
| 95 | |
|---|
| 96 | /* this is more than enough for most glyphs; if you need accurate */ |
|---|
| 97 | /* values, you have to call FT_Outline_Get_CBox */ |
|---|
| 98 | xstr = xstr * 2; |
|---|
| 99 | ystr = xstr; |
|---|
| 100 | } |
|---|
| 101 | else if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) |
|---|
| 102 | { |
|---|
| 103 | /* round to full pixels */ |
|---|
| 104 | xstr &= ~63; |
|---|
| 105 | if ( xstr == 0 ) |
|---|
| 106 | xstr = 1 << 6; |
|---|
| 107 | ystr &= ~63; |
|---|
| 108 | |
|---|
| 109 | error = FT_GlyphSlot_Own_Bitmap( slot ); |
|---|
| 110 | if ( error ) |
|---|
| 111 | return; |
|---|
| 112 | |
|---|
| 113 | error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr ); |
|---|
| 114 | if ( error ) |
|---|
| 115 | return; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | if ( slot->advance.x ) |
|---|
| 119 | slot->advance.x += xstr; |
|---|
| 120 | |
|---|
| 121 | if ( slot->advance.y ) |
|---|
| 122 | slot->advance.y += ystr; |
|---|
| 123 | |
|---|
| 124 | slot->metrics.width += xstr; |
|---|
| 125 | slot->metrics.height += ystr; |
|---|
| 126 | slot->metrics.horiBearingY += ystr; |
|---|
| 127 | slot->metrics.horiAdvance += xstr; |
|---|
| 128 | slot->metrics.vertBearingX -= xstr / 2; |
|---|
| 129 | slot->metrics.vertBearingY += ystr; |
|---|
| 130 | slot->metrics.vertAdvance += ystr; |
|---|
| 131 | |
|---|
| 132 | if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) |
|---|
| 133 | slot->bitmap_top += ystr >> 6; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | /* END */ |
|---|