annotate libass/ass_library.c @ 35833:dbfedb331095

Keep GUI history untouched upon file select "Cancel". Currently, when "Cancel" is selected in the file select menu, the GUI history can be modified nevertheless. Presuming that "Cancel" shall discard changes, the history should be kept unchanged, too. Patch by Hans-Dieter Kosch, hdkosch kabelbw de.
author ib
date Thu, 28 Feb 2013 11:19:59 +0000
parents 6e7f60f6f9d4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
1 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
3 *
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26724
diff changeset
4 * This file is part of libass.
26723
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
5 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
6 * Permission to use, copy, modify, and distribute this software for any
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
8 * copyright notice and this permission notice appear in all copies.
26723
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
9 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26723
0f892cd714b2 Use standard license header.
diego
parents: 25621
diff changeset
17 */
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
18
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 30200
diff changeset
19 #include "config.h"
ac6e48baa03d Import libass 0.9.11
greg
parents: 30200
diff changeset
20
20477
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>
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
25 #include <stdarg.h>
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
26
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
27 #include "ass.h"
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
28 #include "ass_library.h"
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
29 #include "ass_utils.h"
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
30
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
31 static void ass_msg_handler(int level, const char *fmt, va_list va, void *data)
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
32 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
33 if (level > MSGL_INFO)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
34 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
35 fprintf(stderr, "[ass] ");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
36 vfprintf(stderr, fmt, va);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
37 fprintf(stderr, "\n");
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
38 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
39
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
40 ASS_Library *ass_library_init(void)
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
41 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
42 ASS_Library* lib = calloc(1, sizeof(*lib));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
43 lib->msg_callback = ass_msg_handler;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
44
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
45 return lib;
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
46 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
47
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
48 void ass_library_done(ASS_Library *priv)
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
49 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
50 if (priv) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
51 ass_set_fonts_dir(priv, NULL);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
52 ass_set_style_overrides(priv, NULL);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
53 ass_clear_fonts(priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
54 free(priv);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
55 }
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
56 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
57
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
58 void ass_set_fonts_dir(ASS_Library *priv, const char *fonts_dir)
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
59 {
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 30200
diff changeset
60 free(priv->fonts_dir);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
61
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
62 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
63 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
64
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
65 void ass_set_extract_fonts(ASS_Library *priv, int extract)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
66 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
67 priv->extract_fonts = !!extract;
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
68 }
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
69
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
70 void ass_set_style_overrides(ASS_Library *priv, char **list)
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
71 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
72 char **p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
73 char **q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
74 int cnt;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26738
diff changeset
75
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
76 if (priv->style_overrides) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
77 for (p = priv->style_overrides; *p; ++p)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
78 free(*p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
79 }
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 30200
diff changeset
80 free(priv->style_overrides);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
81 priv->style_overrides = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26738
diff changeset
82
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
83 if (!list)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
84 return;
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
85
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
86 for (p = list, cnt = 0; *p; ++p, ++cnt) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
87 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
88
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
89 priv->style_overrides = malloc((cnt + 1) * sizeof(char *));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
90 for (p = list, q = priv->style_overrides; *p; ++p, ++q)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
91 *q = strdup(*p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
92 priv->style_overrides[cnt] = NULL;
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents:
diff changeset
93 }
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
94
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
95 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
96 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
97 if (!(nelem & 31))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
98 *array = realloc(*array, (nelem + 32) * elsize);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
99 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
100
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
101 void ass_add_font(ASS_Library *priv, char *name, char *data, int size)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
102 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
103 int idx = priv->num_fontdata;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
104 if (!name || !data || !size)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
105 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
106 grow_array((void **) &priv->fontdata, priv->num_fontdata,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
107 sizeof(*priv->fontdata));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
108
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
109 priv->fontdata[idx].name = strdup(name);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
110
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
111 priv->fontdata[idx].data = malloc(size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
112 memcpy(priv->fontdata[idx].data, data, size);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
113
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
114 priv->fontdata[idx].size = size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
115
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
116 priv->num_fontdata++;
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
117 }
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
118
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
119 void ass_clear_fonts(ASS_Library *priv)
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
120 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
121 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
122 for (i = 0; i < priv->num_fontdata; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
123 free(priv->fontdata[i].name);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
124 free(priv->fontdata[i].data);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
125 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
126 free(priv->fontdata);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
127 priv->fontdata = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
128 priv->num_fontdata = 0;
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
129 }
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 20722
diff changeset
130
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
131 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
132 * Register a message callback function with libass. Without setting one,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
133 * a default handler is used which prints everything with MSGL_INFO or
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
134 * higher to the standard output.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
135 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
136 * \param msg_cb the callback function
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
137 * \param data additional data that will be passed to the callback
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
138 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
139 void ass_set_message_cb(ASS_Library *priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
140 void (*msg_cb)(int, const char *, va_list, void *),
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
141 void *data)
25613
f00333e3facf Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents: 21497
diff changeset
142 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
143 if (msg_cb) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
144 priv->msg_callback = msg_cb;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
145 priv->msg_callback_data = data;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
146 }
25613
f00333e3facf Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents: 21497
diff changeset
147 }