Guest User

inf_aflatin

a guest
Sep 20th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.63 KB | None | 0 0
  1. --- a/src/autofit/aflatin.c 2014-02-04 04:27:31.814131287 -0600
  2. +++ b/src/autofit/aflatin.c 2014-09-19 22:57:10.382267763 -0500
  3. @@ -24,6 +24,7 @@
  4.  #include "afpic.h"
  5.  #include "aflatin.h"
  6.  #include "aferrors.h"
  7. +#include "strings.h"
  8.  
  9.  
  10.  #ifdef AF_CONFIG_OPTION_USE_WARPER
  11. @@ -40,6 +41,10 @@
  12.  #undef  FT_COMPONENT
  13.  #define FT_COMPONENT  trace_aflatin
  14.  
  15. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  16. +FT_Pos infinality_cur_width = 0;
  17. +#endif
  18. +
  19.  
  20.    /*************************************************************************/
  21.    /*************************************************************************/
  22. @@ -861,7 +866,32 @@
  23.      FT_Pos        delta;
  24.      AF_LatinAxis  axis;
  25.      FT_UInt       nn;
  26. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  27. +    int checked_adjust_heights_env = 0;
  28. +    FT_Bool adjust_heights         = FALSE;
  29. +
  30.  
  31. +    if ( checked_adjust_heights_env == 0 )
  32. +    {
  33. +      char *adjust_heights_env =
  34. +        getenv( "INFINALITY_FT_AUTOHINT_INCREASE_GLYPH_HEIGHTS" );
  35. +      if ( adjust_heights_env != NULL )
  36. +      {
  37. +        if ( strcasecmp(adjust_heights_env, "default" ) != 0 )
  38. +        {
  39. +          if ( strcasecmp(adjust_heights_env, "true") == 0 )
  40. +            adjust_heights = TRUE;
  41. +          else if ( strcasecmp(adjust_heights_env, "1") == 0 )
  42. +            adjust_heights = TRUE;
  43. +          else if ( strcasecmp(adjust_heights_env, "on") == 0 )
  44. +            adjust_heights = TRUE;
  45. +          else if ( strcasecmp(adjust_heights_env, "yes") == 0 )
  46. +            adjust_heights = TRUE;
  47. +        }
  48. +      }
  49. +      checked_adjust_heights_env = 1;
  50. +    }
  51. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  52.  
  53.      if ( dim == AF_DIMENSION_HORZ )
  54.      {
  55. @@ -889,7 +919,7 @@
  56.      {
  57.        AF_LatinAxis  Axis = &metrics->axis[AF_DIMENSION_VERT];
  58.        AF_LatinBlue  blue = NULL;
  59. -
  60. +      int threshold = 40;
  61.  
  62.        for ( nn = 0; nn < Axis->blue_count; nn++ )
  63.        {
  64. @@ -899,7 +929,12 @@
  65.            break;
  66.          }
  67.        }
  68. -
  69. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  70. +      if ( adjust_heights                                       &&
  71. +           metrics->root.scaler.face->size->metrics.x_ppem < 15 &&
  72. +           metrics->root.scaler.face->size->metrics.x_ppem > 5  )
  73. +        threshold = 52;
  74. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  75.        if ( blue )
  76.        {
  77.          FT_Pos   scaled;
  78. @@ -1018,7 +1053,13 @@
  79.  
  80.          /* a blue zone is only active if it is less than 3/4 pixels tall */
  81.          dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale );
  82. +
  83. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  84. +        /* Do at low ppems ( ~< 200 ), in order to prevent fringes */
  85. +        if ( dist <= 256 && dist >= -256 )
  86. +#else
  87.          if ( dist <= 48 && dist >= -48 )
  88. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  89.          {
  90.  #if 0
  91.            FT_Pos  delta1;
  92. @@ -1069,7 +1110,12 @@
  93.              delta2 = -delta2;
  94.  
  95.            blue->ref.fit   = FT_PIX_ROUND( blue->ref.cur );
  96. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  97. +          /* Round to prevent fringes */
  98. +          blue->shoot.fit = FT_PIX_ROUND( blue->ref.fit - delta2 );
  99. +#else
  100.            blue->shoot.fit = blue->ref.fit - delta2;
  101. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  102.  
  103.  #endif
  104.  
  105. @@ -1828,7 +1874,10 @@
  106.                dist = edge->fpos - blue->shoot.org;
  107.                if ( dist < 0 )
  108.                  dist = -dist;
  109. -
  110. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  111. +              /* round down to pixels */
  112. +              /*dist = FT_MulFix( dist, scale ) & ~63;*/
  113. +#endif
  114.                dist = FT_MulFix( dist, scale );
  115.                if ( dist < best_dist )
  116.                {
  117. @@ -1989,8 +2038,31 @@
  118.      FT_Pos           dist     = width;
  119.      FT_Int           sign     = 0;
  120.      FT_Int           vertical = ( dim == AF_DIMENSION_VERT );
  121. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  122. +    FT_Int           infinality_dist = 0;
  123. +    FT_UInt          autohint_snap_stem_height = 0;
  124. +    FT_UInt          checked_autohint_snap_stem_height = 0;
  125. +
  126. +
  127. +    if ( checked_autohint_snap_stem_height == 0 )
  128. +    {
  129. +      char *autohint_snap_stem_height_env =
  130. +        getenv( "INFINALITY_FT_AUTOHINT_SNAP_STEM_HEIGHT" );
  131. +      if ( autohint_snap_stem_height_env != NULL )
  132. +      {
  133. +        sscanf ( autohint_snap_stem_height_env, "%u",
  134. +                 &autohint_snap_stem_height );
  135.  
  136. +        if ( autohint_snap_stem_height > 100 )
  137. +          autohint_snap_stem_height = 100;
  138. +        else if ( autohint_snap_stem_height < 0 )
  139. +          autohint_snap_stem_height = 0;
  140. +      }
  141. +      checked_autohint_snap_stem_height = 1;
  142. +    }
  143.  
  144. +    if ( autohint_snap_stem_height == 0 )
  145. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  146.      if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) ||
  147.           axis->extra_light                       )
  148.        return width;
  149. @@ -2000,9 +2072,73 @@
  150.        dist = -width;
  151.        sign = 1;
  152.      }
  153. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  154. +    /* Calculate snap value differently than standard freetype */
  155. +    if ( autohint_snap_stem_height > 0                              &&
  156. +         ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) )  ||
  157. +           ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) ) )
  158. +    {
  159. +      infinality_dist = af_latin_snap_width( axis->widths,
  160. +                                             axis->width_count, dist );
  161. +
  162. +      if ( metrics->root.scaler.face->size->metrics.x_ppem > 9 &&
  163. +           axis->width_count > 0                               &&
  164. +           abs( axis->widths[0].cur - infinality_dist ) < 32   &&
  165. +           axis->widths[0].cur > 52                            )
  166. +      {
  167. +        if ( strstr( metrics->root.scaler.face->style_name, "Regular" )      ||
  168. +             strstr( metrics->root.scaler.face->style_name, "Book" )         ||
  169. +             strstr( metrics->root.scaler.face->style_name, "Medium" )       ||
  170. +             strcmp( metrics->root.scaler.face->style_name, "Italic" ) == 0  ||
  171. +             strcmp( metrics->root.scaler.face->style_name, "Oblique" ) == 0 )
  172. +        {
  173. +          /* regular weight */
  174. +          if ( axis->widths[0].cur < 64 )
  175. +            infinality_dist = 64;
  176. +          else if ( axis->widths[0].cur  < 88 )
  177. +            infinality_dist = 64;
  178. +          else if ( axis->widths[0].cur  < 160 )
  179. +            infinality_dist = 128;
  180. +          else if ( axis->widths[0].cur  < 240 )
  181. +            infinality_dist = 190;
  182. +          else infinality_dist = ( infinality_dist ) & ~63;
  183. +        }
  184. +        else
  185. +        {
  186. +          /* bold gets a different threshold */
  187. +          if ( axis->widths[0].cur < 64 )
  188. +            infinality_dist = 64 ;
  189. +          else if ( axis->widths[0].cur  < 108 )
  190. +            infinality_dist = 64;
  191. +          else if ( axis->widths[0].cur  < 160 )
  192. +            infinality_dist = 128;
  193. +          else if ( axis->widths[0].cur  < 222 )
  194. +            infinality_dist = 190;
  195. +          else if ( axis->widths[0].cur  < 288 )
  196. +            infinality_dist = 254;
  197. +          else infinality_dist = ( infinality_dist + 16 ) & ~63;
  198. +        }
  199. +
  200. +      }
  201. +      if ( infinality_dist < 52 )
  202. +      {
  203. +        if ( metrics->root.scaler.face->size->metrics.x_ppem < 9 )
  204. +        {
  205. +          if ( infinality_dist < 32 )
  206. +            infinality_dist = 32;
  207. +        }
  208. +        else
  209. +          infinality_dist = 64;
  210. +      }
  211. +    }
  212. +    else if ( autohint_snap_stem_height < 100                            &&
  213. +              ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) )  ||
  214. +                ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) ) )
  215. +#else
  216.  
  217. -    if ( (  vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
  218. +    if ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
  219.           ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
  220. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  221.      {
  222.        /* smooth hinting process: very lightly quantize the stem width */
  223.  
  224. @@ -2062,6 +2198,9 @@
  225.        }
  226.      }
  227.      else
  228. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  229. +      if ( autohint_snap_stem_height < 100 )
  230. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  231.      {
  232.        /* strong hinting process: snap the stem width to integer pixels */
  233.  
  234. @@ -2069,7 +2208,10 @@
  235.  
  236.  
  237.        dist = af_latin_snap_width( axis->widths, axis->width_count, dist );
  238. -
  239. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  240. +      if ( autohint_snap_stem_height > 0 )
  241. +        goto Done_Width;
  242. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  243.        if ( vertical )
  244.        {
  245.          /* in the case of vertical hinting, always round */
  246. @@ -2132,6 +2274,32 @@
  247.      }
  248.  
  249.    Done_Width:
  250. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  251. +    if ( axis->widths[0].cur > 42 )
  252. +      /* weighted average */
  253. +      dist = (dist * ( 100 - autohint_snap_stem_height )
  254. +                + infinality_dist * autohint_snap_stem_height ) / 100;
  255. +
  256. +      {
  257. +        int factor = 100;
  258. +        if ( axis->standard_width < 100 )
  259. +          factor = axis->standard_width;
  260. +
  261. +        if ( metrics->root.scaler.face->size->metrics.x_ppem >= 9  && dist < 52 )
  262. +          dist += ( (52 - dist) * factor ) / 100;
  263. +        if ( metrics->root.scaler.face->size->metrics.x_ppem < 9  && dist < 32 )
  264. +          dist += ( (32 - dist) * factor ) / 100;
  265. +
  266. +        if ( axis->standard_width > 100                             &&
  267. +             metrics->root.scaler.face->size->metrics.x_ppem >= 11  &&
  268. +             dist < 64                                              )
  269. +          dist = 64;
  270. +        if ( axis->standard_width > 100                           &&
  271. +             metrics->root.scaler.face->size->metrics.x_ppem >= 9 &&
  272. +             dist < 52                                            )
  273. +          dist = 52;
  274. +      }
  275. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  276.      if ( sign )
  277.        dist = -dist;
  278.  
  279. @@ -2154,6 +2322,8 @@
  280.                               (AF_Edge_Flags)base_edge->flags,
  281.                               (AF_Edge_Flags)stem_edge->flags );
  282.  
  283. +/* if fitted_width causes stem_edge->pos to land basically on top of an existing
  284. + * stem_edge->pos, then add or remove 64.  Need to figure out a way to do this */
  285.  
  286.      stem_edge->pos = base_edge->pos + fitted_width;
  287.  
  288. @@ -2688,7 +2858,33 @@
  289.    {
  290.      FT_Error  error;
  291.      int       dim;
  292. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  293. +    FT_Int    emboldening_strength = 0;
  294. +    FT_Bool   checked_use_various_tweaks_env = FALSE;
  295. +    FT_Bool   use_various_tweaks = FALSE;
  296. +
  297.  
  298. +    if ( !checked_use_various_tweaks_env )
  299. +    {
  300. +      char *use_various_tweaks_env =
  301. +        getenv( "INFINALITY_FT_USE_VARIOUS_TWEAKS" );
  302. +      if ( use_various_tweaks_env != NULL )
  303. +      {
  304. +        if ( strcasecmp(use_various_tweaks_env, "default" ) != 0 )
  305. +        {
  306. +          if ( strcasecmp(use_various_tweaks_env, "true") == 0 )
  307. +            use_various_tweaks = TRUE;
  308. +          else if ( strcasecmp(use_various_tweaks_env, "1") == 0 )
  309. +            use_various_tweaks = TRUE;
  310. +          else if ( strcasecmp(use_various_tweaks_env, "on") == 0 )
  311. +            use_various_tweaks = TRUE;
  312. +          else if ( strcasecmp(use_various_tweaks_env, "yes") == 0 )
  313. +            use_various_tweaks = TRUE;
  314. +        }
  315. +      }
  316. +      checked_use_various_tweaks_env = TRUE;
  317. +    }
  318. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  319.  
  320.      error = af_glyph_hints_reload( hints, outline );
  321.      if ( error )
  322. @@ -2747,7 +2943,11 @@
  323.      }
  324.  
  325.      af_glyph_hints_save( hints, outline );
  326. -
  327. +#ifdef FT_CONFIG_OPTION_INFINALITY_PATCHSET
  328. +    {
  329. +      infinality_cur_width = metrics->axis->widths[0].cur;
  330. +    }
  331. +#endif /* FT_CONFIG_OPTION_INFINALITY_PATCHSET */
  332.    Exit:
  333.      return error;
  334.    }
Advertisement
Add Comment
Please, Sign In to add comment