diff options
author | Oleg Oshmyan <chortos@inbox.lv> | 2022-11-15 21:50:13 +0200 |
---|---|---|
committer | Oleg Oshmyan <chortos@inbox.lv> | 2023-08-06 00:54:14 +0300 |
commit | 1630dbeeef3b541e86af0c324a53a05a4f5a4b22 (patch) | |
tree | af01b343ec8c0613ca50f513a1d9ae684dcc6599 /libass/ass_fontselect.c | |
parent | 91422bdb9497e8484b3248f5ae7eb50d41e2555d (diff) | |
download | libass-1630dbeeef3b541e86af0c324a53a05a4f5a4b22.tar.bz2 libass-1630dbeeef3b541e86af0c324a53a05a4f5a4b22.tar.xz |
fontselect: eagerly compute is_postscript in get_font_info
This lets us get rid of the font format check in ass_coretext,
which is not available on Mac OS X 10.5 and prerelease 10.6.
This fixes https://github.com/libass/libass/issues/595,
which is about 10.6 prerelease build 10A190, the last Mac OS X
build available for PowerPC CPUs. A separate commit will expand
on this and make us compatible with 10.5 on all CPUs.
This partly reverts commit d0566318ee5035ca3a4d2d65d46a80a4e3d8244c,
where eager is_postscript was replaced by lazy check_postscript because
back then ass_directwrite eagerly loaded all of the system's fonts
and reading is_postscript from each font slowed it down significantly.
But eventually (in particular but not only because even without this
it was still slow for huge font collections) ass_directwrite learnt
to load fonts lazily, so there's a decent chance that this lazy
check_postscript (as well as the lazy get_font_index) isn't necessary
at all any more and can be removed in the future.
Diffstat (limited to 'libass/ass_fontselect.c')
-rw-r--r-- | libass/ass_fontselect.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c index 6d588ce..6b98cc2 100644 --- a/libass/ass_fontselect.c +++ b/libass/ass_fontselect.c @@ -78,6 +78,9 @@ struct font_info { // private data for callbacks void *priv; + + // unused if the provider has a check_postscript function + bool is_postscript; }; struct font_selector { @@ -114,13 +117,6 @@ struct font_data_ft { int idx; }; -static bool check_postscript_ft(void *data) -{ - FontDataFT *fd = (FontDataFT *)data; - PS_FontInfoRec postscript_info; - return !FT_Get_PS_Font_Info(fd->face, &postscript_info); -} - static bool check_glyph_ft(void *data, uint32_t codepoint) { FontDataFT *fd = (FontDataFT *)data; @@ -161,7 +157,6 @@ get_data_embedded(void *data, unsigned char *buf, size_t offset, size_t len) static ASS_FontProviderFuncs ft_funcs = { .get_data = get_data_embedded, - .check_postscript = check_postscript_ft, .check_glyph = check_glyph_ft, .destroy_font = destroy_font_ft, }; @@ -265,6 +260,7 @@ get_font_info(FT_Library lib, FT_Face face, const char *fallback_family_name, int slant, weight; char *fullnames[MAX_FULLNAME]; char *families[MAX_FULLNAME]; + PS_FontInfoRec postscript_info; // we're only interested in outlines if (!(face->face_flags & FT_FACE_FLAG_SCALABLE)) @@ -324,6 +320,7 @@ get_font_info(FT_Library lib, FT_Face face, const char *fallback_family_name, info->width = 100; // FIXME, should probably query the OS/2 table info->postscript_name = (char *)FT_Get_Postscript_Name(face); + info->is_postscript = !FT_Get_PS_Font_Info(face, &postscript_info); if (num_family) { info->families = calloc(sizeof(char *), num_family); @@ -488,6 +485,7 @@ ass_font_provider_add_font(ASS_FontProvider *provider, info->width = width; info->n_fullname = meta->n_fullname; info->n_family = meta->n_family; + info->is_postscript = meta->is_postscript; info->families = calloc(meta->n_family, sizeof(char *)); if (info->families == NULL) @@ -612,9 +610,12 @@ void ass_font_provider_free(ASS_FontProvider *provider) static bool check_postscript(ASS_FontInfo *fi) { ASS_FontProvider *provider = fi->provider; - assert(provider && provider->funcs.check_postscript); + assert(provider); - return provider->funcs.check_postscript(fi->priv); + if (provider->funcs.check_postscript) + return provider->funcs.check_postscript(fi->priv); + else + return fi->is_postscript; } /** |