]> granicus.if.org Git - libass/commitdiff
fontselect: don't trim font names
authorOleg Oshmyan <chortos@inbox.lv>
Thu, 22 Oct 2015 23:20:19 +0000 (02:20 +0300)
committerOleg Oshmyan <chortos@inbox.lv>
Thu, 22 Oct 2015 23:47:03 +0000 (02:47 +0300)
This matches the behavior of GDI and hence VSFilter.

Note that \fn arguments are trimmed during parsing.
However, none of the names inside fonts should be trimmed,
and @-prefixed fonts should keep whitespace following the @,
both of which this commit addresses.

Remove strdup_trimmed because it is no longer used. Also remove
the declaration of a function that was deleted a few months ago.

libass/ass_fontselect.c
libass/ass_utils.c
libass/ass_utils.h

index ce24f7edf707f7f3cbdb9d9f872da1278db80801..2259265d67f44ad4fae4c9786fa1e5bc3fd87f96 100644 (file)
@@ -595,22 +595,21 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
 {
     ASS_FontProvider *default_provider = priv->default_provider;
     ASS_FontProviderMetaData meta = {0};
-    char *family_trim = strdup_trimmed(family);
     char *result = NULL;
     bool name_match = false;
 
-    if (family_trim == NULL)
+    if (family == NULL)
         return NULL;
 
     ASS_FontProviderMetaData default_meta = {
         .n_fullname = 1,
-        .fullnames  = &family_trim,
+        .fullnames  = &family,
     };
 
     // Get a list of substitutes if applicable, and use it for matching.
     if (default_provider && default_provider->funcs.get_substitutions) {
         default_provider->funcs.get_substitutions(default_provider->priv,
-                                                  family_trim, &meta);
+                                                  family, &meta);
     }
 
     if (!meta.n_fullname) {
@@ -636,7 +635,6 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
     }
 
     // cleanup
-    free(family_trim);
     if (meta.fullnames != default_meta.fullnames) {
         for (int i = 0; i < meta.n_fullname; i++)
             free(meta.fullnames[i]);
@@ -732,7 +730,6 @@ get_font_info(FT_Library lib, FT_Face face, ASS_FontProviderMetaData *info)
     int slant, weight;
     char *fullnames[MAX_FULLNAME];
     char *families[MAX_FULLNAME];
-    char *postscript_name = NULL;
     PS_FontInfoRec postscript_info;
 
     // we're only interested in outlines
@@ -753,14 +750,14 @@ get_font_info(FT_Library lib, FT_Face face, ASS_FontProviderMetaData *info)
                                 name.string_len);
 
             if (name.name_id == TT_NAME_ID_FULL_NAME) {
-                fullnames[num_fullname] = strdup_trimmed(buf);
+                fullnames[num_fullname] = strdup(buf);
                 if (fullnames[num_fullname] == NULL)
                     goto error;
                 num_fullname++;
             }
 
             if (name.name_id == TT_NAME_ID_FONT_FAMILY) {
-                families[num_family] = strdup_trimmed(buf);
+                families[num_family] = strdup(buf);
                 if (families[num_family] == NULL)
                     goto error;
                 num_family++;
@@ -781,10 +778,6 @@ get_font_info(FT_Library lib, FT_Face face, ASS_FontProviderMetaData *info)
     if (num_family == 0)
         goto error;
 
-    postscript_name = FT_Get_Postscript_Name(face);
-    if (postscript_name != NULL)
-        postscript_name = strdup_trimmed(postscript_name);
-
     // calculate sensible slant and weight from style attributes
     slant  = 110 * !!(face->style_flags & FT_STYLE_FLAG_ITALIC);
     weight = 300 * !!(face->style_flags & FT_STYLE_FLAG_BOLD) + 400;
@@ -794,7 +787,7 @@ get_font_info(FT_Library lib, FT_Face face, ASS_FontProviderMetaData *info)
     info->weight = weight;
     info->width  = 100;     // FIXME, should probably query the OS/2 table
 
-    info->postscript_name = postscript_name;
+    info->postscript_name = FT_Get_Postscript_Name(face);
     info->is_postscript = !FT_Get_PS_Font_Info(face, &postscript_info);
 
     info->families = calloc(sizeof(char *), num_family);
@@ -822,7 +815,6 @@ error:
 
     free(info->families);
     free(info->fullnames);
-    free(postscript_name);
 
     return true;
 }
@@ -844,7 +836,6 @@ static void free_font_info(ASS_FontProviderMetaData *meta)
 
     free(meta->families);
     free(meta->fullnames);
-    free(meta->postscript_name);
 }
 
 /**
index ab1ea0283f8400c6aec66feae9ff19a2f8a60ce6..bcaeec1c991f860163066fb3538fb6c6cad138e2 100644 (file)
@@ -334,28 +334,6 @@ void ass_msg(ASS_Library *priv, int lvl, const char *fmt, ...)
     va_end(va);
 }
 
-/**
- * Return a string with spaces trimmed at start and end.
- * \param str input string
- * \return output string, can be released with free()
- */
-char *strdup_trimmed(const char *str)
-{
-    int left = 0;
-    int right = strlen(str) - 1;
-    char *out = NULL;
-
-    while (ass_isspace(str[left])) left++;
-    while (right > left && ass_isspace(str[right])) right--;
-
-    out = calloc(1, right-left+2);
-
-    if (out)
-        memcpy(out, str + left, right-left+1);
-
-    return out;
-}
-
 unsigned ass_utf8_get_char(char **str)
 {
     uint8_t *strp = (uint8_t *) * str;
index c2f5a19e281b5e98ab1c162497ea9d48a7af975c..5c3f65fe06fbc32953ad637fd444de0ee4307743 100644 (file)
@@ -84,8 +84,6 @@ int mystrtoi32(char **p, int base, int32_t *res);
 int32_t parse_alpha_tag(char *str);
 uint32_t parse_color_tag(char *str);
 uint32_t parse_color_header(char *str);
-char *trim_space(char *str);
-char *strdup_trimmed(const char *str);
 char parse_bool(char *str);
 int parse_ycbcr_matrix(char *str);
 unsigned ass_utf8_get_char(char **str);