comparison libass/ass_render_api.c @ 31853:e64df5862cea

Import libass 0.9.10
author greg
date Fri, 06 Aug 2010 21:13:41 +0000
parents
children 88eebbbbd6a0
comparison
equal deleted inserted replaced
31852:4ab8b78352ff 31853:e64df5862cea
1 /*
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
3 * Copyright (C) 2010 Grigori Goronzy <greg@geekmind.org>
4 *
5 * This file is part of libass.
6 *
7 * libass is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * libass is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with libass; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include "config.h"
23 #include "ass_render.h"
24
25 static void ass_reconfigure(ASS_Renderer *priv)
26 {
27 ASS_Settings *settings = &priv->settings;
28
29 priv->render_id++;
30 priv->cache.glyph_cache =
31 ass_glyph_cache_reset(priv->cache.glyph_cache);
32 priv->cache.bitmap_cache =
33 ass_bitmap_cache_reset(priv->cache.bitmap_cache);
34 priv->cache.composite_cache =
35 ass_composite_cache_reset(priv->cache.composite_cache);
36 ass_free_images(priv->prev_images_root);
37 priv->prev_images_root = 0;
38
39 priv->width = settings->frame_width;
40 priv->height = settings->frame_height;
41 priv->orig_width = settings->frame_width - settings->left_margin -
42 settings->right_margin;
43 priv->orig_height = settings->frame_height - settings->top_margin -
44 settings->bottom_margin;
45 priv->orig_width_nocrop =
46 settings->frame_width - FFMAX(settings->left_margin, 0) -
47 FFMAX(settings->right_margin, 0);
48 priv->orig_height_nocrop =
49 settings->frame_height - FFMAX(settings->top_margin, 0) -
50 FFMAX(settings->bottom_margin, 0);
51 }
52
53 void ass_set_frame_size(ASS_Renderer *priv, int w, int h)
54 {
55 if (priv->settings.frame_width != w || priv->settings.frame_height != h) {
56 priv->settings.frame_width = w;
57 priv->settings.frame_height = h;
58 if (priv->settings.aspect == 0.) {
59 priv->settings.aspect = ((double) w) / h;
60 priv->settings.storage_aspect = ((double) w) / h;
61 }
62 ass_reconfigure(priv);
63 }
64 }
65
66 void ass_set_margins(ASS_Renderer *priv, int t, int b, int l, int r)
67 {
68 if (priv->settings.left_margin != l || priv->settings.right_margin != r ||
69 priv->settings.top_margin != t || priv->settings.bottom_margin != b) {
70 priv->settings.left_margin = l;
71 priv->settings.right_margin = r;
72 priv->settings.top_margin = t;
73 priv->settings.bottom_margin = b;
74 ass_reconfigure(priv);
75 }
76 }
77
78 void ass_set_use_margins(ASS_Renderer *priv, int use)
79 {
80 priv->settings.use_margins = use;
81 }
82
83 void ass_set_aspect_ratio(ASS_Renderer *priv, double dar, double sar)
84 {
85 if (priv->settings.aspect != dar || priv->settings.storage_aspect != sar) {
86 priv->settings.aspect = dar;
87 priv->settings.storage_aspect = sar;
88 ass_reconfigure(priv);
89 }
90 }
91
92 void ass_set_font_scale(ASS_Renderer *priv, double font_scale)
93 {
94 if (priv->settings.font_size_coeff != font_scale) {
95 priv->settings.font_size_coeff = font_scale;
96 ass_reconfigure(priv);
97 }
98 }
99
100 void ass_set_hinting(ASS_Renderer *priv, ASS_Hinting ht)
101 {
102 if (priv->settings.hinting != ht) {
103 priv->settings.hinting = ht;
104 ass_reconfigure(priv);
105 }
106 }
107
108 void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing)
109 {
110 priv->settings.line_spacing = line_spacing;
111 }
112
113 void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
114 const char *default_family, int fc, const char *config,
115 int update)
116 {
117 free(priv->settings.default_font);
118 free(priv->settings.default_family);
119 priv->settings.default_font = default_font ? strdup(default_font) : 0;
120 priv->settings.default_family =
121 default_family ? strdup(default_family) : 0;
122
123 if (priv->fontconfig_priv)
124 fontconfig_done(priv->fontconfig_priv);
125 priv->fontconfig_priv =
126 fontconfig_init(priv->library, priv->ftlibrary, default_family,
127 default_font, fc, config, update);
128 }
129
130 int ass_fonts_update(ASS_Renderer *render_priv)
131 {
132 return fontconfig_update(render_priv->fontconfig_priv);
133 }
134
135 void ass_set_cache_limits(ASS_Renderer *render_priv, int glyph_max,
136 int bitmap_max)
137 {
138 render_priv->cache.glyph_max = glyph_max ? glyph_max : GLYPH_CACHE_MAX;
139 render_priv->cache.bitmap_max_size = bitmap_max ? 1048576 * bitmap_max :
140 BITMAP_CACHE_MAX_SIZE;
141 }