[MPlayer-cvslog] r28895 - in trunk: DOCS/man/en/mplayer.1 libass/ass_cache.c libass/ass_font.c libass/ass_font.h libass/ass_fontconfig.c libass/ass_fontconfig.h libass/ass_mp.c libass/ass_render.c libass/ass_types.h

eugeni subversion at mplayerhq.hu
Sun Mar 8 17:13:22 CET 2009


Author: eugeni
Date: Sun Mar  8 17:13:21 2009
New Revision: 28895

Log:
Treat -font/-subfont as Fontconfig pattern in libass.

Patch by Adrian Stutz (adrian sttz ch).

Modified:
   trunk/libass/ass_cache.c
   trunk/libass/ass_font.c
   trunk/libass/ass_font.h
   trunk/libass/ass_fontconfig.c
   trunk/libass/ass_fontconfig.h
   trunk/libass/ass_mp.c
   trunk/libass/ass_render.c
   trunk/libass/ass_types.h

Changes in other areas also in this revision:
Modified:
   trunk/DOCS/man/en/mplayer.1

Modified: trunk/libass/ass_cache.c
==============================================================================
--- trunk/libass/ass_cache.c	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_cache.c	Sun Mar  8 17:13:21 2009	(r28895)
@@ -192,6 +192,8 @@ static int font_compare(void* key1, void
 		return 0;
 	if (a->italic != b->italic)
 		return 0;
+	if (a->treat_family_as_pattern != b->treat_family_as_pattern)
+		return 0;
 	return 1;
 }
 

Modified: trunk/libass/ass_font.c
==============================================================================
--- trunk/libass/ass_font.c	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_font.c	Sun Mar  8 17:13:21 2009	(r28895)
@@ -125,7 +125,7 @@ static int add_face(void* fc_priv, ass_f
 	if (font->n_faces == ASS_FONT_MAX_FACES)
 		return -1;
 	
-	path = fontconfig_select(fc_priv, font->desc.family, font->desc.bold,
+	path = fontconfig_select(fc_priv, font->desc.family, font->desc.treat_family_as_pattern, font->desc.bold,
 					      font->desc.italic, &index, ch);
 
 	mem_idx = find_font(font->library, path);
@@ -169,6 +169,7 @@ ass_font_t* ass_font_new(ass_library_t* 
 	font.ftlibrary = ftlibrary;
 	font.n_faces = 0;
 	font.desc.family = strdup(desc->family);
+	font.desc.treat_family_as_pattern = desc->treat_family_as_pattern;
 	font.desc.bold = desc->bold;
 	font.desc.italic = desc->italic;
 

Modified: trunk/libass/ass_font.h
==============================================================================
--- trunk/libass/ass_font.h	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_font.h	Sun Mar  8 17:13:21 2009	(r28895)
@@ -33,6 +33,7 @@ typedef struct ass_font_desc_s {
 	char* family;
 	unsigned bold;
 	unsigned italic;
+	int treat_family_as_pattern;
 } ass_font_desc_t;
 
 #define ASS_FONT_MAX_FACES 10

Modified: trunk/libass/ass_fontconfig.c
==============================================================================
--- trunk/libass/ass_fontconfig.c	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_fontconfig.c	Sun Mar  8 17:13:21 2009	(r28895)
@@ -66,14 +66,15 @@ struct fc_instance_s {
  * \brief Low-level font selection.
  * \param priv private data
  * \param family font family
+ * \param treat_family_as_pattern treat family as fontconfig pattern
  * \param bold font weight value
  * \param italic font slant value
  * \param index out: font index inside a file
  * \param code: the character that should be present in the font, can be 0
  * \return font file path
 */ 
-static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
-			  uint32_t code)
+static char* _select_font(fc_instance_t* priv, const char* family, int treat_family_as_pattern,
+			  unsigned bold, unsigned italic, int* index, uint32_t code)
 {
 	FcBool rc;
 	FcResult result;
@@ -89,10 +90,15 @@ static char* _select_font(fc_instance_t*
 	
 	*index = 0;
 
-	pat = FcPatternCreate();
+	if (treat_family_as_pattern)
+		pat = FcNameParse((const FcChar8*)family);
+	else
+		pat = FcPatternCreate();
+
 	if (!pat)
 		goto error;
 	
+	if (!treat_family_as_pattern) {
 	FcPatternAddString(pat, FC_FAMILY, (const FcChar8*)family);
 
 	// In SSA/ASS fonts are sometimes referenced by their "full name",
@@ -118,6 +124,7 @@ static char* _select_font(fc_instance_t*
 			}
 		free(s);
 	}
+	}
 	FcPatternAddBool(pat, FC_OUTLINE, FcTrue);
 	FcPatternAddInteger(pat, FC_SLANT, italic);
 	FcPatternAddInteger(pat, FC_WEIGHT, bold);
@@ -182,7 +189,8 @@ static char* _select_font(fc_instance_t*
 	if (result != FcResultMatch)
 		r_fullname = NULL;
 
-	if (!(r_family && strcasecmp((const char*)r_family, family) == 0) &&
+	if (!treat_family_as_pattern &&
+		!(r_family && strcasecmp((const char*)r_family, family) == 0) &&
 	    !(r_fullname && strcasecmp((const char*)r_fullname, family) == 0))
 		mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_SelectedFontFamilyIsNotTheRequestedOne,
 		       (const char*)(r_fullname ? r_fullname : r_family), family);
@@ -219,14 +227,15 @@ static char* _select_font(fc_instance_t*
  * \brief Find a font. Use default family or path if necessary.
  * \param priv_ private data
  * \param family font family
+ * \param treat_family_as_pattern treat family as fontconfig pattern
  * \param bold font weight value
  * \param italic font slant value
  * \param index out: font index inside a file
  * \param code: the character that should be present in the font, can be 0
  * \return font file path
 */ 
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
-			uint32_t code)
+char* fontconfig_select(fc_instance_t* priv, const char* family, int treat_family_as_pattern,
+			unsigned bold, unsigned italic, int* index, uint32_t code)
 {
 	char* res = 0;
 	if (!priv->config) {
@@ -234,9 +243,9 @@ char* fontconfig_select(fc_instance_t* p
 		return priv->path_default;
 	}
 	if (family && *family)
-		res = _select_font(priv, family, bold, italic, index, code);
+		res = _select_font(priv, family, treat_family_as_pattern, bold, italic, index, code);
 	if (!res && priv->family_default) {
-		res = _select_font(priv, priv->family_default, bold, italic, index, code);
+		res = _select_font(priv, priv->family_default, 0, bold, italic, index, code);
 		if (res)
 			mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingDefaultFontFamily, 
 					family, bold, italic, res, *index);
@@ -248,7 +257,7 @@ char* fontconfig_select(fc_instance_t* p
 		       family, bold, italic, res, *index);
 	}
 	if (!res) {
-		res = _select_font(priv, "Arial", bold, italic, index, code);
+		res = _select_font(priv, "Arial", 0, bold, italic, index, code);
 		if (res)
 			mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingArialFontFamily, 
 					family, bold, italic, res, *index);
@@ -474,8 +483,8 @@ exit:
 
 #else /* CONFIG_FONTCONFIG */
 
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
-			uint32_t code)
+char* fontconfig_select(fc_instance_t* priv, const char* family, int treat_family_as_pattern,
+			unsigned bold, unsigned italic, int* index, uint32_t code)
 {
 	*index = priv->index_default;
 	return priv->path_default;

Modified: trunk/libass/ass_fontconfig.h
==============================================================================
--- trunk/libass/ass_fontconfig.h	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_fontconfig.h	Sun Mar  8 17:13:21 2009	(r28895)
@@ -35,7 +35,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, int fc);
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index, uint32_t code);
+char* fontconfig_select(fc_instance_t* priv, const char* family, int treat_family_as_pattern, unsigned bold, unsigned italic, int* index, uint32_t code);
 void fontconfig_done(fc_instance_t* priv);
 
 #endif /* LIBASS_FONTCONFIG_H */

Modified: trunk/libass/ass_mp.c
==============================================================================
--- trunk/libass/ass_mp.c	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_mp.c	Sun Mar  8 17:13:21 2009	(r28895)
@@ -94,6 +94,7 @@ ass_track_t* ass_default_track(ass_libra
 		style = track->styles + sid;
 		style->Name = strdup("Default");
 		style->FontName = (font_fontconfig >= 0 && sub_font_name) ? strdup(sub_font_name) : (font_fontconfig >= 0 && font_name) ? strdup(font_name) : strdup("Sans");
+		style->treat_fontname_as_pattern = 1;
 
 		fs = track->PlayResY * text_font_scale_factor / 100.;
 		// approximate autoscale coefficients

Modified: trunk/libass/ass_render.c
==============================================================================
--- trunk/libass/ass_render.c	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_render.c	Sun Mar  8 17:13:21 2009	(r28895)
@@ -184,6 +184,7 @@ typedef struct render_context_s {
 	char* family;
 	unsigned bold;
 	unsigned italic;
+	int treat_family_as_pattern;
 	
 } render_context_t;
 
@@ -676,6 +677,7 @@ static void update_font(void)
 	ass_renderer_t* priv = frame_context.ass_priv;
 	ass_font_desc_t desc;
 	desc.family = strdup(render_context.family);
+	desc.treat_family_as_pattern = render_context.treat_family_as_pattern;
 
 	val = render_context.bold;
 	// 0 = normal, 1 = bold, >1 = exact weight
@@ -1359,6 +1361,7 @@ static void reset_render_context(void)
 	if (render_context.family)
 		free(render_context.family);
 	render_context.family = strdup(render_context.style->FontName);
+	render_context.treat_family_as_pattern = render_context.style->treat_fontname_as_pattern;
 	render_context.bold = render_context.style->Bold;
 	render_context.italic = render_context.style->Italic;
 	update_font();

Modified: trunk/libass/ass_types.h
==============================================================================
--- trunk/libass/ass_types.h	Sun Mar  8 16:56:20 2009	(r28894)
+++ trunk/libass/ass_types.h	Sun Mar  8 17:13:21 2009	(r28895)
@@ -58,6 +58,7 @@ typedef struct ass_style_s {
 	int MarginV;
 //        int AlphaLevel;
 	int Encoding;
+	int treat_fontname_as_pattern;
 } ass_style_t;
 
 typedef struct render_priv_s render_priv_t;



More information about the MPlayer-cvslog mailing list