Mercurial > mplayer.hg
annotate libass/ass_library.c @ 26218:79ee79393eed
Remove unused MACOSX definition.
author | diego |
---|---|
date | Sat, 15 Mar 2008 11:37:18 +0000 |
parents | a09381e1a325 |
children | 0f892cd714b2 |
rev | line source |
---|---|
20477 | 1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*- |
2 // vim:ts=8:sw=8:noet:ai: | |
3 /* | |
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> | |
5 | |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software | |
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 */ | |
20 | |
21 #include <inttypes.h> | |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 | |
26 #include "ass.h" | |
27 #include "ass_library.h" | |
28 | |
29 | |
30 ass_library_t* ass_library_init(void) | |
31 { | |
32 return calloc(1, sizeof(ass_library_t)); | |
33 } | |
34 | |
35 void ass_library_done(ass_library_t* priv) | |
36 { | |
21497
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
37 if (priv) { |
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
38 ass_set_fonts_dir(priv, NULL); |
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
39 ass_set_style_overrides(priv, NULL); |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
40 ass_clear_fonts(priv); |
21497
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
41 free(priv); |
4a4af5271542
Also free ass_library_t members in ass_library_done
reimar
parents:
21458
diff
changeset
|
42 } |
20477 | 43 } |
44 | |
45 void ass_set_fonts_dir(ass_library_t* priv, const char* fonts_dir) | |
46 { | |
47 if (priv->fonts_dir) | |
48 free(priv->fonts_dir); | |
49 | |
50 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0; | |
51 } | |
52 | |
53 void ass_set_extract_fonts(ass_library_t* priv, int extract) | |
54 { | |
55 priv->extract_fonts = !!extract; | |
56 } | |
57 | |
58 void ass_set_style_overrides(ass_library_t* priv, char** list) | |
59 { | |
60 char** p; | |
61 char** q; | |
62 int cnt; | |
63 | |
64 if (priv->style_overrides) { | |
65 for (p = priv->style_overrides; *p; ++p) | |
66 free(*p); | |
67 free(priv->style_overrides); | |
68 } | |
69 | |
70 if (!list) return; | |
71 | |
72 for (p = list, cnt = 0; *p; ++p, ++cnt) {} | |
73 | |
20722
2edba6772316
Bugfix: when copying ass_force_style_list, ending 0 was left out.
eugeni
parents:
20477
diff
changeset
|
74 priv->style_overrides = malloc((cnt + 1) * sizeof(char*)); |
20477 | 75 for (p = list, q = priv->style_overrides; *p; ++p, ++q) |
76 *q = strdup(*p); | |
20722
2edba6772316
Bugfix: when copying ass_force_style_list, ending 0 was left out.
eugeni
parents:
20477
diff
changeset
|
77 priv->style_overrides[cnt] = NULL; |
20477 | 78 } |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
79 |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
80 static void grow_array(void **array, int nelem, size_t elsize) |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
81 { |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
82 if (!(nelem & 31)) |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
83 *array = realloc(*array, (nelem + 32) * elsize); |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
84 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
85 |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
86 void ass_add_font(ass_library_t* priv, char* name, char* data, int size) |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
87 { |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
88 int idx = priv->num_fontdata; |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
89 if (!name || !data || !size) |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
90 return; |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
91 grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata)); |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
92 |
25616 | 93 priv->fontdata[idx].name = strdup(name); |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
94 |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
95 priv->fontdata[idx].data = malloc(size); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
96 memcpy(priv->fontdata[idx].data, data, size); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
97 |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
98 priv->fontdata[idx].size = size; |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
99 |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
100 priv->num_fontdata ++; |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
101 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
102 |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
103 void ass_clear_fonts(ass_library_t* priv) |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
104 { |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
105 int i; |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
106 for (i = 0; i < priv->num_fontdata; ++i) { |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
107 free(priv->fontdata[i].name); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
108 free(priv->fontdata[i].data); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
109 } |
25621 | 110 free(priv->fontdata); |
111 priv->fontdata = NULL; | |
112 priv->num_fontdata = 0; | |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
113 } |