comparison libass/ass_font.c @ 21317:dcfd069efd8f

Move ass_font_t allocation to ass_font.h.
author eugeni
date Mon, 27 Nov 2006 17:13:52 +0000
parents 4b2e5a74a2eb
children 415e2119e91c
comparison
equal deleted inserted replaced
21316:c07ce830b435 21317:dcfd069efd8f
46 break; 46 break;
47 } 47 }
48 } 48 }
49 } 49 }
50 50
51 int ass_font_init(FT_Library ftlibrary, void* fc_priv, ass_font_t* font, ass_font_desc_t* desc) 51 ass_font_t* ass_font_new(FT_Library ftlibrary, void* fc_priv, ass_font_desc_t* desc)
52 { 52 {
53 char* path; 53 char* path;
54 int index; 54 int index;
55 FT_Face face; 55 FT_Face face;
56 int error; 56 int error;
57 ass_font_t* font;
58
59 font = ass_font_cache_find(desc);
60 if (font)
61 return font;
57 62
58 path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index); 63 path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index);
59 64
60 error = FT_New_Face(ftlibrary, path, index, &face); 65 error = FT_New_Face(ftlibrary, path, index, &face);
61 if (error) { 66 if (error) {
62 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); 67 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index);
63 return 1; 68 return 0;
64 } 69 }
65 70
66 charmap_magic(face); 71 charmap_magic(face);
67 72
73 font = calloc(1, sizeof(ass_font_t));
68 font->path = strdup(path); 74 font->path = strdup(path);
69 font->index = index; 75 font->index = index;
70 font->face = face; 76 font->face = face;
71 font->desc.family = strdup(desc->family); 77 font->desc.family = strdup(desc->family);
72 font->desc.bold = desc->bold; 78 font->desc.bold = desc->bold;
75 font->m.xx = font->m.yy = (FT_Fixed)0x10000L; 81 font->m.xx = font->m.yy = (FT_Fixed)0x10000L;
76 font->m.xy = font->m.yy = 0; 82 font->m.xy = font->m.yy = 0;
77 font->v.x = font->v.y = 0; 83 font->v.x = font->v.y = 0;
78 font->size = 0; 84 font->size = 0;
79 85
80 return 0; 86 ass_font_cache_add(font);
87
88 return font;
81 } 89 }
82 90
83 void ass_font_set_transform(ass_font_t* font, FT_Matrix* m, FT_Vector* v) 91 void ass_font_set_transform(ass_font_t* font, FT_Matrix* m, FT_Vector* v)
84 { 92 {
85 font->m.xx = m->xx; 93 font->m.xx = m->xx;
131 void ass_font_free(ass_font_t* font) 139 void ass_font_free(ass_font_t* font)
132 { 140 {
133 if (font->face) FT_Done_Face(font->face); 141 if (font->face) FT_Done_Face(font->face);
134 if (font->path) free(font->path); 142 if (font->path) free(font->path);
135 if (font->desc.family) free(font->desc.family); 143 if (font->desc.family) free(font->desc.family);
144 free(font);
136 } 145 }