[truetype] Modify bytecode initiation.

This reduces the number of function calls and data copying events.

* src/truetype/ttinterp.c (TT_Goto_CodeRange): Merge into...
(TT_Set_CodeRange): ... this function.
(TT_Load_Context): Do not set up any zones, copy GS, or prepare the
execution...
(TT_Run_Context): ... do this here instead..
* src/truetype/ttinterp.c (TT_Set_CodeRange): Update signature.
* src/truetype/ttobjs.c (tt_size_run_fpgm, tt_size_run_prep): Call
TT_Run_Context.
* src/truetype/ttgload.c (TT_Hint_Glyph, tt_loader_init): Updated.
This commit is contained in:
Alexei Podtelezhnikov
2025-06-07 22:09:28 -04:00
parent 70281e0f9d
commit 5631650b1e
4 changed files with 34 additions and 93 deletions

View File

@@ -2325,11 +2325,11 @@
exec->pedantic_hinting = pedantic;
/* check whether the cvt program has disabled hinting */
if ( exec->GS.instruct_control & 1 )
if ( size->GS.instruct_control & 1 )
load_flags |= FT_LOAD_NO_HINTING;
/* check whether GS modifications should be reverted */
if ( exec->GS.instruct_control & 2 )
if ( size->GS.instruct_control & 2 )
size->GS = tt_default_graphics_state;
#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL
@@ -2349,7 +2349,7 @@
if ( driver->interpreter_version == TT_INTERPRETER_VERSION_40 &&
subpixel_hinting_lean &&
!FT_IS_TRICKY( glyph->face ) )
exec->backward_compatibility = ( exec->GS.instruct_control & 4 ) ^ 4;
exec->backward_compatibility = ( size->GS.instruct_control & 4 ) ^ 4;
else
exec->backward_compatibility = 0;
#endif /* TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL */

View File

@@ -114,54 +114,6 @@
*/
/**************************************************************************
*
* @Function:
* TT_Goto_CodeRange
*
* @Description:
* Switches to a new code range (updates the code related elements in
* `exec', and `IP').
*
* @Input:
* range ::
* The new execution code range.
*
* IP ::
* The new IP in the new code range.
*
* @InOut:
* exec ::
* The target execution context.
*/
FT_LOCAL_DEF( void )
TT_Goto_CodeRange( TT_ExecContext exec,
FT_Int range,
FT_Long IP )
{
TT_CodeRange* coderange;
FT_ASSERT( range >= 1 && range <= 3 );
coderange = &exec->codeRangeTable[range - 1];
FT_ASSERT( coderange->base );
/* NOTE: Because the last instruction of a program may be a CALL */
/* which will return to the first byte *after* the code */
/* range, we test for IP <= Size instead of IP < Size. */
/* */
FT_ASSERT( IP <= coderange->size );
exec->code = coderange->base;
exec->codeSize = coderange->size;
exec->IP = IP;
exec->curRange = range;
exec->iniRange = range;
}
/**************************************************************************
*
* @Function:
@@ -187,13 +139,19 @@
FT_LOCAL_DEF( void )
TT_Set_CodeRange( TT_ExecContext exec,
FT_Int range,
void* base,
FT_Byte* base,
FT_Long length )
{
FT_ASSERT( range >= 1 && range <= 3 );
exec->codeRangeTable[range - 1].base = (FT_Byte*)base;
exec->codeRangeTable[range - 1].base = base;
exec->codeRangeTable[range - 1].size = length;
exec->code = base;
exec->codeSize = length;
exec->IP = 0;
exec->curRange = range;
exec->iniRange = range;
}
@@ -361,23 +319,6 @@
exec->tt_metrics = size->ttmetrics;
exec->metrics = *size->metrics;
/* set graphics state */
exec->GS = size->GS;
exec->twilight = size->twilight;
exec->pts.n_points = 0;
exec->pts.n_contours = 0;
exec->zp1 = exec->pts;
exec->zp2 = exec->pts;
exec->zp0 = exec->pts;
exec->callTop = 0;
exec->top = 0;
exec->instruction_trap = FALSE;
return FT_Err_Ok;
}
@@ -452,12 +393,12 @@
TT_Run_Context( TT_ExecContext exec,
TT_Size size )
{
TT_Goto_CodeRange( exec, tt_coderange_glyph, 0 );
exec->zp0 = exec->pts;
exec->zp1 = exec->pts;
exec->zp2 = exec->pts;
exec->twilight = size->twilight;
/* reset graphics state */
exec->GS = size->GS;
@@ -466,6 +407,8 @@
exec->top = 0;
exec->callTop = 0;
exec->instruction_trap = FALSE;
return exec->face->interpreter( exec );
}

View File

@@ -359,15 +359,10 @@ FT_BEGIN_HEADER
#ifdef TT_USE_BYTECODE_INTERPRETER
FT_LOCAL( void )
TT_Goto_CodeRange( TT_ExecContext exec,
FT_Int range,
FT_Long IP );
FT_LOCAL( void )
TT_Set_CodeRange( TT_ExecContext exec,
FT_Int range,
void* base,
FT_Byte* base,
FT_Long length );
FT_LOCAL( void )

View File

@@ -908,22 +908,23 @@
exec->pedantic_hinting = pedantic;
/* allow font program execution */
TT_Set_CodeRange( exec,
tt_coderange_font,
face->font_program,
(FT_Long)face->font_program_size );
/* disable CVT and glyph programs coderange */
TT_Clear_CodeRange( exec, tt_coderange_cvt );
TT_Clear_CodeRange( exec, tt_coderange_glyph );
if ( face->font_program_size > 0 )
{
TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
/* allow font program execution */
TT_Set_CodeRange( exec,
tt_coderange_font,
face->font_program,
(FT_Long)face->font_program_size );
exec->pts.n_points = 0;
exec->pts.n_contours = 0;
FT_TRACE4(( "Executing `fpgm' table.\n" ));
error = face->interpreter( exec );
error = TT_Run_Context( exec, size );
FT_TRACE4(( error ? " failed (error code 0x%x)\n" : "",
error ));
}
@@ -989,19 +990,21 @@
exec->pedantic_hinting = pedantic;
TT_Set_CodeRange( exec,
tt_coderange_cvt,
face->cvt_program,
(FT_Long)face->cvt_program_size );
TT_Clear_CodeRange( exec, tt_coderange_glyph );
if ( face->cvt_program_size > 0 )
{
TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
/* allow CV program execution */
TT_Set_CodeRange( exec,
tt_coderange_cvt,
face->cvt_program,
(FT_Long)face->cvt_program_size );
exec->pts.n_points = 0;
exec->pts.n_contours = 0;
FT_TRACE4(( "Executing `prep' table.\n" ));
error = face->interpreter( exec );
error = TT_Run_Context( exec, size );
FT_TRACE4(( error ? " failed (error code 0x%x)\n" : "",
error ));
}