[base] Refactor obtaining advances.

* src/base/ftadvanc.c (ft_load_advances): New separate function to
handle slow advances.
(FT_Get_Advance, FT_Get_Advances): Updated.
This commit is contained in:
Alexei Podtelezhnikov
2025-10-26 13:28:32 -04:00
parent f238830d77
commit 0d410eb9aa

View File

@@ -52,6 +52,38 @@
return FT_Err_Ok;
}
/* loading (and hinting) to calculate the advances is slow */
/* unless TrueType hdmx table is provided as an accelerator */
static FT_Error
ft_load_advances( FT_Face face,
FT_UInt gindex,
FT_UInt count,
FT_Int32 flags,
FT_Fixed *padvances )
{
FT_UInt nn;
FT_Error error = FT_Err_Ok;
FT_Pos factor = flags & FT_LOAD_NO_SCALE ? 1 : 1024;
FT_Pos* advance = flags & FT_LOAD_VERTICAL_LAYOUT
? &face->glyph->advance.y
: &face->glyph->advance.x;
flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY;
for ( nn = 0; nn < count; nn++ )
{
error = FT_Load_Glyph( face, gindex + nn, flags );
if ( error )
break;
/* scale from 26.6 to 16.16, unless NO_SCALE was requested */
padvances[nn] = *advance * factor;
}
return error;
}
/* at the moment, we can perform fast advance retrieval only in */
/* the following cases: */
@@ -102,7 +134,10 @@
return error;
}
return FT_Get_Advances( face, gindex, 1, flags, padvance );
if ( flags & FT_ADVANCE_FLAG_FAST_ONLY )
return FT_THROW( Unimplemented_Feature );
return ft_load_advances( face, gindex, 1, flags, padvance );
}
@@ -115,12 +150,9 @@
FT_Int32 flags,
FT_Fixed *padvances )
{
FT_Error error = FT_Err_Ok;
FT_Face_GetAdvancesFunc func;
FT_UInt num, end, nn;
FT_Int factor;
FT_UInt num, end;
if ( !face )
@@ -140,6 +172,9 @@
func = face->driver->clazz->get_advances;
if ( func && LOAD_ADVANCE_FAST_CHECK( face, flags ) )
{
FT_Error error;
error = func( face, start, count, flags, padvances );
if ( !error )
return ft_face_scale_advances_( face, padvances, count, flags );
@@ -148,26 +183,10 @@
return error;
}
error = FT_Err_Ok;
if ( flags & FT_ADVANCE_FLAG_FAST_ONLY )
return FT_THROW( Unimplemented_Feature );
flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY;
factor = ( flags & FT_LOAD_NO_SCALE ) ? 1 : 1024;
for ( nn = 0; nn < count; nn++ )
{
error = FT_Load_Glyph( face, start + nn, flags );
if ( error )
break;
/* scale from 26.6 to 16.16, unless NO_SCALE was requested */
padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT )
? face->glyph->advance.y * factor
: face->glyph->advance.x * factor;
}
return error;
return ft_load_advances( face, start, count, flags, padvances );
}