changeset 26582:62ac4f8062ee

Remove libass dependency on global font_fontconfig variable. A new function (ass_set_fonts_nofc) is introduced instead of an extra argument to existing ass_set_fonts to keep binary compatibility with older versions of the library.
author eugeni
date Wed, 30 Apr 2008 14:16:22 +0000
parents f04ebe286154
children 6559b9364ca3
files libass/ass.h libass/ass_fontconfig.c libass/ass_fontconfig.h libass/ass_mp.c libass/ass_render.c
diffstat 5 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass.h	Wed Apr 30 14:12:11 2008 +0000
+++ b/libass/ass.h	Wed Apr 30 14:16:22 2008 +0000
@@ -94,6 +94,11 @@
 int  ass_set_fonts(ass_renderer_t* priv, const char* default_font, const char* default_family);
 
 /**
+ * \brief set font lookup defaults, don't use fontconfig even if it is available
+ */
+int  ass_set_fonts_nofc(ass_renderer_t* priv, const char* default_font, const char* default_family);
+
+/**
  * \brief render a frame, producing a list of ass_image_t
  * \param priv library
  * \param track subtitle track
--- a/libass/ass_fontconfig.c	Wed Apr 30 14:12:11 2008 +0000
+++ b/libass/ass_fontconfig.c	Wed Apr 30 14:16:22 2008 +0000
@@ -40,8 +40,6 @@
 #include <fontconfig/fcfreetype.h>
 #endif
 
-extern int font_fontconfig;
-
 struct fc_instance_s {
 #ifdef HAVE_FONTCONFIG
 	FcConfig* config;
@@ -155,7 +153,7 @@
 			uint32_t code)
 {
 	char* res = 0;
-	if (font_fontconfig < 0) {
+	if (!priv->config) {
 		*index = priv->index_default;
 		return priv->path_default;
 	}
@@ -319,16 +317,17 @@
  * \param path default font path
  * \return pointer to fontconfig private data
 */ 
-fc_instance_t* fontconfig_init(ass_library_t* library, FT_Library ftlibrary, const char* family, const char* path)
+fc_instance_t* fontconfig_init(ass_library_t* library, FT_Library ftlibrary, const char* family, const char* path, int fc)
 {
 	int rc;
 	fc_instance_t* priv = calloc(1, sizeof(fc_instance_t));
 	const char* dir = library->fonts_dir;
 	int i;
 	
-	if (font_fontconfig < 0) {
+	if (!fc) {
 		mp_msg(MSGT_ASS, MSGL_WARN,
 		       MSGTR_LIBASS_FontconfigDisabledDefaultFontWillBeUsed);
+		priv->config = NULL;
 		priv->path_default = strdup(path);
 		priv->index_default = 0;
 		return priv;
--- a/libass/ass_fontconfig.h	Wed Apr 30 14:12:11 2008 +0000
+++ b/libass/ass_fontconfig.h	Wed Apr 30 14:16:22 2008 +0000
@@ -32,7 +32,7 @@
 
 typedef struct fc_instance_s fc_instance_t;
 
-fc_instance_t* fontconfig_init(ass_library_t* library, FT_Library ftlibrary, const char* family, const char* path);
+fc_instance_t* fontconfig_init(ass_library_t* library, FT_Library ftlibrary, const char* family, const char* path, int fc);
 char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index, uint32_t code);
 void fontconfig_done(fc_instance_t* priv);
 
--- a/libass/ass_mp.c	Wed Apr 30 14:12:11 2008 +0000
+++ b/libass/ass_mp.c	Wed Apr 30 14:16:22 2008 +0000
@@ -242,7 +242,10 @@
 	else if (font_fontconfig >= 0 && font_name) family = strdup(font_name);
 	else family = 0;
 
-	ass_set_fonts(priv, path, family);
+	if (font_fontconfig >= 0)
+		ass_set_fonts(priv, path, family);
+	else
+		ass_set_fonts_nofc(priv, path, family);
 
 	free(dir);
 	free(path);
--- a/libass/ass_render.c	Wed Apr 30 14:12:11 2008 +0000
+++ b/libass/ass_render.c	Wed Apr 30 14:16:22 2008 +0000
@@ -2083,7 +2083,7 @@
 	priv->settings.line_spacing = line_spacing;
 }
 
-int ass_set_fonts(ass_renderer_t* priv, const char* default_font, const char* default_family)
+static int ass_set_fonts_(ass_renderer_t* priv, const char* default_font, const char* default_family, int fc)
 {
 	if (priv->settings.default_font)
 		free(priv->settings.default_font);
@@ -2095,11 +2095,21 @@
 
 	if (priv->fontconfig_priv)
 		fontconfig_done(priv->fontconfig_priv);
-	priv->fontconfig_priv = fontconfig_init(priv->library, priv->ftlibrary, default_family, default_font);
+	priv->fontconfig_priv = fontconfig_init(priv->library, priv->ftlibrary, default_family, default_font, fc);
 
 	return !!priv->fontconfig_priv;
 }
 
+int ass_set_fonts(ass_renderer_t* priv, const char* default_font, const char* default_family)
+{
+	return ass_set_fonts_(priv, default_font, default_family, 1);
+}
+
+int ass_set_fonts_nofc(ass_renderer_t* priv, const char* default_font, const char* default_family)
+{
+	return ass_set_fonts_(priv, default_font, default_family, 0);
+}
+
 /**
  * \brief Start a new frame
  */