Commit 125c3ca8f0a9646995375fd63b7b3ea48e957942

Alexei Podtelezhnikov 2014-09-02T22:38:59

[truetype] Shortcut ppem calculations for square pixels. * src/truetype/ttinterp.h (TT_ExecContextRec): New field `cur_ppem_func' with a function pointer. * src/truetype/ttinterp.c (TT_RunIns): Initialize `cur_ppem_func' depending on the pixel geometry to either... (Current_Ppem_Stretched): ... this for stretched pixels. (Current_Ppem): ... or this for square pixels. (DO_MPPEM, DO_MPS, Ins_DELTAP, Ins_DELTAC): Use `cur_ppem_func'.

diff --git a/ChangeLog b/ChangeLog
index 1824c0c..62ec7ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2014-09-02  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	[truetype] Shortcut ppem calculations for square pixels.
+
+	* src/truetype/ttinterp.h (TT_ExecContextRec): New field
+	`cur_ppem_func' with a function pointer.
+	* src/truetype/ttinterp.c (TT_RunIns): Initialize `cur_ppem_func'
+	depending on the pixel geometry to either...
+	(Current_Ppem_Stretched): ... this for stretched pixels.
+	(Current_Ppem): ... or this for square pixels.
+	(DO_MPPEM, DO_MPS, Ins_DELTAP, Ins_DELTAC): Use `cur_ppem_func'.
+
 2014-08-31  Behdad Esfahbod  <behdad@behdad.org>
 
 	Don't use `register' keyword.  Fixes compiler warnings.
@@ -8,7 +20,7 @@
 
 2014-08-24  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
-	[truetype] Optimize DELTAP and DELTAC. 
+	[truetype] Optimize DELTAP and DELTAC.
 
 	* src/truetype/ttinterp.c (Ins_DELTAP, Ins_DELTAC): Move ppem
 	calculations outside of the loop.
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
index 1f8debf..7d0248b 100644
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -172,6 +172,9 @@
 #define CUR_Func_round( d, c ) \
           CUR.func_round( EXEC_ARG_ d, c )
 
+#define CUR_Func_cur_ppem() \
+          CUR.func_cur_ppem( EXEC_ARG )
+
 #define CUR_Func_read_cvt( index ) \
           CUR.func_read_cvt( EXEC_ARG_ index )
 
@@ -184,12 +187,6 @@
 #define CURRENT_Ratio() \
           Current_Ratio( EXEC_ARG )
 
-#define CURRENT_Ppem() \
-          Current_Ppem( EXEC_ARG )
-
-#define CUR_Ppem() \
-          Cur_PPEM( EXEC_ARG )
-
 #define INS_SxVTL( a, b, c, d ) \
           Ins_SxVTL( EXEC_ARG_ a, b, c, d )
 
@@ -1706,9 +1703,16 @@
   }
 
 
-  static FT_Long
+  FT_CALLBACK_DEF( FT_Long )
   Current_Ppem( EXEC_OP )
   {
+    return CUR.tt_metrics.ppem;
+  }
+
+
+  FT_CALLBACK_DEF( FT_Long )
+  Current_Ppem_Stretched( EXEC_OP )
+  {
     return FT_MulFix( CUR.tt_metrics.ppem, CURRENT_Ratio() );
   }
 
@@ -3089,7 +3093,7 @@
 
 
 #define DO_MPPEM              \
-    args[0] = CURRENT_Ppem();
+    args[0] = CUR_Func_cur_ppem();
 
 
   /* Note: The pointSize should be irrelevant in a given font program; */
@@ -3102,7 +3106,7 @@
 #else
 
 #define DO_MPS                \
-    args[0] = CURRENT_Ppem();
+    args[0] = CUR_Func_cur_ppem();
 
 #endif /* 0 */
 
@@ -7523,7 +7527,7 @@
     }
 #endif
 
-    P = (FT_ULong)CURRENT_Ppem();
+    P = (FT_ULong)CUR_Func_cur_ppem();
     nump = (FT_ULong)args[0];   /* some points theoretically may occur more
                                    than once, thus UShort isn't enough */
 
@@ -7692,7 +7696,7 @@
     }
 #endif
 
-    P = (FT_ULong)CURRENT_Ppem();
+    P = (FT_ULong)CUR_Func_cur_ppem();
     nump = (FT_ULong)args[0];
 
     for ( k = 1; k <= nump; k++ )
@@ -8271,11 +8275,12 @@
     CUR.iup_called = FALSE;
 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
-    /* set CVT functions */
+    /* set PPEM and CVT functions */
     CUR.tt_metrics.ratio = 0;
     if ( CUR.metrics.x_ppem != CUR.metrics.y_ppem )
     {
       /* non-square pixels, use the stretched routines */
+      CUR.func_cur_ppem  = Current_Ppem_Stretched;
       CUR.func_read_cvt  = Read_CVT_Stretched;
       CUR.func_write_cvt = Write_CVT_Stretched;
       CUR.func_move_cvt  = Move_CVT_Stretched;
@@ -8283,6 +8288,7 @@
     else
     {
       /* square pixels, use normal routines */
+      CUR.func_cur_ppem  = Current_Ppem;
       CUR.func_read_cvt  = Read_CVT;
       CUR.func_write_cvt = Write_CVT;
       CUR.func_move_cvt  = Move_CVT;
diff --git a/src/truetype/ttinterp.h b/src/truetype/ttinterp.h
index 1d8825d..3cfc859 100644
--- a/src/truetype/ttinterp.h
+++ b/src/truetype/ttinterp.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    TrueType bytecode interpreter (specification).                       */
 /*                                                                         */
-/*  Copyright 1996-2007, 2010, 2012-2013 by                                */
+/*  Copyright 1996-2007, 2010, 2012-2014 by                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -81,6 +81,10 @@ FT_BEGIN_HEADER
   (*TT_Project_Func)( EXEC_OP_ FT_Pos   dx,
                                FT_Pos   dy );
 
+  /* getting current ppem.  Take care of non-square pixels if necessary */
+  typedef FT_Long
+  (*TT_Cur_Ppem_Func)( EXEC_OP );
+
   /* reading a cvt value.  Take care of non-square pixels if necessary */
   typedef FT_F26Dot6
   (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong  idx );
@@ -228,11 +232,6 @@ FT_BEGIN_HEADER
     FT_F26Dot6         phase;      /* `SuperRounding'     */
     FT_F26Dot6         threshold;
 
-#if 0
-    /* this seems to be unused */
-    FT_Int             cur_ppem;   /* ppem along the current proj vector */
-#endif
-
     FT_Bool            instruction_trap; /* If `True', the interpreter will */
                                          /* exit after each instruction     */
 
@@ -254,6 +253,8 @@ FT_BEGIN_HEADER
     TT_Move_Func       func_move;      /* current point move function */
     TT_Move_Func       func_move_orig; /* move original position function */
 
+    TT_Cur_Ppem_Func   func_cur_ppem;  /* get current proj. ppem value  */
+
     TT_Get_CVT_Func    func_read_cvt;  /* read a cvt entry              */
     TT_Set_CVT_Func    func_write_cvt; /* write a cvt entry (in pixels) */
     TT_Set_CVT_Func    func_move_cvt;  /* incr a cvt entry (in pixels)  */