]> granicus.if.org Git - libass/commitdiff
fontselect: move PostScript name into ASS_FontProviderMetaData
authorOleg Oshmyan <chortos@inbox.lv>
Mon, 19 Oct 2015 13:11:27 +0000 (16:11 +0300)
committerOleg Oshmyan <chortos@inbox.lv>
Wed, 21 Oct 2015 18:36:48 +0000 (21:36 +0300)
libass/ass_coretext.c
libass/ass_directwrite.c
libass/ass_fontconfig.c
libass/ass_fontselect.c
libass/ass_fontselect.h

index fdc7bd1f2802b6353f63899ed2249169d6f4edb0..a2cd77f50f065ad0d74d127b44876000aa15e9e6 100644 (file)
@@ -185,15 +185,16 @@ static void process_descriptors(ASS_FontProvider *provider, CFArrayRef fontsd)
         get_name(fontd, kCTFontFamilyNameAttribute, families, &meta.n_family);
         meta.families = families;
 
-        int zero = 0;
-        get_name(fontd, kCTFontNameAttribute, identifiers, &zero);
         get_name(fontd, kCTFontDisplayNameAttribute, fullnames, &meta.n_fullname);
         meta.fullnames = fullnames;
 
+        int zero = 0;
+        get_name(fontd, kCTFontNameAttribute, identifiers, &zero);
+        meta.postscript_name = identifiers[0];
+
         CFCharacterSetRef chset =
             CTFontDescriptorCopyAttribute(fontd, kCTFontCharacterSetAttribute);
-        ass_font_provider_add_font(provider, &meta, path, index,
-                                   identifiers[0], (void*)chset);
+        ass_font_provider_add_font(provider, &meta, path, index, (void*)chset);
 
         for (int j = 0; j < meta.n_family; j++)
             free(meta.families[j]);
@@ -201,7 +202,7 @@ static void process_descriptors(ASS_FontProvider *provider, CFArrayRef fontsd)
         for (int j = 0; j < meta.n_fullname; j++)
             free(meta.fullnames[j]);
 
-        free(identifiers[0]);
+        free(meta.postscript_name);
 
         free(path);
     }
index 521447d1da95e49f8bc0d2b4332765b2e9b97fbd..6b6b623df19543af2d4520725b19b503d2a6168a 100644 (file)
@@ -512,7 +512,6 @@ static void scan_fonts(IDWriteFactory *factory,
         IDWriteLocalizedStrings *fontNames = NULL;
         IDWriteLocalizedStrings *psNames = NULL;
         BOOL exists = FALSE;
-        char *psName = NULL;
 
         hr = IDWriteFontCollection_GetFontFamily(fontCollection, i, &fontFamily);
         if (FAILED(hr))
@@ -556,8 +555,10 @@ static void scan_fonts(IDWriteFactory *factory,
 
                 temp_name[NAME_MAX_LENGTH-1] = 0;
                 size_needed = WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, NULL, 0,NULL, NULL);
-                psName = (char *) malloc(size_needed);
-                WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, psName, size_needed, NULL, NULL);
+                char *mbName = (char *) malloc(size_needed);
+                WideCharToMultiByte(CP_UTF8, 0, temp_name, -1, mbName, size_needed, NULL, NULL);
+                meta.postscript_name = mbName;
+
                 IDWriteLocalizedStrings_Release(psNames);
             }
 
@@ -618,7 +619,7 @@ static void scan_fonts(IDWriteFactory *factory,
             FontPrivate *font_priv = (FontPrivate *) calloc(1, sizeof(*font_priv));
             font_priv->font = font;
 
-            ass_font_provider_add_font(provider, &meta, NULL, 0, psName, font_priv);
+            ass_font_provider_add_font(provider, &meta, NULL, 0, font_priv);
 
             for (UINT32 k = 0; k < meta.n_family; ++k)
                 free(meta.families[k]);
@@ -626,7 +627,7 @@ static void scan_fonts(IDWriteFactory *factory,
                 free(meta.fullnames[k]);
             free(meta.fullnames);
             free(meta.families);
-            free(psName);
+            free(meta.postscript_name);
         }
     }
 }
index 30a9d38a2f63371b2a15e2afcc7156bf6e288729..8f885c8faf9c4af83db0bcf65e78c4a03e51721d 100644 (file)
@@ -133,8 +133,7 @@ static void scan_fonts(FcConfig *config, ASS_FontProvider *provider)
             meta.n_fullname++;
         meta.fullnames = fullnames;
 
-        ass_font_provider_add_font(provider, &meta, path, index, NULL,
-                                   (void *)pat);
+        ass_font_provider_add_font(provider, &meta, path, index, (void *)pat);
     }
 }
 
index 72d6d0b4d3c0a25b1c99d89b2e9868a5bf9222dc..d0d282f8e70a6f22db9a09d08588b410a55eaaaa 100644 (file)
@@ -237,14 +237,13 @@ static void ass_font_provider_free_fontinfo(ASS_FontInfo *info)
  * \param meta basic metadata of the font
  * \param path path to the font file, or NULL
  * \param index face index inside the file (-1 to look up by PostScript name)
- * \param psname PostScript name of the face
  * \param data private data for the font
  * \return success
  */
 int
 ass_font_provider_add_font(ASS_FontProvider *provider,
                            ASS_FontProviderMetaData *meta, const char *path,
-                           int index, const char *psname, void *data)
+                           int index, void *data)
 {
     int i;
     int weight, slant, width;
@@ -322,15 +321,15 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
             goto error;
     }
 
-    if (path) {
-        info->path = strdup(path);
-        if (info->path == NULL)
+    if (meta->postscript_name) {
+        info->postscript_name = strdup(meta->postscript_name);
+        if (info->postscript_name == NULL)
             goto error;
     }
 
-    if (psname) {
-        info->postscript_name = strdup(psname);
-        if (info->postscript_name == NULL)
+    if (path) {
+        info->path = strdup(path);
+        if (info->path == NULL)
             goto error;
     }
 
@@ -881,8 +880,7 @@ static void process_fontdata(ASS_FontProvider *priv, ASS_Library *library,
         ft->face = face;
         ft->idx  = idx;
 
-        if (ass_font_provider_add_font(priv, &info, NULL, face_index,
-                    NULL, ft)) {
+        if (ass_font_provider_add_font(priv, &info, NULL, face_index, ft)) {
             ass_msg(library, MSGL_WARN, "Failed to add embedded font '%s'",
                     name);
         }
index 93bd746c933e8fa19163324f52905c7b96e987e0..f1e2933221b061084fe2cae680bb78e675b8eaec 100644 (file)
@@ -147,7 +147,6 @@ typedef struct font_provider_funcs {
  * At minimum one family is required.
  */
 struct ass_font_provider_meta_data {
-
     /**
      * List of localized font family names, e.g. "Arial".
      */
@@ -158,6 +157,12 @@ struct ass_font_provider_meta_data {
      * The English name should be listed first to speed up typical matching.
      */
     char **fullnames;
+
+    /**
+     * The PostScript name, e.g. "Arial-BoldMT".
+     */
+    char *postscript_name;
+
     int n_family;       // Number of localized family names
     int n_fullname;     // Number of localized full names
 
@@ -231,7 +236,6 @@ ass_create_font_provider(ASS_Renderer *priv, ASS_FontProviderFuncs *funcs,
  * \param path absolute path to font, or NULL for memory-based fonts
  * \param index index inside a font collection file
  *              (-1 to look up by PostScript name)
- * \param psname PostScript name of the face
  * \param data private data for font callbacks
  * \return success
  *
@@ -239,7 +243,7 @@ ass_create_font_provider(ASS_Renderer *priv, ASS_FontProviderFuncs *funcs,
 int
 ass_font_provider_add_font(ASS_FontProvider *provider,
                            ASS_FontProviderMetaData *meta, const char *path,
-                           int index, const char *psname, void *data);
+                           int index, void *data);
 
 /**
  * \brief Free font provider and associated fonts.