Edit

kc3-lang/freetype/src/cff/cffparse.h

Branch :

  • Show log

    Commit

  • Author : Skef Iterum
    Date : 2023-12-14 06:59:05
    Hash : 8eab5110
    Message : [CFF] Extract `BlueValues` as `Fixed` rather than `Int`. This is a follow-up to commit 26a7f047, [cff] Make blend operator work with floats in private dicts. which addressed the 'party baseline' bug. However, the reporting user indicated that the default location and some other points in design space rendered OK, but other points in design space still had problems. The most obvious issue being that the x-heights of lower-case letters did not align; see https://github.com/adobe-fonts/source-serif/issues/121#issuecomment-1773794136 After some analysis we determined that this was due to an interaction between `BlueValue` rounding and the zone-based algorithm. In short, for a point to be considered in a zone it must fall within the bounds of the zone. (There is a slop factor in some cases, but only a very small one.) In the Adobe-contributed side of the code, point values are not integer-rounded, instead they're kept as (some form of) fixed. Rounding just the `BlueValues` means that points that need to be considered within a zone will fall outside of it at some points in design space. The majority of this patch changes the storage and parsing of `BlueValues` to keep them as `FT_Fixed`. No significant code changes were needed because the values are converted to `Fixed` anyway when stored in `CF_BlueRec`. No attempt was made to address problems in the older pshinter code beyond converting the values from `FT_Fixed` to `FT_Short` when copying the private dictionary. (However, as the point values are also rounded in that code, the problem is much less likely to occur, although inconsistency between rounding and truncation could cause an analogous problem.) * include/freetype/internal/cfftypes.h (CFF_PrivateRec): Use `FT_Fixed` for `blue_values`, `other_blues`, `family_blues`, and `family_other_blues`. * src/cff/cffload.c (cff_blend_doBlend): Updated. * src/cff/cffobjs.c (CFF_fixedToInt): New macro. (cff_make_private_dict): Use it. * src/cff/cffparse.h (cff_kind_delta_fixed): New enum value. * src/cff/cffparse.c (do_fixed): Updated. (CFF_FIELD_DELTA, CFF_FIELD_DELTA_FIXED, CFF_DELTA_KIND): New set of macros, replacing `CFF_FIELD_DELTA`. (cff_parser_run): Updated to handle fixed-float deltas. * src/cff/cfftoken.h: Updated to use `CFF_FIELD_DELTA_FIXED` for blue values. * src/psaux/psblues.c (cf2_blueToFixed): Removed, no longer needed. (cf2_blues_init): Updated. * src/pxaux/psft.c, src/pxaux/psft.h (cf2_getBlueValues, cf2_getOtherBlues, cf2_getFamilyBlues, cf2_getFamilyOtherBlues): Updated signatures. * src/psaux/psobjs.c (t1_make_subfont): Updated.

  • src/cff/cffparse.h
  • /****************************************************************************
     *
     * cffparse.h
     *
     *   CFF token stream parser (specification)
     *
     * Copyright (C) 1996-2023 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.
     *
     */
    
    
    #ifndef CFFPARSE_H_
    #define CFFPARSE_H_
    
    
    #include <freetype/internal/cfftypes.h>
    #include <freetype/internal/ftobjs.h>
    
    
    FT_BEGIN_HEADER
    
    
      /* CFF uses constant parser stack size; */
      /* CFF2 can increase from default 193   */
    #define CFF_MAX_STACK_DEPTH  96
    
      /*
       * There are plans to remove the `maxstack' operator in a forthcoming
       * revision of the CFF2 specification, increasing the (then static) stack
       * size to 513.  By making the default stack size equal to the maximum
       * stack size, the operator is essentially disabled, which has the
       * desired effect in FreeType.
       */
    #define CFF2_MAX_STACK      513
    #define CFF2_DEFAULT_STACK  513
    
    #define CFF_CODE_TOPDICT    0x1000
    #define CFF_CODE_PRIVATE    0x2000
    #define CFF2_CODE_TOPDICT   0x3000
    #define CFF2_CODE_FONTDICT  0x4000
    #define CFF2_CODE_PRIVATE   0x5000
    
    
      typedef struct  CFF_ParserRec_
      {
        FT_Library  library;
        FT_Byte*    start;
        FT_Byte*    limit;
        FT_Byte*    cursor;
    
        FT_Byte**   stack;
        FT_Byte**   top;
        FT_UInt     stackSize;  /* allocated size */
    
    #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
        FT_ListRec  t2_strings;
    #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
    
        FT_UInt     object_code;
        void*       object;
    
        FT_UShort   num_designs; /* a copy of `CFF_FontRecDict->num_designs' */
        FT_UShort   num_axes;    /* a copy of `CFF_FontRecDict->num_axes'    */
    
      } CFF_ParserRec, *CFF_Parser;
    
    
      FT_LOCAL( FT_Long )
      cff_parse_num( CFF_Parser  parser,
                     FT_Byte**   d );
    
      FT_LOCAL( FT_Fixed )
      cff_parse_fixed( CFF_Parser  parser,
                       FT_Byte**   d );
    
      FT_LOCAL( FT_Error )
      cff_parser_init( CFF_Parser  parser,
                       FT_UInt     code,
                       void*       object,
                       FT_Library  library,
                       FT_UInt     stackSize,
                       FT_UShort   num_designs,
                       FT_UShort   num_axes );
    
      FT_LOCAL( void )
      cff_parser_done( CFF_Parser  parser );
    
      FT_LOCAL( FT_Error )
      cff_parser_run( CFF_Parser  parser,
                      FT_Byte*    start,
                      FT_Byte*    limit );
    
    
      enum
      {
        cff_kind_none = 0,
        cff_kind_num,
        cff_kind_fixed,
        cff_kind_fixed_thousand,
        cff_kind_string,
        cff_kind_bool,
        cff_kind_delta,
        cff_kind_delta_fixed,
        cff_kind_callback,
        cff_kind_blend,
    
        cff_kind_max  /* do not remove */
      };
    
    
      /* now generate handlers for the most simple fields */
      typedef FT_Error  (*CFF_Field_Reader)( CFF_Parser  parser );
    
      typedef struct  CFF_Field_Handler_
      {
        int               kind;
        int               code;
        FT_UInt           offset;
        FT_Byte           size;
        CFF_Field_Reader  reader;
        FT_UInt           array_max;
        FT_UInt           count_offset;
    
    #ifdef FT_DEBUG_LEVEL_TRACE
        const char*       id;
    #endif
    
      } CFF_Field_Handler;
    
    
    FT_END_HEADER
    
    
    #endif /* CFFPARSE_H_ */
    
    
    /* END */