1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
2 // vim:ts=8:sw=8:noet:ai:
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
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
)
38 ass_set_fonts_dir(priv
, NULL
);
39 ass_set_style_overrides(priv
, NULL
);
44 void ass_set_fonts_dir(ass_library_t
* priv
, const char* 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
)
63 if (priv
->style_overrides
) {
64 for (p
= priv
->style_overrides
; *p
; ++p
)
66 free(priv
->style_overrides
);
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
)
76 priv
->style_overrides
[cnt
] = NULL
;
79 static void grow_array(void **array
, int nelem
, size_t elsize
)
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
++;