Mercurial > mplayer.hg
comparison libass/ass_cache.c @ 21277:0603972f083c
Move fonts-related code to a separate file.
author | eugeni |
---|---|
date | Sun, 26 Nov 2006 22:49:27 +0000 |
parents | 9ec30b8622ec |
children | 9040bce9f768 |
comparison
equal
deleted
inserted
replaced
21276:eda0d1a84e81 | 21277:0603972f083c |
---|---|
28 | 28 |
29 #include "mputils.h" | 29 #include "mputils.h" |
30 #include "ass_fontconfig.h" | 30 #include "ass_fontconfig.h" |
31 #include "ass_bitmap.h" | 31 #include "ass_bitmap.h" |
32 #include "ass_cache.h" | 32 #include "ass_cache.h" |
33 #include "ass_font.h" | |
33 | 34 |
34 #define MAX_FONT_CACHE_SIZE 100 | 35 #define MAX_FONT_CACHE_SIZE 100 |
35 | 36 |
36 static ass_font_t* font_cache; | 37 static ass_font_t* font_cache; |
37 static int font_cache_size; | 38 static int font_cache_size; |
44 if (a->bold != b->bold) | 45 if (a->bold != b->bold) |
45 return 0; | 46 return 0; |
46 if (a->italic != b->italic) | 47 if (a->italic != b->italic) |
47 return 0; | 48 return 0; |
48 return 1; | 49 return 1; |
49 } | |
50 | |
51 /** | |
52 * Select Microfost Unicode CharMap, if the font has one. | |
53 * Otherwise, let FreeType decide. | |
54 */ | |
55 static void charmap_magic(FT_Face face) | |
56 { | |
57 int i; | |
58 for (i = 0; i < face->num_charmaps; ++i) { | |
59 FT_CharMap cmap = face->charmaps[i]; | |
60 unsigned pid = cmap->platform_id; | |
61 unsigned eid = cmap->encoding_id; | |
62 if (pid == 3 /*microsoft*/ && (eid == 1 /*unicode bmp*/ || eid == 10 /*full unicode*/)) { | |
63 FT_Set_Charmap(face, cmap); | |
64 break; | |
65 } | |
66 } | |
67 } | 50 } |
68 | 51 |
69 /** | 52 /** |
70 * \brief Get a face object, either from cache or created through FreeType+FontConfig. | 53 * \brief Get a face object, either from cache or created through FreeType+FontConfig. |
71 * \param library FreeType library object | 54 * \param library FreeType library object |
73 * \param desc required face description | 56 * \param desc required face description |
74 * \return new font struct | 57 * \return new font struct |
75 */ | 58 */ |
76 ass_font_t* ass_new_font(FT_Library library, void* fontconfig_priv, ass_font_desc_t* desc) | 59 ass_font_t* ass_new_font(FT_Library library, void* fontconfig_priv, ass_font_desc_t* desc) |
77 { | 60 { |
78 FT_Error error; | |
79 int i; | 61 int i; |
80 char* path; | |
81 int index; | |
82 ass_font_t* item; | 62 ass_font_t* item; |
83 FT_Face face; | 63 int error; |
84 | 64 |
85 for (i=0; i<font_cache_size; ++i) | 65 for (i=0; i<font_cache_size; ++i) |
86 if (font_compare(desc, &(font_cache[i].desc))) | 66 if (font_compare(desc, &(font_cache[i].desc))) |
87 return font_cache + i; | 67 return font_cache + i; |
88 | 68 |
89 if (font_cache_size == MAX_FONT_CACHE_SIZE) { | 69 if (font_cache_size == MAX_FONT_CACHE_SIZE) { |
90 mp_msg(MSGT_ASS, MSGL_FATAL, MSGTR_LIBASS_TooManyFonts); | 70 mp_msg(MSGT_ASS, MSGL_FATAL, MSGTR_LIBASS_TooManyFonts); |
91 return 0; | 71 return 0; |
92 } | 72 } |
93 | 73 |
94 path = fontconfig_select(fontconfig_priv, desc->family, desc->bold, desc->italic, &index); | |
95 | |
96 error = FT_New_Face(library, path, index, &face); | |
97 if (error) { | |
98 if (!no_more_font_messages) | |
99 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); | |
100 no_more_font_messages = 1; | |
101 return 0; | |
102 } | |
103 | |
104 charmap_magic(face); | |
105 | |
106 item = font_cache + font_cache_size; | 74 item = font_cache + font_cache_size; |
107 item->path = strdup(path); | 75 error = ass_font_init(library, fontconfig_priv, item, desc); |
108 item->index = index; | 76 if (error) // FIXME: mp_msg |
109 item->face = face; | 77 return 0; |
110 memcpy(&(item->desc), desc, sizeof(ass_font_desc_t)); | |
111 font_cache_size++; | 78 font_cache_size++; |
79 | |
112 return item; | 80 return item; |
113 } | 81 } |
114 | 82 |
115 void ass_font_cache_init(void) | 83 void ass_font_cache_init(void) |
116 { | 84 { |
121 void ass_font_cache_done(void) | 89 void ass_font_cache_done(void) |
122 { | 90 { |
123 int i; | 91 int i; |
124 for (i = 0; i < font_cache_size; ++i) { | 92 for (i = 0; i < font_cache_size; ++i) { |
125 ass_font_t* item = font_cache + i; | 93 ass_font_t* item = font_cache + i; |
126 if (item->face) FT_Done_Face(item->face); | 94 ass_font_free(item); |
127 if (item->path) free(item->path); | |
128 // FIXME: free desc ? | |
129 } | 95 } |
130 free(font_cache); | 96 free(font_cache); |
131 font_cache_size = 0; | 97 font_cache_size = 0; |
132 } | 98 } |
133 | 99 |