summaryrefslogtreecommitdiffstats
path: root/libass/ass_font.c
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-11-02 12:07:07 +0100
committerGrigori Goronzy <greg@chown.ath.cx>2015-07-10 10:42:40 +0200
commit9014b275e9e90d796bee95249a6059e4a55f3cf9 (patch)
treecb8972dc534a88fd4dc2bf3ee88a0735cdc53035 /libass/ass_font.c
parentd9585a81add0a41f6a59f3c7f95bcc6182732059 (diff)
downloadlibass-9014b275e9e90d796bee95249a6059e4a55f3cf9.tar.bz2
libass-9014b275e9e90d796bee95249a6059e4a55f3cf9.tar.xz
fontselect: coretext: allow selection based on PostScript name
Up until now fontselect used the face index to identify which font to load from a font collection. While this pretty convenient when using something freetype based like fontconfig, it seems to be somewhat freetype specific. CoreText uses the PostScript name as the unique identifier of a font. This commit allows to use that instead of the index to decide which face to open with FT_New_Face. To use the PostScript name the provider must return a -1 index and the PostScript name.
Diffstat (limited to 'libass/ass_font.c')
-rw-r--r--libass/ass_font.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/libass/ass_font.c b/libass/ass_font.c
index 0b6d24b..9a81dca 100644
--- a/libass/ass_font.c
+++ b/libass/ass_font.c
@@ -135,6 +135,7 @@ close_stream_font(FT_Stream stream)
static int add_face(ASS_FontSelector *fontsel, ASS_Font *font, uint32_t ch)
{
char *path;
+ char *postscript_name;
int i, index, uid, error;
ASS_FontStream stream = { NULL, NULL };
FT_Face face;
@@ -142,8 +143,8 @@ static int add_face(ASS_FontSelector *fontsel, ASS_Font *font, uint32_t ch)
if (font->n_faces == ASS_FONT_MAX_FACES)
return -1;
- path = ass_font_select(fontsel, font->library, font , &index, &uid,
- &stream, ch);
+ path = ass_font_select(fontsel, font->library, font , &index,
+ &postscript_name, &uid, &stream, ch);
if (!path)
return -1;
@@ -191,6 +192,25 @@ static int add_face(ASS_FontSelector *fontsel, ASS_Font *font, uint32_t ch)
free(path);
return -1;
}
+
+ if (postscript_name && index < 0 && face->num_faces > 0) {
+ // The font provider gave us a post_script name and is not sure
+ // about the face index.. so use the postscript name to find the
+ // correct face_index in the collection!
+ for (int i = 0; face->num_faces; i++) {
+ FT_Done_Face(face);
+ error = FT_New_Face(font->ftlibrary, path, i, &face);
+ if (error) {
+ ass_msg(font->library, MSGL_WARN,
+ "Error opening font: '%s', %d", path, i);
+ free(path);
+ return -1;
+ }
+
+ if (strcmp(FT_Get_Postscript_Name(face), postscript_name) == 0)
+ break;
+ }
+ }
}
charmap_magic(font->library, face);