Work on preloading font outlines

This commit is contained in:
Anurag Thakur 2023-08-14 19:51:22 +05:30
parent 71f5924d25
commit d23d82d84b
2 changed files with 46 additions and 5 deletions

View File

@ -2399,6 +2399,9 @@ FT_BEGIN_HEADER
* FT_OPEN_PARAMS :: * FT_OPEN_PARAMS ::
* Use the `num_params` and `params` fields. * Use the `num_params` and `params` fields.
* *
* FT_OPEN_PRELOAD ::
* Preprocess the font outline to save cpu time later.
*
* @note: * @note:
* The `FT_OPEN_MEMORY`, `FT_OPEN_STREAM`, and `FT_OPEN_PATHNAME` flags * The `FT_OPEN_MEMORY`, `FT_OPEN_STREAM`, and `FT_OPEN_PATHNAME` flags
* are mutually exclusive. * are mutually exclusive.
@ -2408,7 +2411,7 @@ FT_BEGIN_HEADER
#define FT_OPEN_PATHNAME 0x4 #define FT_OPEN_PATHNAME 0x4
#define FT_OPEN_DRIVER 0x8 #define FT_OPEN_DRIVER 0x8
#define FT_OPEN_PARAMS 0x10 #define FT_OPEN_PARAMS 0x10
#define FT_OPEN_PRELOAD 0x20
/* these constants are deprecated; use the corresponding `FT_OPEN_XXX` */ /* these constants are deprecated; use the corresponding `FT_OPEN_XXX` */
/* values instead */ /* values instead */
@ -2572,6 +2575,12 @@ FT_BEGIN_HEADER
FT_Long face_index, FT_Long face_index,
FT_Face *aface ); FT_Face *aface );
FT_EXPORT( FT_Error )
FT_New_Face2( FT_Library library,
const char* filepathname,
FT_Long face_index,
FT_Face *aface,
FT_UInt flags);
/************************************************************************** /**************************************************************************
* *

View File

@ -1610,7 +1610,6 @@
{ {
FT_Open_Args args; FT_Open_Args args;
/* test for valid `library' and `aface' delayed to `FT_Open_Face' */ /* test for valid `library' and `aface' delayed to `FT_Open_Face' */
if ( !pathname ) if ( !pathname )
return FT_THROW( Invalid_Argument ); return FT_THROW( Invalid_Argument );
@ -1622,6 +1621,29 @@
return ft_open_face_internal( library, &args, face_index, aface, 1 ); return ft_open_face_internal( library, &args, face_index, aface, 1 );
} }
FT_EXPORT_DEF( FT_Error )
FT_New_Face2( FT_Library library,
const char* pathname,
FT_Long face_index,
FT_Face *aface,
FT_UInt flags)
{
FT_Open_Args args;
/* test for valid `library' and `aface' delayed to `FT_Open_Face' */
if ( !pathname )
return FT_THROW( Invalid_Argument );
args.flags = FT_OPEN_PATHNAME;
args.flags |= flags;
args.pathname = (char*)pathname;
args.stream = NULL;
return ft_open_face_internal( library, &args, face_index, aface, 1 );
}
#endif #endif
@ -2540,6 +2562,10 @@
FT_UNUSED( test_mac_fonts ); FT_UNUSED( test_mac_fonts );
#endif #endif
if (args->flags & FT_OPEN_PRELOAD)
{
FT_TRACE0(("Requested Preload\n"));
}
/* only use lower 31 bits together with sign bit */ /* only use lower 31 bits together with sign bit */
if ( face_index > 0 ) if ( face_index > 0 )
@ -2636,7 +2662,6 @@
driver = FT_DRIVER( cur[0] ); driver = FT_DRIVER( cur[0] );
// TODO: Check the args for a "preload" flag and act accordingly
if ( args->flags & FT_OPEN_PARAMS ) if ( args->flags & FT_OPEN_PARAMS )
{ {
num_params = args->num_params; num_params = args->num_params;
@ -2727,7 +2752,12 @@
/* face->driver instead. */ /* face->driver instead. */
FT_List_Add( &face->driver->faces_list, node ); FT_List_Add( &face->driver->faces_list, node );
// TODO: The preload logic should be performed here if (args->flags & FT_OPEN_PRELOAD)
{
/* Preload the font here */
}
/* now allocate a glyph slot object for the face */ /* now allocate a glyph slot object for the face */
FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" )); FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" ));
@ -2749,6 +2779,8 @@
goto Fail; goto Fail;
face->size = size; face->size = size;
// FT_Outline_Decompose here
} }
} }