misc/libfreetype/src/base/ftsynth.c
author nemo
Sun, 02 Sep 2012 09:23:36 -0400
changeset 7649 df90970ae81a
parent 5172 88f2e05288ba
permissions -rw-r--r--
Correct snow fall/rotation (matching visual gear)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftsynth.c                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType synthesizing code for emboldening and slanting (body).      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2010 by             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_SYNTHESIS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_OUTLINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_BITMAP_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#define FT_COMPONENT  trace_synth
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /****   EXPERIMENTAL OBLIQUING SUPPORT                                ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /* documentation is in ftsynth.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  FT_GlyphSlot_Oblique( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    FT_Matrix    transform;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    FT_Outline*  outline = &slot->outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    /* only oblique outline glyphs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    /* we don't touch the advance width */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    /* For italic, simply apply a shear transform, with an angle */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    /* of about 12 degrees.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    transform.xx = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    transform.yx = 0x00000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    transform.xy = 0x06000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    transform.yy = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    FT_Outline_Transform( outline, &transform );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  /****   EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT                    ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  /* documentation is in ftsynth.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  FT_GlyphSlot_Embolden( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    FT_Library  library = slot->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    FT_Face     face    = slot->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    FT_Pos      xstr, ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    if ( slot->format != FT_GLYPH_FORMAT_OUTLINE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
         slot->format != FT_GLYPH_FORMAT_BITMAP  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    /* some reasonable strength */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    xstr = FT_MulFix( face->units_per_EM,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
                      face->size->metrics.y_scale ) / 24;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    ystr = xstr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
      /* ignore error */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
      (void)FT_Outline_Embolden( &slot->outline, xstr );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
      /* this is more than enough for most glyphs; if you need accurate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
      /* values, you have to call FT_Outline_Get_CBox                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
      xstr = xstr * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
      ystr = xstr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    else /* slot->format == FT_GLYPH_FORMAT_BITMAP */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
      /* round to full pixels */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      xstr &= ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
      if ( xstr == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
        xstr = 1 << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
      ystr &= ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
       * XXX: overflow check for 16-bit system, for compatibility
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
       *      with FT_GlyphSlot_Embolden() since freetype-2.1.10.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
       *      unfortunately, this function return no informations
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
       *      about the cause of error.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
        FT_TRACE1(( "FT_GlyphSlot_Embolden:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
        FT_TRACE1(( "too strong embolding parameter ystr=%d\n", ystr ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
      error = FT_GlyphSlot_Own_Bitmap( slot );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    if ( slot->advance.x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
      slot->advance.x += xstr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    if ( slot->advance.y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
      slot->advance.y += ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    slot->metrics.width        += xstr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    slot->metrics.height       += ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    slot->metrics.horiBearingY += ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    slot->metrics.horiAdvance  += xstr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    slot->metrics.vertBearingX -= xstr / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    slot->metrics.vertBearingY += ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    slot->metrics.vertAdvance  += ystr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    /* XXX: 16-bit overflow case must be excluded before here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      slot->bitmap_top += (FT_Int)( ystr >> 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
/* END */