summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@chown.ath.cx>2011-08-19 01:24:13 +0200
committerGrigori Goronzy <greg@chown.ath.cx>2015-07-10 10:42:40 +0200
commit544a89104b99a3e1e8fc234e2e777d85baed91b9 (patch)
treeb13b7f1032f1d54b0ad7be18acc5c7af0664265d
parent93c4e8ebf3dea5c9e1978f78a33cb961d6a1aaf7 (diff)
downloadlibass-544a89104b99a3e1e8fc234e2e777d85baed91b9.tar.bz2
libass-544a89104b99a3e1e8fc234e2e777d85baed91b9.tar.xz
Check weight and slant validity in font provider
When adding a new font, check that weight and slant are valid. If they're not, use reasonable defaults.
-rw-r--r--libass/ass_fontselect.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index 3bf67fd..ad91bf6 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -62,7 +62,7 @@ struct font_info {
int n_fullname;
int slant;
- int weight;
+ int weight; // TrueType scale, 100-900
// how to access this face
char *path;
@@ -175,11 +175,21 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
unsigned int index, void *data)
{
int i;
+ int weight, slant;
ASS_FontSelector *selector = provider->parent;
ASS_FontInfo *info;
// TODO: sanity checks. do we have a path or valid get_face function?
+ weight = meta->weight;
+ slant = meta->slant;
+
+ // check slant/weight for validity, use defaults if they're invalid
+ if (weight < 100 || weight > 900)
+ meta->weight = 400;
+ if (slant < 0 || slant > 110)
+ slant = 0;
+
// check size
if (selector->n_font >= selector->alloc_font) {
selector->alloc_font = FFMAX(1, 2 * selector->alloc_font);
@@ -194,8 +204,8 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
// set uid
info->uid = selector->uid++;
- info->slant = meta->slant;
- info->weight = meta->weight;
+ info->slant = slant;
+ info->weight = weight;
info->family = strdup(meta->family);
info->n_fullname = meta->n_fullname;
info->fullnames = calloc(meta->n_fullname, sizeof(char *));