From e6c7e4b42bc39a7cfa438b2fa628aa3198374124 Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Tue, 1 Sep 2020 21:49:52 -0400 Subject: [PATCH] [truetype] Refactor compensation color. * src/truetype/ttinterp.h (TT_Round_Func): Change the last argument. * src/truetype/ttinterp.c (Ins_ROUND, Ins_NROUND, Ins_MDAP, Ins_MIAP, Ins_MDRP, Ins_MIRP): Move compensation retrieval from here... (Round_*): ... to here. * src/truetype/ttobjs.c (tt_size_init_bytecode): Reserve zero compensation at color index 3. --- ChangeLog | 13 +++- src/truetype/ttinterp.c | 127 ++++++++++++++-------------------------- src/truetype/ttinterp.h | 2 +- src/truetype/ttobjs.c | 8 +-- 4 files changed, 62 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index 290f79c84..26aa3bcb3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,15 @@ -2020-08-25 Alexei Podtelezhnikov +2020-09-01 Alexei Podtelezhnikov + + [truetype] Refactor compensation color. + + * src/truetype/ttinterp.h (TT_Round_Func): Change the last argument. + * src/truetype/ttinterp.c (Ins_ROUND, Ins_NROUND, Ins_MDAP, Ins_MIAP, + Ins_MDRP, Ins_MIRP): Move compensation retrieval from here... + (Round_*): ... to here. + * src/truetype/ttobjs.c (tt_size_init_bytecode): Reserve zero + compensation at color index 3. + +2020-08-28 Alexei Podtelezhnikov [smooth] Don't set target in direct mode. diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c index 2c6fc0588..28c8d6d68 100644 --- a/src/truetype/ttinterp.c +++ b/src/truetype/ttinterp.c @@ -1955,8 +1955,8 @@ * distance :: * The distance (not) to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * The compensated distance. @@ -1964,12 +1964,11 @@ static FT_F26Dot6 Round_None( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; - FT_UNUSED( exc ); - if ( distance >= 0 ) { @@ -1999,8 +1998,8 @@ * distance :: * The distance to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * Rounded distance. @@ -2008,12 +2007,11 @@ static FT_F26Dot6 Round_To_Grid( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; - FT_UNUSED( exc ); - if ( distance >= 0 ) { @@ -2045,8 +2043,8 @@ * distance :: * The distance to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * Rounded distance. @@ -2054,12 +2052,11 @@ static FT_F26Dot6 Round_To_Half_Grid( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; - FT_UNUSED( exc ); - if ( distance >= 0 ) { @@ -2093,8 +2090,8 @@ * distance :: * The distance to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * Rounded distance. @@ -2102,12 +2099,11 @@ static FT_F26Dot6 Round_Down_To_Grid( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; - FT_UNUSED( exc ); - if ( distance >= 0 ) { @@ -2138,8 +2134,8 @@ * distance :: * The distance to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * Rounded distance. @@ -2147,12 +2143,11 @@ static FT_F26Dot6 Round_Up_To_Grid( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; - FT_UNUSED( exc ); - if ( distance >= 0 ) { @@ -2184,8 +2179,8 @@ * distance :: * The distance to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * Rounded distance. @@ -2193,12 +2188,11 @@ static FT_F26Dot6 Round_To_Double_Grid( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; - FT_UNUSED( exc ); - if ( distance >= 0 ) { @@ -2230,8 +2224,8 @@ * distance :: * The distance to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * Rounded distance. @@ -2245,8 +2239,9 @@ static FT_F26Dot6 Round_Super( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; @@ -2285,8 +2280,8 @@ * distance :: * The distance to round. * - * compensation :: - * The engine compensation. + * color :: + * The engine compensation color. * * @Return: * Rounded distance. @@ -2298,8 +2293,9 @@ static FT_F26Dot6 Round_Super_45( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ) + FT_Int color ) { + FT_F26Dot6 compensation = exc->tt_metrics.compensations[color]; FT_F26Dot6 val; @@ -2898,7 +2894,7 @@ Ins_ODD( TT_ExecContext exc, FT_Long* args ) { - args[0] = ( ( exc->func_round( exc, args[0], 0 ) & 127 ) == 64 ); + args[0] = ( ( exc->func_round( exc, args[0], 3 ) & 127 ) == 64 ); } @@ -2912,7 +2908,7 @@ Ins_EVEN( TT_ExecContext exc, FT_Long* args ) { - args[0] = ( ( exc->func_round( exc, args[0], 0 ) & 127 ) == 0 ); + args[0] = ( ( exc->func_round( exc, args[0], 3 ) & 127 ) == 0 ); } @@ -3242,10 +3238,7 @@ Ins_ROUND( TT_ExecContext exc, FT_Long* args ) { - args[0] = exc->func_round( - exc, - args[0], - exc->tt_metrics.compensations[exc->opcode - 0x68] ); + args[0] = exc->func_round( exc, args[0], exc->opcode & 3 ); } @@ -3259,10 +3252,7 @@ Ins_NROUND( TT_ExecContext exc, FT_Long* args ) { - args[0] = Round_None( - exc, - args[0], - exc->tt_metrics.compensations[exc->opcode - 0x6C] ); + args[0] = Round_None( exc, args[0], exc->opcode & 3 ); } @@ -5986,18 +5976,10 @@ if ( SUBPIXEL_HINTING_INFINALITY && exc->ignore_x_mode && exc->GS.freeVector.x != 0 ) - distance = SUB_LONG( - Round_None( exc, - cur_dist, - exc->tt_metrics.compensations[0] ), - cur_dist ); + distance = SUB_LONG( Round_None( exc, cur_dist, 3 ), cur_dist ); else #endif - distance = SUB_LONG( - exc->func_round( exc, - cur_dist, - exc->tt_metrics.compensations[0] ), - cur_dist ); + distance = SUB_LONG( exc->func_round( exc, cur_dist, 3 ), cur_dist ); } else distance = 0; @@ -6111,14 +6093,10 @@ if ( SUBPIXEL_HINTING_INFINALITY && exc->ignore_x_mode && exc->GS.freeVector.x != 0 ) - distance = Round_None( exc, - distance, - exc->tt_metrics.compensations[0] ); + distance = Round_None( exc, distance, 3 ); else #endif - distance = exc->func_round( exc, - distance, - exc->tt_metrics.compensations[0] ); + distance = exc->func_round( exc, distance, 3 ); } exc->func_move( exc, &exc->zp0, point, SUB_LONG( distance, org_dist ) ); @@ -6225,22 +6203,13 @@ if ( SUBPIXEL_HINTING_INFINALITY && exc->ignore_x_mode && exc->GS.freeVector.x != 0 ) - distance = Round_None( - exc, - org_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); + distance = Round_None( exc, org_dist, exc->opcode & 3 ); else #endif - distance = exc->func_round( - exc, - org_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); + distance = exc->func_round( exc, org_dist, exc->opcode & 3 ); } else - distance = Round_None( - exc, - org_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); + distance = Round_None( exc, org_dist, exc->opcode & 3 ); /* minimum distance flag */ @@ -6412,10 +6381,7 @@ cvt_dist = org_dist; } - distance = exc->func_round( - exc, - cvt_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); + distance = exc->func_round( exc, cvt_dist, exc->opcode & 3 ); } else { @@ -6435,10 +6401,7 @@ } #endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - distance = Round_None( - exc, - cvt_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); + distance = Round_None( exc, cvt_dist, exc->opcode & 3 ); } /* minimum distance test */ diff --git a/src/truetype/ttinterp.h b/src/truetype/ttinterp.h index 2b6c7497e..6a83705a6 100644 --- a/src/truetype/ttinterp.h +++ b/src/truetype/ttinterp.h @@ -51,7 +51,7 @@ FT_BEGIN_HEADER typedef FT_F26Dot6 (*TT_Round_Func)( TT_ExecContext exc, FT_F26Dot6 distance, - FT_F26Dot6 compensation ); + FT_Int color ); /* Point displacement along the freedom vector routine */ typedef void diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c index 04d23737c..06d456955 100644 --- a/src/truetype/ttobjs.c +++ b/src/truetype/ttobjs.c @@ -1115,10 +1115,10 @@ /* The Apple specification says that the compensation for */ /* `gray' is always zero. FreeType doesn't do any */ /* compensation at all. */ - tt_metrics->compensations[0] = 0; /* gray */ - tt_metrics->compensations[1] = 0; /* black */ - tt_metrics->compensations[2] = 0; /* white */ - tt_metrics->compensations[3] = 0; /* the same as gray */ + tt_metrics->compensations[0] = 0; /* gray */ + tt_metrics->compensations[1] = 0; /* black */ + tt_metrics->compensations[2] = 0; /* white */ + tt_metrics->compensations[3] = 0; /* zero */ } /* allocate function defs, instruction defs, cvt, and storage area */