annotate libass/ass_render_api.c @ 36984:3f3a415d605b

Move most of TranslateFilename() back to the renderer files. Although it would be nice to share the code (which was the reason for r34263), most of it really doesn't belong to string.c.
author ib
date Thu, 27 Mar 2014 01:49:01 +0000
parents c3aaaf17c721
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
1 /*
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
3 * Copyright (C) 2010 Grigori Goronzy <greg@geekmind.org>
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
4 *
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
5 * This file is part of libass.
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
6 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
7 * Permission to use, copy, modify, and distribute this software for any
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
8 * purpose with or without fee is hereby granted, provided that the above
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
9 * copyright notice and this permission notice appear in all copies.
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
10 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
18 */
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
19
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
20 #include "config.h"
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
21 #include "ass_render.h"
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
22
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
23 static void ass_reconfigure(ASS_Renderer *priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
24 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
25 ASS_Settings *settings = &priv->settings;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
26
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
27 priv->render_id++;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
28 ass_cache_empty(priv->cache.outline_cache, 0);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
29 ass_cache_empty(priv->cache.bitmap_cache, 0);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
30 ass_cache_empty(priv->cache.composite_cache, 0);
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
31 ass_free_images(priv->prev_images_root);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
32 priv->prev_images_root = 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
33
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
34 priv->width = settings->frame_width;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
35 priv->height = settings->frame_height;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
36 priv->orig_width = settings->frame_width - settings->left_margin -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
37 settings->right_margin;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
38 priv->orig_height = settings->frame_height - settings->top_margin -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
39 settings->bottom_margin;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
40 priv->orig_width_nocrop =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
41 settings->frame_width - FFMAX(settings->left_margin, 0) -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
42 FFMAX(settings->right_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
43 priv->orig_height_nocrop =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
44 settings->frame_height - FFMAX(settings->top_margin, 0) -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
45 FFMAX(settings->bottom_margin, 0);
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
46 if (settings->storage_height) {
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
47 priv->storage_width = settings->storage_width;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
48 priv->storage_height = settings->storage_height;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
49 } else {
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
50 priv->storage_width = priv->orig_width;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
51 priv->storage_height = priv->orig_height;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
52 }
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
53 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
54
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
55 void ass_set_frame_size(ASS_Renderer *priv, int w, int h)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
56 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
57 if (priv->settings.frame_width != w || priv->settings.frame_height != h) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
58 priv->settings.frame_width = w;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
59 priv->settings.frame_height = h;
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
60 ass_reconfigure(priv);
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
61 }
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
62 }
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
63
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
64 void ass_set_storage_size(ASS_Renderer *priv, int w, int h)
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
65 {
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
66 if (priv->settings.storage_width != w ||
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
67 priv->settings.storage_height != h) {
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
68 priv->settings.storage_width = w;
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
69 priv->settings.storage_height = h;
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
70 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
71 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
72 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
73
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
74 void ass_set_shaper(ASS_Renderer *priv, ASS_ShapingLevel level)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
75 {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
76 #ifdef CONFIG_HARFBUZZ
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
77 // select the complex shaper for illegal values
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
78 if (level == ASS_SHAPING_SIMPLE || level == ASS_SHAPING_COMPLEX)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
79 priv->settings.shaper = level;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
80 else
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
81 priv->settings.shaper = ASS_SHAPING_COMPLEX;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
82 #endif
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
83 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
84
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
85 void ass_set_margins(ASS_Renderer *priv, int t, int b, int l, int r)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
86 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
87 if (priv->settings.left_margin != l || priv->settings.right_margin != r ||
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
88 priv->settings.top_margin != t || priv->settings.bottom_margin != b) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
89 priv->settings.left_margin = l;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
90 priv->settings.right_margin = r;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
91 priv->settings.top_margin = t;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
92 priv->settings.bottom_margin = b;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
93 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
94 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
95 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
96
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
97 void ass_set_use_margins(ASS_Renderer *priv, int use)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
98 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
99 priv->settings.use_margins = use;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
100 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
101
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
102 void ass_set_aspect_ratio(ASS_Renderer *priv, double dar, double sar)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
103 {
36363
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
104 ass_set_pixel_aspect(priv, dar / sar);
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
105 }
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
106
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
107 void ass_set_pixel_aspect(ASS_Renderer *priv, double par)
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
108 {
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
109 if (priv->settings.par != par) {
c3aaaf17c721 Update libass to latest git version.
reimar
parents: 35262
diff changeset
110 priv->settings.par = par;
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
111 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
112 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
113 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
114
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
115 void ass_set_font_scale(ASS_Renderer *priv, double font_scale)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
116 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
117 if (priv->settings.font_size_coeff != font_scale) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
118 priv->settings.font_size_coeff = font_scale;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
119 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
120 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
121 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
122
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
123 void ass_set_hinting(ASS_Renderer *priv, ASS_Hinting ht)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
124 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
125 if (priv->settings.hinting != ht) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
126 priv->settings.hinting = ht;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
127 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
128 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
129 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
130
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
131 void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
132 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
133 priv->settings.line_spacing = line_spacing;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
134 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
135
35262
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
136 void ass_set_line_position(ASS_Renderer *priv, double line_position)
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
137 {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
138 if (priv->settings.line_position != line_position) {
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
139 priv->settings.line_position = line_position;
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
140 ass_reconfigure(priv);
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
141 }
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
142 }
49fc594fda43 Updated libass to 0.10.1
SubJunk
parents: 34295
diff changeset
143
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
144 void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
145 const char *default_family, int fc, const char *config,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
146 int update)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
147 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
148 free(priv->settings.default_font);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
149 free(priv->settings.default_family);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
150 priv->settings.default_font = default_font ? strdup(default_font) : 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
151 priv->settings.default_family =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
152 default_family ? strdup(default_family) : 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
153
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
154 if (priv->fontconfig_priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
155 fontconfig_done(priv->fontconfig_priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
156 priv->fontconfig_priv =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
157 fontconfig_init(priv->library, priv->ftlibrary, default_family,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
158 default_font, fc, config, update);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
159 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
160
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
161 int ass_fonts_update(ASS_Renderer *render_priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
162 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
163 return fontconfig_update(render_priv->fontconfig_priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
164 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
165
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
166 void ass_set_cache_limits(ASS_Renderer *render_priv, int glyph_max,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
167 int bitmap_max)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
168 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
169 render_priv->cache.glyph_max = glyph_max ? glyph_max : GLYPH_CACHE_MAX;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
170 render_priv->cache.bitmap_max_size = bitmap_max ? 1048576 * bitmap_max :
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
171 BITMAP_CACHE_MAX_SIZE;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
172 }