diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-12-13 08:14:43 +0100 |
---|---|---|
committer | Grigori Goronzy <greg@chown.ath.cx> | 2015-07-10 10:42:40 +0200 |
commit | f6e321acb11492ac87171825a630bc4e189c5cea (patch) | |
tree | 3bcc3739ef772df3c10562d3008591f08e6a5ecd | |
parent | bc743feb07cffe7a81e07411a484e499377deb50 (diff) | |
download | libass-f6e321acb11492ac87171825a630bc4e189c5cea.tar.bz2 libass-f6e321acb11492ac87171825a630bc4e189c5cea.tar.xz |
fontselect: expose a fontprovider listing API
This allows client code to query libass for the font providers it was compiled
with. It can be useful for clients so that they can show selection interfaces
to their users.
-rw-r--r-- | libass/ass.h | 8 | ||||
-rw-r--r-- | libass/ass_fontselect.c | 15 | ||||
-rw-r--r-- | libass/libass.sym | 1 | ||||
-rw-r--r-- | test/test.c | 22 |
4 files changed, 46 insertions, 0 deletions
diff --git a/libass/ass.h b/libass/ass.h index a3feb0b3..1fb2234a 100644 --- a/libass/ass.h +++ b/libass/ass.h @@ -401,6 +401,14 @@ void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing); void ass_set_line_position(ASS_Renderer *priv, double line_position); /** + * \brief Get the list of available font providers. + * \return list of available font providers (user owns the returned array) + */ +void ass_get_available_font_providers(ASS_Library *priv, + ASS_DefaultFontProvider **providers, + size_t *size); + +/** * \brief Set font lookup defaults. * \param default_font path to default font to use. Must be supplied if * fontconfig is disabled or unavailable. diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c index dacff11e..dc475b1d 100644 --- a/libass/ass_fontselect.c +++ b/libass/ass_fontselect.c @@ -848,6 +848,21 @@ ass_fontselect_init(ASS_Library *library, return priv; } +void ass_get_available_font_providers(ASS_Library *priv, + ASS_DefaultFontProvider **providers, + size_t *size) +{ + size_t offset = 2; + *size = offset; + for (int i = 0; font_constructors[i].constructor; i++) + (*size)++; + *providers = calloc(*size, sizeof(ASS_DefaultFontProvider)); + (*providers)[0] = ASS_FONTPROVIDER_NONE; + (*providers)[1] = ASS_FONTPROVIDER_AUTODETECT; + for (int i = offset; i < *size; i++) + (*providers)[i] = font_constructors[i-offset].id; +} + /** * \brief Free font selector and release associated data * \param the font selector diff --git a/libass/libass.sym b/libass/libass.sym index aafb7a8b..8a6826ad 100644 --- a/libass/libass.sym +++ b/libass/libass.sym @@ -14,6 +14,7 @@ ass_set_aspect_ratio ass_set_font_scale ass_set_hinting ass_set_line_spacing +ass_get_available_font_providers ass_set_fonts ass_render_frame ass_new_track diff --git a/test/test.c b/test/test.c index 8522840c..33aa94c9 100644 --- a/test/test.c +++ b/test/test.c @@ -166,6 +166,26 @@ static void blend(image_t * frame, ASS_Image *img) printf("%d images blended\n", cnt); } +char *font_provider_labels[] = { + [ASS_FONTPROVIDER_NONE] = "None", + [ASS_FONTPROVIDER_AUTODETECT] = "Autodetect", + [ASS_FONTPROVIDER_CORETEXT] = "CoreText", + [ASS_FONTPROVIDER_FONTCONFIG] = "Fontconfig", +}; + +static void print_font_providers(ASS_Library *ass_library) +{ + ASS_DefaultFontProvider *providers; + size_t providers_size = 0; + ass_get_available_font_providers(ass_library, &providers, &providers_size); + printf("test.c: Available font providers (%zu): ", providers_size); + for (int i = 0; i < providers_size; i++) { + const char *separator = i > 0 ? ", ": ""; + printf("%s'%s'", separator, font_provider_labels[providers[i]]); + } + printf(".\n"); +} + int main(int argc, char *argv[]) { const int frame_w = 1280; @@ -179,6 +199,8 @@ int main(int argc, char *argv[]) char *subfile = argv[2]; double tm = strtod(argv[3], 0); + print_font_providers(ass_library); + init(frame_w, frame_h); ASS_Track *track = ass_read_file(ass_library, subfile, NULL); if (!track) { |