aboutsummaryrefslogtreecommitdiffhomepage
path: root/libass
diff options
context:
space:
mode:
authorGravatar eugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>2009-03-08 16:13:21 +0000
committerGravatar eugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>2009-03-08 16:13:21 +0000
commit686d57168f91e7314a0dc7a3ce95a905e83e49dc (patch)
treed87bc1c32a0dfb15d9f30966cd01ec6be74bf437 /libass
parent1f612555888ae906248cad0fad70667adce1c58f (diff)
Treat -font/-subfont as Fontconfig pattern in libass.
Patch by Adrian Stutz (adrian sttz ch). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28895 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libass')
-rw-r--r--libass/ass_cache.c2
-rw-r--r--libass/ass_font.c3
-rw-r--r--libass/ass_font.h1
-rw-r--r--libass/ass_fontconfig.c31
-rw-r--r--libass/ass_fontconfig.h2
-rw-r--r--libass/ass_mp.c1
-rw-r--r--libass/ass_render.c3
-rw-r--r--libass/ass_types.h1
8 files changed, 31 insertions, 13 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c
index 0561874606..3b90e66e4c 100644
--- a/libass/ass_cache.c
+++ b/libass/ass_cache.c
@@ -192,6 +192,8 @@ static int font_compare(void* key1, void* key2, size_t key_size) {
return 0;
if (a->italic != b->italic)
return 0;
+ if (a->treat_family_as_pattern != b->treat_family_as_pattern)
+ return 0;
return 1;
}
diff --git a/libass/ass_font.c b/libass/ass_font.c
index f2214a345d..579e658f14 100644
--- a/libass/ass_font.c
+++ b/libass/ass_font.c
@@ -125,7 +125,7 @@ static int add_face(void* fc_priv, ass_font_t* font, uint32_t ch)
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* library, FT_Library ftlibrary, void* fc_
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;
diff --git a/libass/ass_font.h b/libass/ass_font.h
index 03396a6f21..520431821b 100644
--- a/libass/ass_font.h
+++ b/libass/ass_font.h
@@ -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
diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c
index 9a7bddecc4..9bdca86f31 100644
--- a/libass/ass_fontconfig.c
+++ b/libass/ass_fontconfig.c
@@ -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* priv, const char* family, unsigned bold
*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* priv, const char* family, unsigned bold
}
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* priv, const char* family, unsigned bold
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* priv, const char* family, unsigned bold
* \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* priv, const char* family, unsigned bold,
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* priv, const char* family, unsigned bold,
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;
diff --git a/libass/ass_fontconfig.h b/libass/ass_fontconfig.h
index e9a1ce1567..77806909cf 100644
--- a/libass/ass_fontconfig.h
+++ b/libass/ass_fontconfig.h
@@ -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 */
diff --git a/libass/ass_mp.c b/libass/ass_mp.c
index 40da63c348..7e25b8e316 100644
--- a/libass/ass_mp.c
+++ b/libass/ass_mp.c
@@ -94,6 +94,7 @@ ass_track_t* ass_default_track(ass_library_t* library) {
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
diff --git a/libass/ass_render.c b/libass/ass_render.c
index dec08e519d..b561b2a82a 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -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();
diff --git a/libass/ass_types.h b/libass/ass_types.h
index 52aff0fb85..01c36c5748 100644
--- a/libass/ass_types.h
+++ b/libass/ass_types.h
@@ -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;