annotate libass/ass_library.c @ 24015:b636b5de36f3

Add <application> tag around MEncoder
author reimar
date Wed, 08 Aug 2007 13:13:12 +0000
parents 4a4af5271542
children f00333e3facf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
2 // vim:ts=8:sw=8:noet:ai:
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
3 /*
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
5
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
9 (at your option) any later version.
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
10
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
14 GNU General Public License for more details.
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
15
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
17 along with this program; if not, write to the Free Software
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
19 */
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
20
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
21 #include <inttypes.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
22 #include <stdio.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
23 #include <stdlib.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
24 #include <string.h>
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
25
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
26 #include "ass.h"
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
27 #include "ass_library.h"
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
28
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
29
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
30 ass_library_t* ass_library_init(void)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
31 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
32 return calloc(1, sizeof(ass_library_t));
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
33 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
34
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
35 void ass_library_done(ass_library_t* priv)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
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);
4a4af5271542 Also free ass_library_t members in ass_library_done
reimar
parents: 21458
diff changeset
40 free(priv);
4a4af5271542 Also free ass_library_t members in ass_library_done
reimar
parents: 21458
diff changeset
41 }
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
42 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
43
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
44 void ass_set_fonts_dir(ass_library_t* priv, const char* fonts_dir)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
45 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
46 if (priv->fonts_dir)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
47 free(priv->fonts_dir);
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
48
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
49 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
50 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
51
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
52 void ass_set_extract_fonts(ass_library_t* priv, int extract)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
53 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
54 priv->extract_fonts = !!extract;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
55 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
56
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
57 void ass_set_style_overrides(ass_library_t* priv, char** list)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
58 {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
59 char** p;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
60 char** q;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
61 int cnt;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
62
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
63 if (priv->style_overrides) {
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
64 for (p = priv->style_overrides; *p; ++p)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
65 free(*p);
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
66 free(priv->style_overrides);
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
67 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
68
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
69 if (!list) return;
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
70
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
71 for (p = list, cnt = 0; *p; ++p, ++cnt) {}
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
72
20722
2edba6772316 Bugfix: when copying ass_force_style_list, ending 0 was left out.
eugeni
parents: 20477
diff changeset
73 priv->style_overrides = malloc((cnt + 1) * sizeof(char*));
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
74 for (p = list, q = priv->style_overrides; *p; ++p, ++q)
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
75 *q = strdup(*p);
20722
2edba6772316 Bugfix: when copying ass_force_style_list, ending 0 was left out.
eugeni
parents: 20477
diff changeset
76 priv->style_overrides[cnt] = NULL;
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
77 }
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
78
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
79 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
80 {
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
81 if (!(nelem & 31))
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
82 *array = realloc(*array, (nelem + 32) * elsize);
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
83 }
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 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
86 {
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
87 grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata));
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
88 priv->fontdata[priv->num_fontdata].name = name;
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
89 priv->fontdata[priv->num_fontdata].data = data;
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
90 priv->fontdata[priv->num_fontdata].size = size;
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
91 priv->num_fontdata ++;
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
92 }
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
93