summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2022-11-15 21:50:13 +0200
committerOleg Oshmyan <chortos@inbox.lv>2023-08-06 00:54:14 +0300
commit1630dbeeef3b541e86af0c324a53a05a4f5a4b22 (patch)
treeaf01b343ec8c0613ca50f513a1d9ae684dcc6599
parent91422bdb9497e8484b3248f5ae7eb50d41e2555d (diff)
downloadlibass-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.
-rw-r--r--libass/ass_coretext.c24
-rw-r--r--libass/ass_fontselect.c21
-rw-r--r--libass/ass_fontselect.h8
3 files changed, 18 insertions, 35 deletions
diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c
index 8002d8b..88a320c 100644
--- a/libass/ass_coretext.c
+++ b/libass/ass_coretext.c
@@ -61,29 +61,6 @@ static void destroy_font(void *priv)
CFRelease(fontd);
}
-static bool is_postscript_font_format(CFNumberRef cfformat)
-{
- bool ret = false;
- int format;
- if (CFNumberGetValue(cfformat, kCFNumberIntType, &format)) {
- ret = format == kCTFontFormatOpenTypePostScript ||
- format == kCTFontFormatPostScript;
- }
- return ret;
-}
-
-static bool check_postscript(void *priv)
-{
- CTFontDescriptorRef fontd = priv;
- CFNumberRef cfformat =
- CTFontDescriptorCopyAttribute(fontd, kCTFontFormatAttribute);
- if (!cfformat)
- return false;
- bool ret = is_postscript_font_format(cfformat);
- CFRelease(cfformat);
- return ret;
-}
-
static bool check_glyph(void *priv, uint32_t code)
{
if (code == 0)
@@ -295,7 +272,6 @@ static void get_substitutions(void *priv, const char *name,
}
static ASS_FontProviderFuncs coretext_callbacks = {
- .check_postscript = check_postscript,
.check_glyph = check_glyph,
.destroy_font = destroy_font,
.match_fonts = match_fonts,
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;
}
/**
diff --git a/libass/ass_fontselect.h b/libass/ass_fontselect.h
index 07fad7b..43366bb 100644
--- a/libass/ass_fontselect.h
+++ b/libass/ass_fontselect.h
@@ -158,7 +158,7 @@ typedef char *(*GetFallbackFunc)(void *priv,
typedef struct font_provider_funcs {
GetDataFunc get_data; /* optional/mandatory */
- CheckPostscriptFunc check_postscript; /* mandatory */
+ CheckPostscriptFunc check_postscript; /* optional */
CheckGlyphFunc check_glyph; /* mandatory */
DestroyFontFunc destroy_font; /* optional */
DestroyProviderFunc destroy_provider; /* optional */
@@ -211,6 +211,12 @@ struct ass_font_provider_meta_data {
// See FONT_WEIGHT_*
int width; // Font weight in percent, normally 100
// See FONT_WIDTH_*
+
+ /**
+ * Whether the font contains PostScript outlines.
+ * Unused if the font provider has a check_postscript function.
+ */
+ bool is_postscript;
};
struct ass_font_stream {