summaryrefslogtreecommitdiffstats
path: root/libass/ass_coretext.c
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2015-11-04 15:25:47 +0200
committerOleg Oshmyan <chortos@inbox.lv>2015-11-04 15:38:50 +0200
commitd0566318ee5035ca3a4d2d65d46a80a4e3d8244c (patch)
treeac342a9147ddc911698235c73a36e66c485b6ce4 /libass/ass_coretext.c
parentad5988af46f5ca698115140f9252882286539f72 (diff)
downloadlibass-d0566318ee5035ca3a4d2d65d46a80a4e3d8244c.tar.bz2
libass-d0566318ee5035ca3a4d2d65d46a80a4e3d8244c.tar.xz
fontselect: replace is_postscript flag with check_postscript function
DirectWrite does not provide fast access to the is_postscript flag, requiring each font to be loaded before its format can be determined. Eagerly doing this for every installed font can be quite slow, on the order of seconds. To improve performance, ask the font provider for this information only when it is actually needed, i.e. when one of the font's full names or its PostScript name matches a requested font name and we need to know whether to accept this match. The return value of check_postscript is not cached in this commit. This makes repeated calls slower than accessing is_postscript was. This should not be a problem, but if it is, the value can be cached (or precomputed) by font providers in their font private data. This commit also potentially increases the memory usage of some font providers by retaining data structures needed to implement check_postscript in their font private data. This should not be a problem either, but if it is, the value of check_postscript can be precomputed by all providers other than DirectWrite.
Diffstat (limited to 'libass/ass_coretext.c')
-rw-r--r--libass/ass_coretext.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c
index 2eacd92..1e74ad1 100644
--- a/libass/ass_coretext.c
+++ b/libass/ass_coretext.c
@@ -49,13 +49,29 @@ static char *cfstr2buf(CFStringRef string)
static void destroy_font(void *priv)
{
- CFCharacterSetRef set = priv;
- SAFE_CFRelease(set);
+ CTFontDescriptorRef fontd = priv;
+ SAFE_CFRelease(fontd);
+}
+
+static bool check_postscript(void *priv)
+{
+ CTFontDescriptorRef fontd = priv;
+ CFNumberRef cfformat =
+ CTFontDescriptorCopyAttribute(fontd, kCTFontFormatAttribute);
+ int format;
+
+ if (!CFNumberGetValue(cfformat, kCFNumberIntType, &format))
+ return false;
+
+ return format == kCTFontFormatOpenTypePostScript ||
+ format == kCTFontFormatPostScript;
}
static bool check_glyph(void *priv, uint32_t code)
{
- CFCharacterSetRef set = priv;
+ CTFontDescriptorRef fontd = priv;
+ CFCharacterSetRef set =
+ CTFontDescriptorCopyAttribute(fontd, kCTFontCharacterSetAttribute);
if (!set)
return true;
@@ -63,7 +79,9 @@ static bool check_glyph(void *priv, uint32_t code)
if (code == 0)
return true;
- return CFCharacterSetIsLongCharacterMember(set, code);
+ bool result = CFCharacterSetIsLongCharacterMember(set, code);
+ SAFE_CFRelease(set);
+ return result;
}
static char *get_font_file(CTFontDescriptorRef fontd)
@@ -88,19 +106,6 @@ static void get_name(CTFontDescriptorRef fontd, CFStringRef attr,
}
}
-static bool is_postscript(CTFontDescriptorRef fontd)
-{
- int format;
- CFNumberRef cfformat =
- CTFontDescriptorCopyAttribute(fontd, kCTFontFormatAttribute);
-
- if (!CFNumberGetValue(cfformat, kCFNumberIntType, &format))
- return false;
-
- return format == kCTFontFormatOpenTypePostScript ||
- format == kCTFontFormatPostScript;
-}
-
static void get_trait(CFDictionaryRef traits, CFStringRef attribute,
float *trait)
{
@@ -205,11 +210,8 @@ static void process_descriptors(ASS_FontProvider *provider, CFArrayRef fontsd)
get_name(fontd, kCTFontNameAttribute, identifiers, &zero);
meta.postscript_name = identifiers[0];
- meta.is_postscript = is_postscript(fontd);
-
- CFCharacterSetRef chset =
- CTFontDescriptorCopyAttribute(fontd, kCTFontCharacterSetAttribute);
- ass_font_provider_add_font(provider, &meta, path, index, (void*)chset);
+ CFRetain(fontd);
+ ass_font_provider_add_font(provider, &meta, path, index, (void*)fontd);
for (int j = 0; j < meta.n_family; j++)
free(meta.families[j]);
@@ -297,6 +299,7 @@ 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,