Advertisement
Guest User

brebs

a guest
Aug 7th, 2010
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 31.83 KB | None | 0 0
  1. From http://www.infinality.net/fedora/linux/13/SRPMS/freetype-subpixel-2.3.12-3.fc13.src.rpm
  2. and modified to patch freetype 2.4.2
  3. See http://www.infinality.net/blog/?p=67
  4. and http://forums.gentoo.org/viewtopic-p-6350912.html#6350912
  5.  
  6. Added:
  7. freetype-2.3.0-enable-spr.patch from Fedora's src.rpm
  8. freetype-2.2.1-enable-valid.patch from Fedora's src.rpm
  9. freetype-2.2.1-memcpy-fix.patch from Fedora's src.rpm
  10. And #define FT_CONFIG_OPTION_SYSTEM_ZLIB in include/freetype/config/ftoption.h
  11.  
  12.  
  13. diff -Naur freetype-2.4.2-orig//include/freetype/config/ftoption.h freetype-2.4.2/include/freetype/config/ftoption.h
  14. --- freetype-2.4.2-orig//include/freetype/config/ftoption.h 2010-07-05 11:38:55.000000000 +0700
  15. +++ freetype-2.4.2/include/freetype/config/ftoption.h   2010-08-07 22:52:47.000000000 +0700
  16. @@ -93,7 +93,7 @@
  17.    /* This is done to allow FreeType clients to run unmodified, forcing     */
  18.    /* them to display normal gray-level anti-aliased glyphs.                */
  19.    /*                                                                       */
  20. -/* #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
  21. +#define FT_CONFIG_OPTION_SUBPIXEL_RENDERING
  22.  
  23.  
  24.    /*************************************************************************/
  25. @@ -185,7 +185,7 @@
  26.    /*   Do not #undef this macro here since the build system might define   */
  27.    /*   it for certain configurations only.                                 */
  28.    /*                                                                       */
  29. -/* #define FT_CONFIG_OPTION_SYSTEM_ZLIB */
  30. +#define FT_CONFIG_OPTION_SYSTEM_ZLIB
  31.  
  32.  
  33.    /*************************************************************************/
  34. diff -Naur freetype-2.4.2-orig//include/freetype/freetype.h freetype-2.4.2/include/freetype/freetype.h
  35. --- freetype-2.4.2-orig//include/freetype/freetype.h    2010-08-07 02:51:58.000000000 +0700
  36. +++ freetype-2.4.2/include/freetype/freetype.h  2010-08-07 22:52:47.000000000 +0700
  37. @@ -2516,6 +2516,7 @@
  38.  #define FT_LOAD_MONOCHROME                   0x1000
  39.  #define FT_LOAD_LINEAR_DESIGN                0x2000
  40.  #define FT_LOAD_NO_AUTOHINT                  0x8000U
  41. +/*#define FT_LOAD_COMPATIBLE_WIDTHS            0x10000U*/
  42.  
  43.    /* */
  44.  
  45. diff -Naur freetype-2.4.2-orig//include/freetype/internal/ftobjs.h freetype-2.4.2/include/freetype/internal/ftobjs.h
  46. --- freetype-2.4.2-orig//include/freetype/internal/ftobjs.h 2010-07-18 23:07:31.000000000 +0700
  47. +++ freetype-2.4.2/include/freetype/internal/ftobjs.h   2010-08-07 22:52:47.000000000 +0700
  48. @@ -81,6 +81,13 @@
  49.  #define FT_PIX_ROUND( x )     FT_PIX_FLOOR( (x) + 32 )
  50.  #define FT_PIX_CEIL( x )      FT_PIX_FLOOR( (x) + 63 )
  51.  
  52. +#define FT_PIX_FLOOR_sph( x )     ( (x) & ~3 )
  53. +#define FT_PIX_ROUND_sph( x )     FT_PIX_FLOOR_sph( (x) + 2 )
  54. +#define FT_PIX_CEIL_sph( x )      FT_PIX_FLOOR_sph( (x) + 3 )
  55. +
  56. +#define FT_PIX_FLOOR_sphn( x, n )     ( (x) & ~(64 / n - 1) )
  57. +#define FT_PIX_ROUND_sphn( x, n )     FT_PIX_FLOOR_sph( (x) + 32 / n)
  58. +#define FT_PIX_CEIL_sphn( x, n )      FT_PIX_FLOOR_sph( (x) + 64 / n - 1)
  59.  
  60.    /*
  61.     *  Return the highest power of 2 that is <= value; this correspond to
  62. diff -Naur freetype-2.4.2-orig//modules.cfg freetype-2.4.2/modules.cfg
  63. --- freetype-2.4.2-orig//modules.cfg    2009-03-14 20:45:26.000000000 +0700
  64. +++ freetype-2.4.2/modules.cfg  2010-08-07 22:52:47.000000000 +0700
  65. @@ -110,7 +110,7 @@
  66.  AUX_MODULES += cache
  67.  
  68.  # TrueType GX/AAT table validation.  Needs ftgxval.c below.
  69. -# AUX_MODULES += gxvalid
  70. +AUX_MODULES += gxvalid
  71.  
  72.  # Support for streams compressed with gzip (files with suffix .gz).
  73.  #
  74. @@ -124,7 +124,7 @@
  75.  
  76.  # OpenType table validation.  Needs ftotval.c below.
  77.  #
  78. -# AUX_MODULES += otvalid
  79. +AUX_MODULES += otvalid
  80.  
  81.  # Auxiliary PostScript driver component to share common code.
  82.  #
  83. diff -Naur freetype-2.4.2-orig//src/psaux/psobjs.c freetype-2.4.2/src/psaux/psobjs.c
  84. --- freetype-2.4.2-orig//src/psaux/psobjs.c 2010-06-20 21:24:14.000000000 +0700
  85. +++ freetype-2.4.2/src/psaux/psobjs.c   2010-08-07 22:52:47.000000000 +0700
  86. @@ -183,6 +183,11 @@
  87.        return PSaux_Err_Invalid_Argument;
  88.      }
  89.  
  90. +    if ( length < 0 ) {
  91. +      FT_ERROR(( "ps_table_add: invalid length\n" ));
  92. +      return PSaux_Err_Invalid_Argument;
  93. +    }
  94. +
  95.      /* grow the base block if needed */
  96.      if ( table->cursor + length > table->capacity )
  97.      {
  98. diff -Naur freetype-2.4.2-orig//src/truetype/ttgload.c freetype-2.4.2/src/truetype/ttgload.c
  99. --- freetype-2.4.2-orig//src/truetype/ttgload.c 2010-06-29 15:27:12.000000000 +0700
  100. +++ freetype-2.4.2/src/truetype/ttgload.c   2010-08-07 22:52:47.000000000 +0700
  101. @@ -1659,7 +1659,6 @@
  102.      {
  103.        FT_Pos  advance = loader->linear;
  104.  
  105. -
  106.        /* the flag FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH was introduced to */
  107.        /* correctly support DynaLab fonts, which have an incorrect       */
  108.        /* `advance_Width_Max' field!  It is used, to my knowledge,       */
  109. @@ -1669,6 +1668,8 @@
  110.             ( loader->load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) == 0 )
  111.          advance = face->horizontal.advance_Width_Max;
  112.  
  113. +
  114. +
  115.        /* we need to return the advance in font units in linearHoriAdvance, */
  116.        /* it will be scaled later by the base layer.                        */
  117.        glyph->linearHoriAdvance = advance;
  118. @@ -1683,13 +1684,20 @@
  119.           IS_HINTED( loader->load_flags ) )
  120.      {
  121.        FT_Byte*  widthp;
  122. +      FT_Bool   subpixel;
  123. +      FT_Bool   compatible_widths;
  124. +
  125. +      subpixel =
  126. +        FT_BOOL( FT_LOAD_TARGET_MODE( loader->load_flags ) != FT_RENDER_MODE_MONO );
  127.  
  128. +      compatible_widths = FALSE;
  129. +        /*FT_BOOL( FT_LOAD_TARGET_MODE( loader->load_flags ) != FT_LOAD_COMPATIBLE_WIDTHS )*/
  130.  
  131.        widthp = tt_face_get_device_metrics( face,
  132.                                             size->root.metrics.x_ppem,
  133.                                             glyph_index );
  134.  
  135. -      if ( widthp )
  136. +      if ( (!subpixel && widthp) || compatible_widths )
  137.          glyph->metrics.horiAdvance = *widthp << 6;
  138.      }
  139.  
  140. @@ -1883,7 +1891,8 @@
  141.      {
  142.        TT_ExecContext  exec;
  143.        FT_Bool         grayscale;
  144. -
  145. +      FT_Bool         subpixel;
  146. +      FT_Bool         compatible_widths;
  147.  
  148.        if ( !size->cvt_ready )
  149.        {
  150. @@ -1901,10 +1910,31 @@
  151.        grayscale =
  152.          FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_RENDER_MODE_MONO );
  153.  
  154. +      subpixel =
  155. +        FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_RENDER_MODE_MONO );
  156. +
  157. +      compatible_widths = FALSE;
  158. +        /*FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_LOAD_COMPATIBLE_WIDTHS)*/;
  159. +
  160.        TT_Load_Context( exec, face, size );
  161.  
  162.        /* a change from mono to grayscale rendering (and vice versa) */
  163.        /* requires a re-execution of the CVT program                 */
  164. +      if ( compatible_widths != exec->compatible_widths )
  165. +      {
  166. +        FT_UInt  i;
  167. +
  168. +
  169. +        exec->compatible_widths = compatible_widths;
  170. +
  171. +        for ( i = 0; i < size->cvt_size; i++ )
  172. +          size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
  173. +        tt_size_run_prep( size );
  174. +      }
  175. +
  176. +
  177. +      /* a change from mono to grayscale rendering (and vice versa) */
  178. +      /* requires a re-execution of the CVT program                 */
  179.        if ( grayscale != exec->grayscale )
  180.        {
  181.          FT_UInt  i;
  182. @@ -1914,6 +1944,18 @@
  183.  
  184.          for ( i = 0; i < size->cvt_size; i++ )
  185.            size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
  186. +        tt_size_run_prep( size );
  187. +      }
  188. +
  189. +      if ( subpixel != exec->subpixel )
  190. +      {
  191. +        FT_UInt  i;
  192. +
  193. +
  194. +        exec->subpixel = subpixel;
  195. +
  196. +        for ( i = 0; i < size->cvt_size; i++ )
  197. +          size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
  198.          tt_size_run_prep( size );
  199.        }
  200.  
  201. diff -Naur freetype-2.4.2-orig//src/truetype/ttinterp.c freetype-2.4.2/src/truetype/ttinterp.c
  202. --- freetype-2.4.2-orig//src/truetype/ttinterp.c    2010-08-06 05:36:55.000000000 +0700
  203. +++ freetype-2.4.2/src/truetype/ttinterp.c  2010-08-07 22:59:40.000000000 +0700
  204. @@ -168,6 +168,9 @@
  205.  #define CUR_Func_round( d, c ) \
  206.            CUR.func_round( EXEC_ARG_ d, c )
  207.  
  208. +#define CUR_Func_round_sphn( d, c ) \
  209. +          CUR.func_round_sphn( EXEC_ARG_ d, c )
  210. +
  211.  #define CUR_Func_read_cvt( index ) \
  212.            CUR.func_read_cvt( EXEC_ARG_ index )
  213.  
  214. @@ -1837,7 +1840,7 @@
  215.  #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  216.      FT_ASSERT( !CUR.face->unpatented_hinting );
  217.  #endif
  218. -
  219. +if (CUR.skip_x == 0){
  220.      v = CUR.GS.freeVector.x;
  221.  
  222.      if ( v != 0 )
  223. @@ -1848,7 +1851,8 @@
  224.  
  225.        zone->tags[point] |= FT_CURVE_TAG_TOUCH_X;
  226.      }
  227. -
  228. +}
  229. +if (CUR.skip_y == 0){
  230.      v = CUR.GS.freeVector.y;
  231.  
  232.      if ( v != 0 )
  233. @@ -1860,6 +1864,7 @@
  234.        zone->tags[point] |= FT_CURVE_TAG_TOUCH_Y;
  235.      }
  236.    }
  237. +  }
  238.  
  239.  
  240.    /*************************************************************************/
  241. @@ -1890,14 +1895,15 @@
  242.  #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  243.      FT_ASSERT( !CUR.face->unpatented_hinting );
  244.  #endif
  245. -
  246. +if (CUR.skip_x == 0){
  247.      v = CUR.GS.freeVector.x;
  248.  
  249.      if ( v != 0 )
  250.        zone->org[point].x += TT_MULDIV( distance,
  251.                                         v * 0x10000L,
  252.                                         CUR.F_dot_P );
  253. -
  254. +}
  255. +if (CUR.skip_y==0){
  256.      v = CUR.GS.freeVector.y;
  257.  
  258.      if ( v != 0 )
  259. @@ -1905,7 +1911,7 @@
  260.                                         v * 0x10000L,
  261.                                         CUR.F_dot_P );
  262.    }
  263. -
  264. +  }
  265.  
  266.    /*************************************************************************/
  267.    /*                                                                       */
  268. @@ -1923,9 +1929,10 @@
  269.                            FT_F26Dot6    distance )
  270.    {
  271.      FT_UNUSED_EXEC;
  272. -
  273. +if (CUR.skip_x == 0){
  274.      zone->cur[point].x += distance;
  275.      zone->tags[point]  |= FT_CURVE_TAG_TOUCH_X;
  276. +}
  277.    }
  278.  
  279.  
  280. @@ -1935,11 +1942,11 @@
  281.                            FT_F26Dot6    distance )
  282.    {
  283.      FT_UNUSED_EXEC;
  284. -
  285. +if (CUR.skip_y ==0){
  286.      zone->cur[point].y += distance;
  287.      zone->tags[point]  |= FT_CURVE_TAG_TOUCH_Y;
  288.    }
  289. -
  290. +  }
  291.  
  292.    /*************************************************************************/
  293.    /*                                                                       */
  294. @@ -1957,8 +1964,9 @@
  295.                                 FT_F26Dot6    distance )
  296.    {
  297.      FT_UNUSED_EXEC;
  298. -
  299. +if (CUR.skip_x == 0){
  300.      zone->org[point].x += distance;
  301. +}
  302.    }
  303.  
  304.  
  305. @@ -1968,9 +1976,10 @@
  306.                                 FT_F26Dot6    distance )
  307.    {
  308.      FT_UNUSED_EXEC;
  309. -
  310. +if (CUR.skip_y == 0){
  311.      zone->org[point].y += distance;
  312.    }
  313. +  }
  314.  
  315.  
  316.    /*************************************************************************/
  317. @@ -2064,6 +2073,32 @@
  318.    }
  319.  
  320.  
  321. +    static FT_F26Dot6
  322. +  Round_To_Grid_sphn( EXEC_OP_ FT_F26Dot6  distance,
  323. +                          FT_F26Dot6  compensation )
  324. +  {
  325. +    FT_F26Dot6  val;
  326. +
  327. +    FT_UNUSED_EXEC;
  328. +
  329. +    if ( distance >= 0 )
  330. +    {
  331. +      val = distance + compensation + 32 / CUR.grid_factor;
  332. +      if ( distance && val > 0 )
  333. +        val &= ~(64 / CUR.grid_factor - 1);
  334. +      else
  335. +        val = 0;
  336. +    }
  337. +    else
  338. +    {
  339. +      val = -FT_PIX_ROUND_sphn( compensation - distance, CUR.grid_factor );
  340. +      if ( val > 0 )
  341. +        val = 0;
  342. +    }
  343. +    return  val;
  344. +  }
  345. +
  346. +
  347.    /*************************************************************************/
  348.    /*                                                                       */
  349.    /* <Function>                                                            */
  350. @@ -2106,6 +2141,32 @@
  351.    }
  352.  
  353.  
  354. +  static FT_F26Dot6
  355. +  Round_To_Half_Grid_sphn( EXEC_OP_ FT_F26Dot6  distance,
  356. +                               FT_F26Dot6  compensation )
  357. +  {
  358. +    FT_F26Dot6  val;
  359. +
  360. +    FT_UNUSED_EXEC;
  361. +
  362. +    if ( distance >= 0 )
  363. +    {
  364. +      val = FT_PIX_FLOOR_sphn( distance + compensation, CUR.grid_factor )
  365. +        + 32 / CUR.grid_factor;
  366. +      if ( distance && val < 0 )
  367. +        val = 0;
  368. +    }
  369. +    else
  370. +    {
  371. +      val = -( FT_PIX_FLOOR_sphn( compensation - distance, CUR.grid_factor )
  372. +        + 32 / CUR.grid_factor);
  373. +      if ( val > 0 )
  374. +        val = 0;
  375. +    }
  376. +
  377. +    return val;
  378. +  }
  379. +
  380.    /*************************************************************************/
  381.    /*                                                                       */
  382.    /* <Function>                                                            */
  383. @@ -2149,6 +2210,31 @@
  384.      return val;
  385.    }
  386.  
  387. +  static FT_F26Dot6
  388. +  Round_Down_To_Grid_sphn( EXEC_OP_ FT_F26Dot6  distance,
  389. +                               FT_F26Dot6  compensation )
  390. +  {
  391. +    FT_F26Dot6  val;
  392. +
  393. +    FT_UNUSED_EXEC;
  394. +
  395. +    if ( distance >= 0 )
  396. +    {
  397. +      val = distance + compensation;
  398. +      if ( distance && val > 0 )
  399. +        val &= ~(64 / CUR.grid_factor - 1);
  400. +      else
  401. +        val = 0;
  402. +    }
  403. +    else
  404. +    {
  405. +      val = -( ( compensation - distance ) & -(64 / CUR.grid_factor) );
  406. +      if ( val > 0 )
  407. +        val = 0;
  408. +    }
  409. +
  410. +    return val;
  411. +  }
  412.  
  413.    /*************************************************************************/
  414.    /*                                                                       */
  415. @@ -2194,6 +2280,33 @@
  416.    }
  417.  
  418.  
  419. +
  420. +  static FT_F26Dot6
  421. +  Round_Up_To_Grid_sphn( EXEC_OP_ FT_F26Dot6  distance,
  422. +                             FT_F26Dot6  compensation )
  423. +  {
  424. +    FT_F26Dot6  val;
  425. +
  426. +    FT_UNUSED_EXEC;
  427. +
  428. +    if ( distance >= 0 )
  429. +    {
  430. +      val = distance + compensation + (64 / CUR.grid_factor - 1);
  431. +      if ( distance && val > 0 )
  432. +        val &= ~(64 / CUR.grid_factor - 1);
  433. +      else
  434. +        val = 0;
  435. +    }
  436. +    else
  437. +    {
  438. +      val = - FT_PIX_CEIL_sphn( compensation - distance, CUR.grid_factor );
  439. +      if ( val > 0 )
  440. +        val = 0;
  441. +    }
  442. +
  443. +    return val;
  444. +  }
  445. +
  446.    /*************************************************************************/
  447.    /*                                                                       */
  448.    /* <Function>                                                            */
  449. @@ -2238,6 +2351,32 @@
  450.    }
  451.  
  452.  
  453. +
  454. +  static FT_F26Dot6
  455. +  Round_To_Double_Grid_sphn( EXEC_OP_ FT_F26Dot6  distance,
  456. +                                 FT_F26Dot6  compensation )
  457. +  {
  458. +    FT_F26Dot6 val;
  459. +
  460. +    FT_UNUSED_EXEC;
  461. +
  462. +    if ( distance >= 0 )
  463. +    {
  464. +      val = distance + compensation + 16 / CUR.grid_factor;
  465. +      if ( distance && val > 0 )
  466. +        val &= ~(32 / CUR.grid_factor - 1);
  467. +      else
  468. +        val = 0;
  469. +    }
  470. +    else
  471. +    {
  472. +      val = -FT_PAD_ROUND( compensation - distance, 32 / CUR.grid_factor );
  473. +      if ( val > 0 )
  474. +        val = 0;
  475. +    }
  476. +
  477. +    return val;
  478. +  }
  479.    /*************************************************************************/
  480.    /*                                                                       */
  481.    /* <Function>                                                            */
  482. @@ -2288,6 +2427,14 @@
  483.    }
  484.  
  485.  
  486. +
  487. +  static FT_F26Dot6
  488. +  Round_Super_sphn( EXEC_OP_ FT_F26Dot6  distance,
  489. +                        FT_F26Dot6  compensation  )
  490. +  {
  491. +    return distance;
  492. +  }
  493. +
  494.    /*************************************************************************/
  495.    /*                                                                       */
  496.    /* <Function>                                                            */
  497. @@ -2336,6 +2483,15 @@
  498.    }
  499.  
  500.  
  501. +
  502. +  static FT_F26Dot6
  503. +  Round_Super_45_sphn( EXEC_OP_ FT_F26Dot6  distance,
  504. +                        FT_F26Dot6  compensation  )
  505. +  {
  506. +
  507. +    return distance;
  508. +  }
  509. +
  510.    /*************************************************************************/
  511.    /*                                                                       */
  512.    /* <Function>                                                            */
  513. @@ -2358,30 +2514,37 @@
  514.  
  515.      case TT_Round_To_Grid:
  516.        CUR.func_round = (TT_Round_Func)Round_To_Grid;
  517. +      CUR.func_round_sphn = (TT_Round_Func)Round_To_Grid_sphn;
  518.        break;
  519.  
  520.      case TT_Round_Up_To_Grid:
  521.        CUR.func_round = (TT_Round_Func)Round_Up_To_Grid;
  522. +      CUR.func_round_sphn = (TT_Round_Func)Round_Up_To_Grid_sphn;
  523.        break;
  524.  
  525.      case TT_Round_Down_To_Grid:
  526.        CUR.func_round = (TT_Round_Func)Round_Down_To_Grid;
  527. +      CUR.func_round_sphn = (TT_Round_Func)Round_Down_To_Grid_sphn;
  528.        break;
  529.  
  530.      case TT_Round_To_Half_Grid:
  531.        CUR.func_round = (TT_Round_Func)Round_To_Half_Grid;
  532. +      CUR.func_round_sphn = (TT_Round_Func)Round_To_Half_Grid_sphn;
  533.        break;
  534.  
  535.      case TT_Round_To_Double_Grid:
  536.        CUR.func_round = (TT_Round_Func)Round_To_Double_Grid;
  537. +      CUR.func_round_sphn = (TT_Round_Func)Round_To_Double_Grid_sphn;
  538.        break;
  539.  
  540.      case TT_Round_Super:
  541.        CUR.func_round = (TT_Round_Func)Round_Super;
  542. +      CUR.func_round_sphn = (TT_Round_Func)Round_Super_sphn;
  543.        break;
  544.  
  545.      case TT_Round_Super_45:
  546.        CUR.func_round = (TT_Round_Func)Round_Super_45;
  547. +      CUR.func_round_sphn = (TT_Round_Func)Round_Super_45_sphn;
  548.        break;
  549.      }
  550.    }
  551. @@ -3032,44 +3195,52 @@
  552.  
  553.  #define DO_RTHG                                         \
  554.      CUR.GS.round_state = TT_Round_To_Half_Grid;         \
  555. -    CUR.func_round = (TT_Round_Func)Round_To_Half_Grid;
  556. +    CUR.func_round = (TT_Round_Func)Round_To_Half_Grid; \
  557. +    CUR.func_round_sphn = (TT_Round_Func)Round_To_Half_Grid_sphn;
  558.  
  559.  
  560.  #define DO_RTG                                     \
  561.      CUR.GS.round_state = TT_Round_To_Grid;         \
  562. -    CUR.func_round = (TT_Round_Func)Round_To_Grid;
  563. +    CUR.func_round = (TT_Round_Func)Round_To_Grid; \
  564. +    CUR.func_round_sphn = (TT_Round_Func)Round_To_Grid_sphn;
  565.  
  566.  
  567.  #define DO_RTDG                                           \
  568.      CUR.GS.round_state = TT_Round_To_Double_Grid;         \
  569. -    CUR.func_round = (TT_Round_Func)Round_To_Double_Grid;
  570. +    CUR.func_round = (TT_Round_Func)Round_To_Double_Grid; \
  571. +    CUR.func_round_sphn = (TT_Round_Func)Round_To_Double_Grid_sphn;
  572.  
  573.  
  574.  #define DO_RUTG                                       \
  575.      CUR.GS.round_state = TT_Round_Up_To_Grid;         \
  576. -    CUR.func_round = (TT_Round_Func)Round_Up_To_Grid;
  577. +    CUR.func_round = (TT_Round_Func)Round_Up_To_Grid; \
  578. +    CUR.func_round_sphn = (TT_Round_Func)Round_Up_To_Grid_sphn;
  579.  
  580.  
  581.  #define DO_RDTG                                         \
  582.      CUR.GS.round_state = TT_Round_Down_To_Grid;         \
  583. -    CUR.func_round = (TT_Round_Func)Round_Down_To_Grid;
  584. +    CUR.func_round = (TT_Round_Func)Round_Down_To_Grid; \
  585. +    CUR.func_round_sphn = (TT_Round_Func)Round_Down_To_Grid_sphn;
  586.  
  587.  
  588.  #define DO_ROFF                                 \
  589.      CUR.GS.round_state = TT_Round_Off;          \
  590. -    CUR.func_round = (TT_Round_Func)Round_None;
  591. +    CUR.func_round = (TT_Round_Func)Round_None; \
  592. +    CUR.func_round_sphn = (TT_Round_Func)Round_None;
  593.  
  594.  
  595.  #define DO_SROUND                                \
  596.      SET_SuperRound( 0x4000, args[0] );           \
  597.      CUR.GS.round_state = TT_Round_Super;         \
  598. -    CUR.func_round = (TT_Round_Func)Round_Super;
  599. +    CUR.func_round = (TT_Round_Func)Round_Super; \
  600. +    CUR.func_round_sphn = (TT_Round_Func)Round_Super_sphn;
  601.  
  602.  
  603.  #define DO_S45ROUND                                 \
  604.      SET_SuperRound( 0x2D41, args[0] );              \
  605.      CUR.GS.round_state = TT_Round_Super_45;         \
  606. -    CUR.func_round = (TT_Round_Func)Round_Super_45;
  607. +    CUR.func_round = (TT_Round_Func)Round_Super_45; \
  608. +    CUR.func_round_sphn = (TT_Round_Func)Round_Super_45_sphn;
  609.  
  610.  
  611.  #define DO_SLOOP                       \
  612. @@ -3297,7 +3468,9 @@
  613.           args[0] = 0;                   \
  614.       }                                  \
  615.       else                               \
  616. -       args[0] = CUR.storage[I];        \
  617. +        /* Subpixel Hinting- Typeman Dstroke and Istroke, Vacuform Rounds */ \
  618. +       if (CUR.subpixel && (I == 24 || I == 22 || I == 8)) args[0] = 0; \
  619. +       else args[0] = CUR.storage[I];  \
  620.     }
  621.  
  622.  
  623. @@ -5154,6 +5327,9 @@
  624.        }
  625.      }
  626.  
  627. +   /* Subpixel Hinting - Type 2 Vacuform Rounds - Arial Narrow */
  628. +   if (CUR.subpixel && FT_ABS(D) == 64) D += 1;
  629. +
  630.      args[0] = D;
  631.    }
  632.  
  633. @@ -5633,14 +5809,15 @@
  634.        return;
  635.      }
  636.  #endif
  637. -
  638. +if (CUR.skip_x == 0){
  639.      if ( CUR.GS.freeVector.x != 0 )
  640.      {
  641.        CUR.zp2.cur[point].x += dx;
  642.        if ( touch )
  643.          CUR.zp2.tags[point] |= FT_CURVE_TAG_TOUCH_X;
  644.      }
  645. -
  646. +}
  647. +if (CUR.skip_y == 0){
  648.      if ( CUR.GS.freeVector.y != 0 )
  649.      {
  650.        CUR.zp2.cur[point].y += dy;
  651. @@ -5648,7 +5825,7 @@
  652.          CUR.zp2.tags[point] |= FT_CURVE_TAG_TOUCH_Y;
  653.      }
  654.    }
  655. -
  656. +  }
  657.  
  658.    /*************************************************************************/
  659.    /*                                                                       */
  660. @@ -5863,7 +6040,18 @@
  661.          }
  662.        }
  663.        else
  664. -        MOVE_Zp2_Point( point, dx, dy, TRUE );
  665. +      {
  666. +        /* If freedom vector is Y, and point is touched, continue */
  667. +        if ( CUR.subpixel && CUR.GS.freeVector.y != 0 && CUR.iup_called == 0
  668. +          && ( ( CUR.pts.tags[point] & FT_CURVE_TAG_TOUCH_X ) != 0
  669. +            || ( CUR.pts.tags[point] & FT_CURVE_TAG_TOUCH_Y ) != 0 )
  670. +        ){
  671. +          MOVE_Zp2_Point( point, dx, dy, TRUE ); }
  672. +
  673. +        else if ( !CUR.subpixel || CUR.is_composite )
  674. +          MOVE_Zp2_Point( point, dx, dy, TRUE );
  675. +
  676. +      }
  677.  
  678.        CUR.GS.loop--;
  679.      }
  680. @@ -5908,6 +6096,15 @@
  681.      distance = CUR_Func_project( CUR.zp1.cur + point,
  682.                                   CUR.zp0.cur + CUR.GS.rp0 );
  683.  
  684. +    /* Subpixel Hinting - make MSIRP respect CVT cutin            */
  685. +    /* Fixes "k" issue with Arial                                 */
  686. +    /* Using 0 instead of CUR.GS.control_value_cutin/grid_factor  */
  687. +    /* fixes Helvetica Neue                                       */
  688. +    if (CUR.subpixel && CUR.GS.freeVector.x != 0
  689. +      && FT_ABS(distance - args[1]) >= 0 )
  690. +      distance = args[1];
  691. +
  692. +
  693.      CUR_Func_move( &CUR.zp1, point, args[1] - distance );
  694.  
  695.      CUR.GS.rp1 = CUR.GS.rp0;
  696. @@ -5946,7 +6143,10 @@
  697.      if ( ( CUR.opcode & 1 ) != 0 )
  698.      {
  699.        cur_dist = CUR_fast_project( &CUR.zp0.cur[point] );
  700. -      distance = CUR_Func_round( cur_dist,
  701. +      if (!CUR.subpixel || CUR.GS.freeVector.x == 0)
  702. +        distance = CUR_Func_round( cur_dist,
  703. +                                 CUR.tt_metrics.compensations[0] ) - cur_dist;
  704. +      else distance = CUR_Func_round_sphn( cur_dist,
  705.                                   CUR.tt_metrics.compensations[0] ) - cur_dist;
  706.      }
  707.      else
  708. @@ -6020,10 +6220,20 @@
  709.  
  710.      if ( ( CUR.opcode & 1 ) != 0 )   /* rounding and control cutin flag */
  711.      {
  712. -      if ( FT_ABS( distance - org_dist ) > CUR.GS.control_value_cutin )
  713. -        distance = org_dist;
  714.  
  715. -      distance = CUR_Func_round( distance, CUR.tt_metrics.compensations[0] );
  716. +      if ( !CUR.subpixel || CUR.GS.freeVector.x == 0 )
  717. +      {
  718. +        if ( FT_ABS( distance - org_dist ) > CUR.GS.control_value_cutin)
  719. +          distance = org_dist;
  720. +        distance = CUR_Func_round( distance, CUR.tt_metrics.compensations[0] );
  721. +      }
  722. +      else
  723. +      {
  724. +        if ( FT_ABS( distance - org_dist )
  725. +                > CUR.GS.control_value_cutin / CUR.grid_factor)
  726. +          distance = org_dist;
  727. +        distance = CUR_Func_round_sphn( distance, CUR.tt_metrics.compensations[0] );
  728. +      }
  729.      }
  730.  
  731.      CUR_Func_move( &CUR.zp0, point, distance - org_dist );
  732. @@ -6107,9 +6317,15 @@
  733.      /* round flag */
  734.  
  735.      if ( ( CUR.opcode & 4 ) != 0 )
  736. -      distance = CUR_Func_round(
  737. +    {
  738. +      if ( !CUR.subpixel || CUR.GS.freeVector.x == 0 )
  739. +        distance = CUR_Func_round(
  740. +                   org_dist,
  741. +                   CUR.tt_metrics.compensations[CUR.opcode & 3] );
  742. +      else distance = CUR_Func_round_sphn(
  743.                     org_dist,
  744.                     CUR.tt_metrics.compensations[CUR.opcode & 3] );
  745. +    }
  746.      else
  747.        distance = ROUND_None(
  748.                     org_dist,
  749. @@ -6117,17 +6333,36 @@
  750.  
  751.      /* minimum distance flag */
  752.  
  753. -    if ( ( CUR.opcode & 8 ) != 0 )
  754. -    {
  755. -      if ( org_dist >= 0 )
  756. +    /* Use 2/3 in x direction.  Better results than documented 1/2 */
  757. +    if (CUR.GS.freeVector.x != 0 && CUR.subpixel ){
  758. +      if ( ( CUR.opcode & 8 ) != 0 )
  759.        {
  760. -        if ( distance < CUR.GS.minimum_distance )
  761. -          distance = CUR.GS.minimum_distance;
  762. +        if ( org_dist >= 0 )
  763. +        {
  764. +          if ( distance < 2*CUR.GS.minimum_distance/3 )
  765. +            distance = 2*CUR.GS.minimum_distance/3;
  766. +        }
  767. +        else
  768. +        {
  769. +          if ( distance > -CUR.GS.minimum_distance/2 )
  770. +            distance = -CUR.GS.minimum_distance/2;
  771. +        }
  772.        }
  773. -      else
  774. +    }
  775. +    else
  776. +    {
  777. +      if ( ( CUR.opcode & 8 ) != 0 )
  778.        {
  779. -        if ( distance > -CUR.GS.minimum_distance )
  780. -          distance = -CUR.GS.minimum_distance;
  781. +        if ( org_dist >= 0 )
  782. +        {
  783. +          if ( distance < CUR.GS.minimum_distance )
  784. +            distance = CUR.GS.minimum_distance;
  785. +        }
  786. +        else
  787. +        {
  788. +          if ( distance > -CUR.GS.minimum_distance )
  789. +            distance = -CUR.GS.minimum_distance;
  790. +        }
  791.        }
  792.      }
  793.  
  794. @@ -6163,7 +6398,6 @@
  795.                  cur_dist,
  796.                  org_dist;
  797.  
  798. -
  799.      point    = (FT_UShort)args[0];
  800.      cvtEntry = (FT_ULong)( args[1] + 1 );
  801.  
  802. @@ -6224,41 +6458,84 @@
  803.  
  804.      /* control value cutin and round */
  805.  
  806. -    if ( ( CUR.opcode & 4 ) != 0 )
  807. +    if ( (!CUR.subpixel && ( CUR.opcode & 4 ) != 0) || CUR.subpixel )
  808.      {
  809.        /* XXX: UNDOCUMENTED!  Only perform cut-in test when both points */
  810.        /*      refer to the same zone.                                  */
  811.  
  812. -      if ( CUR.GS.gep0 == CUR.GS.gep1 )
  813. -        if ( FT_ABS( cvt_dist - org_dist ) >= CUR.GS.control_value_cutin )
  814. -          cvt_dist = org_dist;
  815. +      if ( (!CUR.subpixel && CUR.GS.gep0 == CUR.GS.gep1) || CUR.subpixel )
  816. +      {
  817. +        if ( (CUR.subpixel && CUR.GS.freeVector.x == 0) || !CUR.subpixel )
  818. +        {
  819. +          if ( FT_ABS(cvt_dist - org_dist)  >= CUR.GS.control_value_cutin  )
  820. +            cvt_dist = org_dist;
  821. +
  822. +          distance = CUR_Func_round(
  823. +            cvt_dist,
  824. +            CUR.tt_metrics.compensations[CUR.opcode & 3] );
  825. +        }
  826.  
  827. -      distance = CUR_Func_round(
  828. +        else if (CUR.subpixel)
  829. +        {
  830. +          if ( FT_ABS(cvt_dist - org_dist)
  831. +                >= CUR.GS.control_value_cutin / CUR.grid_factor )
  832. +                  cvt_dist = org_dist;
  833. +
  834. +          distance = CUR_Func_round_sphn(
  835.                     cvt_dist,
  836.                     CUR.tt_metrics.compensations[CUR.opcode & 3] );
  837. +        }
  838. +
  839. +      /* This fixes subpixel hinting italics (Verdana) but may be hacky */
  840. +        else
  841. +          distance = ROUND_None(
  842. +                   cvt_dist,
  843. +                   CUR.tt_metrics.compensations[CUR.opcode & 3] );
  844. +      }
  845.      }
  846. -    else
  847. +    else if (!CUR.subpixel){
  848.        distance = ROUND_None(
  849.                     cvt_dist,
  850.                     CUR.tt_metrics.compensations[CUR.opcode & 3] );
  851. +    }
  852.  
  853.      /* minimum distance test */
  854. -
  855. -    if ( ( CUR.opcode & 8 ) != 0 )
  856. +   if (CUR.GS.freeVector.x != 0 && CUR.subpixel)
  857.      {
  858. -      if ( org_dist >= 0 )
  859. +      if ( ( CUR.opcode & 8 ) != 0 )
  860.        {
  861. -        if ( distance < CUR.GS.minimum_distance )
  862. -          distance = CUR.GS.minimum_distance;
  863. +        if ( org_dist >= 0 )
  864. +        {
  865. +          if ( distance < 2 * CUR.GS.minimum_distance / 3 )
  866. +            distance = 2 * CUR.GS.minimum_distance / 3;
  867. +        }
  868. +        else
  869. +        {
  870. +          if ( distance > -2 * CUR.GS.minimum_distance / 3 )
  871. +            distance = -2 * CUR.GS.minimum_distance / 3;
  872. +        }
  873. +
  874.        }
  875. -      else
  876. +    }
  877. +    else
  878. +    {
  879. +      if ( ( CUR.opcode & 8 ) != 0 )
  880.        {
  881. -        if ( distance > -CUR.GS.minimum_distance )
  882. -          distance = -CUR.GS.minimum_distance;
  883. +        if ( org_dist >= 0 )
  884. +        {
  885. +          if ( distance < CUR.GS.minimum_distance )
  886. +            distance = CUR.GS.minimum_distance;
  887. +        }
  888. +        else
  889. +        {
  890. +          if ( distance > -CUR.GS.minimum_distance )
  891. +            distance = -CUR.GS.minimum_distance;
  892. +        }
  893.        }
  894. +
  895.      }
  896.  
  897. -    CUR_Func_move( &CUR.zp1, point, distance - cur_dist );
  898. +      CUR_Func_move( &CUR.zp1, point, distance - cur_dist );
  899.  
  900.      CUR.GS.rp1 = CUR.GS.rp0;
  901.  
  902. @@ -6727,6 +7004,7 @@
  903.  
  904.      FT_UNUSED_ARG;
  905.  
  906. +    CUR.iup_called = 1;
  907.  
  908.      /* ignore empty outlines */
  909.      if ( CUR.pts.n_contours == 0 )
  910. @@ -6821,7 +7099,7 @@
  911.      FT_UShort  A;
  912.      FT_ULong   C;
  913.      FT_Long    B;
  914. -
  915. +    FT_Byte    orig_round_state;
  916.  
  917.  #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  918.      /* Delta hinting is covered by US Patent 5159668. */
  919. @@ -6891,7 +7169,28 @@
  920.              B++;
  921.            B = B * 64 / ( 1L << CUR.GS.delta_shift );
  922.  
  923. -          CUR_Func_move( &CUR.zp0, A, B );
  924. +          /* This dirty hack fixes subpixel y-artifacts in trebuchet,  */
  925. +          /* verdana bold, ms sans serif, due to bi-level deltas in y  */
  926. +          /* direction, but breaks some glyphs (trebuchet e, times e,  */
  927. +          /* arial bold S.  Needs work.  */
  928. +
  929. +          if (0 && CUR.GS.freeVector.y != 0 && CUR.subpixel  )
  930. +          {
  931. +            orig_round_state= CUR.GS.round_state;
  932. +            COMPUTE_Round( TT_Round_Down_To_Grid );
  933. +            B = CUR_Func_round( B, CUR.tt_metrics.compensations[0] );
  934. +            COMPUTE_Round( orig_round_state );
  935. +          }
  936. +
  937. +          /* Only allow deltas under certain conditions */
  938. +          if ( CUR.subpixel && CUR.GS.freeVector.y != 0 && CUR.iup_called == 0
  939. +            &&  (( CUR.pts.tags[A] & FT_CURVE_TAG_TOUCH_X ) != 0
  940. +              || ( CUR.pts.tags[A] & FT_CURVE_TAG_TOUCH_Y ) != 0 )
  941. +             ){
  942. +            CUR_Func_move(&CUR.zp0, A, B); }
  943. +          else if ( !CUR.subpixel || CUR.is_composite )
  944. +            CUR_Func_move(&CUR.zp0, A, B);
  945. +
  946.          }
  947.        }
  948.        else
  949. @@ -7016,9 +7315,9 @@
  950.  
  951.      K = 0;
  952.  
  953. -    /* We return MS rasterizer version 1.7 for the font scaler. */
  954. +    /* We return MS rasterizer version 1.8 for the font scaler. */
  955.      if ( ( args[0] & 1 ) != 0 )
  956. -      K = 35;
  957. +      K = 37;
  958.  
  959.      /* Has the glyph been rotated? */
  960.      if ( ( args[0] & 2 ) != 0 && CUR.tt_metrics.rotated )
  961. @@ -7032,6 +7331,27 @@
  962.      if ( ( args[0] & 32 ) != 0 && CUR.grayscale )
  963.        K |= 1 << 12;
  964.  
  965. +    /* Are we hinting for subpixel? */
  966. +    if ( ( args[0] & 64 ) != 0 && CUR.subpixel )
  967. +      K |= 1 << 13;
  968. +
  969. +    /* Are we hinting for compatible_widths? */
  970. +    if ( ( args[0] & 128 ) != 0 && CUR.compatible_widths ){
  971. +      K |= 1 << 14;
  972. +      CUR.skip_x = 0;
  973. +    }
  974. +    else CUR.skip_x = 1;
  975. +    CUR.skip_y = 0;
  976. +
  977. +    /* Are we hinting for symmetrical_smoothing? */
  978. +    /*if ( ( args[0] & 256 ) != 0 && CUR.symmetrical_smoothing )*/
  979. +    /* Forcibly setting to 0 fixes PALATINO */
  980. +      K |= 0 << 15;
  981. +
  982. +    /* Are we hinting for bgr? */
  983. +    if ( ( args[0] & 512 ) != 0 && CUR.bgr )
  984. +      K |= 1 << 16;
  985. +
  986.      args[0] = K;
  987.    }
  988.  
  989. @@ -7405,6 +7725,13 @@
  990.  #ifdef TT_CONFIG_OPTION_STATIC_RASTER
  991.      cur = *exc;
  992.  #endif
  993. +    if (CUR.subpixel)
  994. +      /* 1/32 of a pixel in y direction */
  995. +      CUR.grid_factor = 32;
  996. +    else
  997. +      CUR.grid_factor = 1;
  998. +
  999. +    CUR.iup_called = 0;
  1000.  
  1001.      /* set CVT functions */
  1002.      CUR.tt_metrics.ratio = 0;
  1003. diff -Naur freetype-2.4.2-orig//src/truetype/ttinterp.h freetype-2.4.2/src/truetype/ttinterp.h
  1004. --- freetype-2.4.2-orig//src/truetype/ttinterp.h    2010-08-06 04:56:05.000000000 +0700
  1005. +++ freetype-2.4.2/src/truetype/ttinterp.h  2010-08-07 22:52:47.000000000 +0700
  1006. @@ -203,6 +203,7 @@
  1007.      FT_Long            F_dot_P;    /* dot product of freedom and projection */
  1008.                                     /* vectors                               */
  1009.      TT_Round_Func      func_round; /* current rounding function             */
  1010. +    TT_Round_Func      func_round_sphn; /* subpixel rounding function       */
  1011.  
  1012.      TT_Project_Func    func_project,   /* current projection function */
  1013.                         func_dualproj,  /* current dual proj. function */
  1014. @@ -215,7 +216,16 @@
  1015.      TT_Set_CVT_Func    func_write_cvt; /* write a cvt entry (in pixels) */
  1016.      TT_Set_CVT_Func    func_move_cvt;  /* incr a cvt entry (in pixels)  */
  1017.  
  1018. -    FT_Bool            grayscale;      /* are we hinting for grayscale? */
  1019. +    FT_Bool            grayscale;         /* are we hinting for grayscale?  */
  1020. +    FT_Bool            subpixel;          /* are we hinting for subpixel?   */
  1021. +    FT_Bool            compatible_widths; /* are we using compatible widths?*/
  1022. +    FT_Bool            symmetrical_smoothing; /* symmetrical_smoothing ?    */
  1023. +    FT_Bool            bgr;               /* are we using bgr, not rgb?     */
  1024. +
  1025. +    FT_Bool            grid_factor;    /* freedom vector resol (1 < 32) */
  1026. +    FT_Bool            iup_called;     /* IUP[] been called for this glyph? */
  1027. +    FT_Bool            skip_x;         /* Skip all x moves? */
  1028. +    FT_Bool            skip_y;         /* Skip all y moves? */
  1029.  
  1030.    } TT_ExecContextRec;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement