consistency cosmetics
[mplayer/greg.git] / libass / ass_library.c
blob107a6eda3f2271b5368137e3cadd06a0120bce55
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>
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.
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.
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
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include "ass.h"
27 #include "ass_library.h"
30 ass_library_t* ass_library_init(void)
32 return calloc(1, sizeof(ass_library_t));
35 void ass_library_done(ass_library_t* priv)
37 if (priv) {
38 ass_set_fonts_dir(priv, NULL);
39 ass_set_style_overrides(priv, NULL);
40 free(priv);
44 void ass_set_fonts_dir(ass_library_t* priv, const char* fonts_dir)
46 if (priv->fonts_dir)
47 free(priv->fonts_dir);
49 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0;
52 void ass_set_extract_fonts(ass_library_t* priv, int extract)
54 priv->extract_fonts = !!extract;
57 void ass_set_style_overrides(ass_library_t* priv, char** list)
59 char** p;
60 char** q;
61 int cnt;
63 if (priv->style_overrides) {
64 for (p = priv->style_overrides; *p; ++p)
65 free(*p);
66 free(priv->style_overrides);
69 if (!list) return;
71 for (p = list, cnt = 0; *p; ++p, ++cnt) {}
73 priv->style_overrides = malloc((cnt + 1) * sizeof(char*));
74 for (p = list, q = priv->style_overrides; *p; ++p, ++q)
75 *q = strdup(*p);
76 priv->style_overrides[cnt] = NULL;
79 static void grow_array(void **array, int nelem, size_t elsize)
81 if (!(nelem & 31))
82 *array = realloc(*array, (nelem + 32) * elsize);
85 void ass_add_font(ass_library_t* priv, char* name, char* data, int size)
87 grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata));
88 priv->fontdata[priv->num_fontdata].name = name;
89 priv->fontdata[priv->num_fontdata].data = data;
90 priv->fontdata[priv->num_fontdata].size = size;
91 priv->num_fontdata ++;