changeset 26591:0f069e41d8d2

Allow inexact font family matching. In SSA/ASS fonts are sometimes referenced by their "full name", which is usually a concatenation of family name and font style (ex. Ottawa Bold). Full name is available from FontConfig pattern element FC_FULLNAME, but it is never used for font matching. Therefore, I'm removing words from the end of the name one by one, and adding shortened names to the pattern. It seems that the first value (full name in this case) has precedence in matching.
author eugeni
date Thu, 01 May 2008 00:34:26 +0000
parents ccfcdc2323aa
children cc9b88c49d90
files libass/ass_fontconfig.c
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass_fontconfig.c	Wed Apr 30 17:54:02 2008 +0000
+++ b/libass/ass_fontconfig.c	Thu May 01 00:34:26 2008 +0000
@@ -81,6 +81,26 @@
 		goto error;
 	
 	FcPatternAddString(pat, FC_FAMILY, (const FcChar8*)family);
+
+	// In SSA/ASS fonts are sometimes referenced by their "full name",
+	// which is usually a concatenation of family name and font
+	// style (ex. Ottawa Bold). Full name is available from
+	// FontConfig pattern element FC_FULLNAME, but it is never
+	// used for font matching.
+	// Therefore, I'm removing words from the end of the name one
+	// by one, and adding shortened names to the pattern. It seems
+	// that the first value (full name in this case) has
+	// precedence in matching.
+	// An alternative approach could be to reimplement FcFontSort
+	// using FC_FULLNAME instead of FC_FAMILY.
+	if (strchr(family, ' ')) {
+		char *p, *s = strdup(family);
+		while (p = strrchr(s, ' ')) {
+			*p = '\0';
+			FcPatternAddString(pat, FC_FAMILY, (const FcChar8*)s);
+		}
+		free(s);
+	}
 	FcPatternAddBool(pat, FC_OUTLINE, FcTrue);
 	FcPatternAddInteger(pat, FC_SLANT, italic);
 	FcPatternAddInteger(pat, FC_WEIGHT, bold);