Edit

kc3-lang/freetype/src/base/ftadvanc.c

Branch :

  • Show log

    Commit

  • Author : Werner Lemberg
    Date : 2017-04-22 13:27:21
    Hash : 5aa6716a
    Message : Add new `slight' auto-hinting mode. This mode uses fractional advance widths and doesn't scale glyphs horizontally, only applying vertical scaling and hinting. At the same time, the behaviour of the `light' auto-hinter gets restored for backwards compatibility: Both vertical and horizontal scaling is again based on rounded metrics values (this was changed in a commit from 2017-03-30 as a side effect). To be more precise, the behaviour is restored for TrueType fonts only; for other font formats like Type 1, this is a new feature of the `light' hinting mode. * include/freetype/freetype.h (FT_LOAD_TARGET_SLIGHT): New macro. (FT_RENDER_MODE_SLIGHT): New render mode. * include/freetype/internal/ftobjs.h (FT_Size_InternalRec): Add `autohint_mode' and `autohint_metrics' fields. * src/autofit/afcjk.c (af_cjk_hints_init), src/autofit/aflatin.c (af_latin_hints_init), src/autofit/aflatin2 (af_latin2_hints_init): Updated. * src/autofit/afloader.c (af_loader_embolden_glyph_in_slot): Use `autohint_metrics'. (af_loader_load_glyph): s/internal/slot_internal/. Initialize `autohint_metrics' and `autohint_mode' depending on current auto-hint mode. Use `autohint_metrics'. Updated. * src/base/ftadvanc.c (LOAD_ADVANCE_FAST_CHECK): Updated. * src/base/ftobjs.c (FT_Load_Glyph): Updated. (FT_New_Size): Allocate `internal' object. * src/pshinter/pshalgo.c (ps_hints_apply): Updated. * src/smooth/ftsmooth.c (ft_smooth_render): Updated.

  • src/base/ftadvanc.c
  • /***************************************************************************/
    /*                                                                         */
    /*  ftadvanc.c                                                             */
    /*                                                                         */
    /*    Quick computation of advance widths (body).                          */
    /*                                                                         */
    /*  Copyright 2008-2017 by                                                 */
    /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
    /*                                                                         */
    /*  This file is part of the FreeType project, and may only be used,       */
    /*  modified, and distributed under the terms of the FreeType project      */
    /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
    /*  this file you indicate that you have read the license and              */
    /*  understand and accept it fully.                                        */
    /*                                                                         */
    /***************************************************************************/
    
    
    #include <ft2build.h>
    #include FT_INTERNAL_DEBUG_H
    
    #include FT_ADVANCES_H
    #include FT_INTERNAL_OBJECTS_H
    
    
      static FT_Error
      _ft_face_scale_advances( FT_Face    face,
                               FT_Fixed*  advances,
                               FT_UInt    count,
                               FT_Int32   flags )
      {
        FT_Fixed  scale;
        FT_UInt   nn;
    
    
        if ( flags & FT_LOAD_NO_SCALE )
          return FT_Err_Ok;
    
        if ( !face->size )
          return FT_THROW( Invalid_Size_Handle );
    
        if ( flags & FT_LOAD_VERTICAL_LAYOUT )
          scale = face->size->metrics.y_scale;
        else
          scale = face->size->metrics.x_scale;
    
        /* this must be the same scaling as to get linear{Hori,Vert}Advance */
        /* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c)        */
    
        for ( nn = 0; nn < count; nn++ )
          advances[nn] = FT_MulDiv( advances[nn], scale, 64 );
    
        return FT_Err_Ok;
      }
    
    
       /* at the moment, we can perform fast advance retrieval only in */
       /* the following cases:                                         */
       /*                                                              */
       /*  - unscaled load                                             */
       /*  - unhinted load                                             */
       /*  - light-hinted and slight-hinted load                       */
       /*  - if a variations font, it must have an `HVAR' or `VVAR'    */
       /*    table (thus the old MM or GX fonts don't qualify; this    */
       /*    gets checked by the driver-specific functions)            */
    
    #define LOAD_ADVANCE_FAST_CHECK( face, flags )                           \
              ( flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING )         || \
                ( FT_LOAD_TARGET_MODE( flags ) == FT_RENDER_MODE_LIGHT  ||   \
                  FT_LOAD_TARGET_MODE( flags ) == FT_RENDER_MODE_SLIGHT ) )
    
    
      /* documentation is in ftadvanc.h */
    
      FT_EXPORT_DEF( FT_Error )
      FT_Get_Advance( FT_Face    face,
                      FT_UInt    gindex,
                      FT_Int32   flags,
                      FT_Fixed  *padvance )
      {
        FT_Face_GetAdvancesFunc  func;
    
    
        if ( !face )
          return FT_THROW( Invalid_Face_Handle );
    
        if ( !padvance )
          return FT_THROW( Invalid_Argument );
    
        if ( gindex >= (FT_UInt)face->num_glyphs )
          return FT_THROW( Invalid_Glyph_Index );
    
        func = face->driver->clazz->get_advances;
        if ( func && LOAD_ADVANCE_FAST_CHECK( face, flags ) )
        {
          FT_Error  error;
    
    
          error = func( face, gindex, 1, flags, padvance );
          if ( !error )
            return _ft_face_scale_advances( face, padvance, 1, flags );
    
          if ( FT_ERR_NEQ( error, Unimplemented_Feature ) )
            return error;
        }
    
        return FT_Get_Advances( face, gindex, 1, flags, padvance );
      }
    
    
      /* documentation is in ftadvanc.h */
    
      FT_EXPORT_DEF( FT_Error )
      FT_Get_Advances( FT_Face    face,
                       FT_UInt    start,
                       FT_UInt    count,
                       FT_Int32   flags,
                       FT_Fixed  *padvances )
      {
        FT_Face_GetAdvancesFunc  func;
        FT_UInt                  num, end, nn;
        FT_Error                 error = FT_Err_Ok;
    
    
        if ( !face )
          return FT_THROW( Invalid_Face_Handle );
    
        if ( !padvances )
          return FT_THROW( Invalid_Argument );
    
        num = (FT_UInt)face->num_glyphs;
        end = start + count;
        if ( start >= num || end < start || end > num )
          return FT_THROW( Invalid_Glyph_Index );
    
        if ( count == 0 )
          return FT_Err_Ok;
    
        func = face->driver->clazz->get_advances;
        if ( func && LOAD_ADVANCE_FAST_CHECK( face, flags ) )
        {
          error = func( face, start, count, flags, padvances );
          if ( !error )
            return _ft_face_scale_advances( face, padvances, count, flags );
    
          if ( FT_ERR_NEQ( error, Unimplemented_Feature ) )
            return error;
        }
    
        error = FT_Err_Ok;
    
        if ( flags & FT_ADVANCE_FLAG_FAST_ONLY )
          return FT_THROW( Unimplemented_Feature );
    
        flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY;
        for ( nn = 0; nn < count; nn++ )
        {
          error = FT_Load_Glyph( face, start + nn, flags );
          if ( error )
            break;
    
          /* scale from 26.6 to 16.16 */
          padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT )
                          ? face->glyph->advance.y * 1024
                          : face->glyph->advance.x * 1024;
        }
    
        return error;
      }
    
    
    /* END */