1 | /***************************************************************************** |
2 | * vlc_text_style.h: text_style_t definition and helpers. |
3 | ***************************************************************************** |
4 | * Copyright (C) 1999-2010 VLC authors and VideoLAN |
5 | * $Id: c24d76adcfedf63514255bb31483acb9325df1b1 $ |
6 | * |
7 | * Authors: Derk-Jan Hartman <hartman _AT_ videolan _DOT_ org> |
8 | * basOS G <noxelia 4t gmail , com> |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU Lesser General Public License as published by |
12 | * the Free Software Foundation; either version 2.1 of the License, or |
13 | * (at your option) any later version. |
14 | * |
15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU Lesser General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU Lesser General Public License |
21 | * along with this program; if not, write to the Free Software Foundation, |
22 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
23 | *****************************************************************************/ |
24 | |
25 | #ifndef VLC_TEXT_STYLE_H |
26 | #define VLC_TEXT_STYLE_H 1 |
27 | |
28 | #ifdef __cplusplus |
29 | extern "C" { |
30 | #endif |
31 | |
32 | /** |
33 | * Text style |
34 | * |
35 | * A text style is used to specify the formatting of text. |
36 | * A font renderer can use the supplied information to render the |
37 | * text specified. |
38 | */ |
39 | typedef struct |
40 | { |
41 | /* Family font names */ |
42 | char * psz_fontname; /**< The name of the font */ |
43 | char * psz_monofontname; /**< The name of the mono font */ |
44 | |
45 | uint16_t i_features; /**< Feature flags (means non default) */ |
46 | uint16_t i_style_flags; /**< Formatting style flags */ |
47 | |
48 | /* Font style */ |
49 | float f_font_relsize; /**< The font size in video height % */ |
50 | int i_font_size; /**< The font size in pixels */ |
51 | int i_font_color; /**< The color of the text 0xRRGGBB |
52 | (native endianness) */ |
53 | uint8_t i_font_alpha; /**< The transparency of the text.*/ |
54 | int i_spacing; /**< The spaceing between glyphs in pixels */ |
55 | |
56 | /* Outline */ |
57 | int i_outline_color; /**< The color of the outline 0xRRGGBB */ |
58 | uint8_t i_outline_alpha; /**< The transparency of the outline */ |
59 | int i_outline_width; /**< The width of the outline in pixels */ |
60 | |
61 | /* Shadow */ |
62 | int i_shadow_color; /**< The color of the shadow 0xRRGGBB */ |
63 | uint8_t i_shadow_alpha; /**< The transparency of the shadow. */ |
64 | int i_shadow_width; /**< The width of the shadow in pixels */ |
65 | |
66 | /* Background (and karaoke) */ |
67 | int i_background_color;/**< The color of the background 0xRRGGBB */ |
68 | uint8_t i_background_alpha;/**< The transparency of the background */ |
69 | int i_karaoke_background_color;/**< Background color for karaoke 0xRRGGBB */ |
70 | uint8_t i_karaoke_background_alpha;/**< The transparency of the karaoke bg */ |
71 | |
72 | /* Line breaking */ |
73 | enum |
74 | { |
75 | STYLE_WRAP_DEFAULT = 0, /**< Breaks on whitespace or fallback on char */ |
76 | STYLE_WRAP_CHAR, /**< Breaks at character level only */ |
77 | STYLE_WRAP_NONE, /**< No line breaks (except explicit ones) */ |
78 | } e_wrapinfo; |
79 | } text_style_t; |
80 | |
81 | #define STYLE_ALPHA_OPAQUE 0xFF |
82 | #define STYLE_ALPHA_TRANSPARENT 0x00 |
83 | |
84 | /* Features flags for \ref i_features */ |
85 | #define STYLE_NO_DEFAULTS 0x0 |
86 | #define STYLE_FULLY_SET 0xFFFF |
87 | #define STYLE_HAS_FONT_COLOR (1 << 0) |
88 | #define STYLE_HAS_FONT_ALPHA (1 << 1) |
89 | #define STYLE_HAS_FLAGS (1 << 2) |
90 | #define STYLE_HAS_OUTLINE_COLOR (1 << 3) |
91 | #define STYLE_HAS_OUTLINE_ALPHA (1 << 4) |
92 | #define STYLE_HAS_SHADOW_COLOR (1 << 5) |
93 | #define STYLE_HAS_SHADOW_ALPHA (1 << 6) |
94 | #define STYLE_HAS_BACKGROUND_COLOR (1 << 7) |
95 | #define STYLE_HAS_BACKGROUND_ALPHA (1 << 8) |
96 | #define STYLE_HAS_K_BACKGROUND_COLOR (1 << 9) |
97 | #define STYLE_HAS_K_BACKGROUND_ALPHA (1 << 10) |
98 | #define STYLE_HAS_WRAP_INFO (1 << 11) |
99 | |
100 | /* Style flags for \ref text_style_t */ |
101 | #define STYLE_BOLD (1 << 0) |
102 | #define STYLE_ITALIC (1 << 1) |
103 | #define STYLE_OUTLINE (1 << 2) |
104 | #define STYLE_SHADOW (1 << 3) |
105 | #define STYLE_BACKGROUND (1 << 4) |
106 | #define STYLE_UNDERLINE (1 << 5) |
107 | #define STYLE_STRIKEOUT (1 << 6) |
108 | #define STYLE_HALFWIDTH (1 << 7) |
109 | #define STYLE_MONOSPACED (1 << 8) |
110 | #define STYLE_DOUBLEWIDTH (1 << 9) |
111 | #define STYLE_BLINK_FOREGROUND (1 << 10) |
112 | #define STYLE_BLINK_BACKGROUND (1 << 11) |
113 | |
114 | #define STYLE_DEFAULT_FONT_SIZE 20 |
115 | #define STYLE_DEFAULT_REL_FONT_SIZE 6.25 |
116 | |
117 | |
118 | typedef struct text_segment_t text_segment_t; |
119 | /** |
120 | * Text segment for subtitles |
121 | * |
122 | * This structure is used to store a formatted text, with mixed styles |
123 | * Every segment is comprised of one text and a unique style |
124 | * |
125 | * On style change, a new segment is created with the next part of text |
126 | * and the new style, and chained to the list |
127 | * |
128 | * Create with text_segment_New and clean the chain with |
129 | * text_segment_ChainDelete |
130 | */ |
131 | struct text_segment_t { |
132 | char *psz_text; /**< text string of the segment */ |
133 | text_style_t *style; /**< style applied to this segment */ |
134 | text_segment_t *p_next; /**< next segment */ |
135 | }; |
136 | |
137 | /** |
138 | * Create a default text style |
139 | */ |
140 | VLC_API text_style_t * text_style_New( void ); |
141 | |
142 | /** |
143 | * Create a text style |
144 | * |
145 | * Set feature flags as argument if you want to set style defaults |
146 | */ |
147 | VLC_API text_style_t * text_style_Create( int ); |
148 | |
149 | /** |
150 | * Copy a text style into another |
151 | */ |
152 | VLC_API text_style_t * text_style_Copy( text_style_t *, const text_style_t * ); |
153 | |
154 | /** |
155 | * Duplicate a text style |
156 | */ |
157 | VLC_API text_style_t * text_style_Duplicate( const text_style_t * ); |
158 | |
159 | /** |
160 | * Merge two styles using non default values |
161 | * |
162 | * Set b_override to true if you also want to overwrite non-defaults |
163 | */ |
164 | VLC_API void text_style_Merge( text_style_t *, const text_style_t *, bool b_override ); |
165 | |
166 | /** |
167 | * Delete a text style created by text_style_New or text_style_Duplicate |
168 | */ |
169 | VLC_API void text_style_Delete( text_style_t * ); |
170 | |
171 | /** |
172 | * This function will create a new text segment. |
173 | * |
174 | * You should use text_segment_ChainDelete to destroy it, to clean all |
175 | * the linked segments, or text_segment_Delete to free a specic one |
176 | * |
177 | * This duplicates the string passed as argument |
178 | */ |
179 | VLC_API text_segment_t *text_segment_New( const char * ); |
180 | |
181 | /** |
182 | * This function will create a new text segment and duplicates the style passed as argument |
183 | * |
184 | * You should use text_segment_ChainDelete to destroy it, to clean all |
185 | * the linked segments, or text_segment_Delete to free a specic one |
186 | * |
187 | * This doesn't initialize the text. |
188 | */ |
189 | VLC_API text_segment_t *text_segment_NewInheritStyle( const text_style_t* p_style ); |
190 | |
191 | /** |
192 | * Delete a text segment and its content. |
193 | * |
194 | * This assumes the segment is not part of a chain |
195 | */ |
196 | VLC_API void text_segment_Delete( text_segment_t * ); |
197 | |
198 | /** |
199 | * This function will destroy a list of text segments allocated |
200 | * by text_segment_New. |
201 | * |
202 | * You may pass it NULL. |
203 | */ |
204 | VLC_API void text_segment_ChainDelete( text_segment_t * ); |
205 | |
206 | /** |
207 | * This function will copy a text_segment and its chain into a new one |
208 | * |
209 | * You may give it NULL, but it will return NULL. |
210 | */ |
211 | VLC_API text_segment_t * text_segment_Copy( text_segment_t * ); |
212 | |
213 | static const struct { |
214 | const char *psz_name; |
215 | uint32_t i_value; |
216 | } p_html_colors[] = { |
217 | /* Official html colors */ |
218 | { .psz_name: "Aqua" , .i_value: 0x00FFFF }, |
219 | { .psz_name: "Black" , .i_value: 0x000000 }, |
220 | { .psz_name: "Blue" , .i_value: 0x0000FF }, |
221 | { .psz_name: "Fuchsia" , .i_value: 0xFF00FF }, |
222 | { .psz_name: "Gray" , .i_value: 0x808080 }, |
223 | { .psz_name: "Green" , .i_value: 0x008000 }, |
224 | { .psz_name: "Lime" , .i_value: 0x00FF00 }, |
225 | { .psz_name: "Maroon" , .i_value: 0x800000 }, |
226 | { .psz_name: "Navy" , .i_value: 0x000080 }, |
227 | { .psz_name: "Olive" , .i_value: 0x808000 }, |
228 | { .psz_name: "Purple" , .i_value: 0x800080 }, |
229 | { .psz_name: "Red" , .i_value: 0xFF0000 }, |
230 | { .psz_name: "Silver" , .i_value: 0xC0C0C0 }, |
231 | { .psz_name: "Teal" , .i_value: 0x008080 }, |
232 | { .psz_name: "White" , .i_value: 0xFFFFFF }, |
233 | { .psz_name: "Yellow" , .i_value: 0xFFFF00 }, |
234 | |
235 | /* Common ones */ |
236 | { .psz_name: "AliceBlue" , .i_value: 0xF0F8FF }, |
237 | { .psz_name: "AntiqueWhite" , .i_value: 0xFAEBD7 }, |
238 | { .psz_name: "Aqua" , .i_value: 0x00FFFF }, |
239 | { .psz_name: "Aquamarine" , .i_value: 0x7FFFD4 }, |
240 | { .psz_name: "Azure" , .i_value: 0xF0FFFF }, |
241 | { .psz_name: "Beige" , .i_value: 0xF5F5DC }, |
242 | { .psz_name: "Bisque" , .i_value: 0xFFE4C4 }, |
243 | { .psz_name: "Black" , .i_value: 0x000000 }, |
244 | { .psz_name: "BlanchedAlmond" , .i_value: 0xFFEBCD }, |
245 | { .psz_name: "Blue" , .i_value: 0x0000FF }, |
246 | { .psz_name: "BlueViolet" , .i_value: 0x8A2BE2 }, |
247 | { .psz_name: "Brown" , .i_value: 0xA52A2A }, |
248 | { .psz_name: "BurlyWood" , .i_value: 0xDEB887 }, |
249 | { .psz_name: "CadetBlue" , .i_value: 0x5F9EA0 }, |
250 | { .psz_name: "Chartreuse" , .i_value: 0x7FFF00 }, |
251 | { .psz_name: "Chocolate" , .i_value: 0xD2691E }, |
252 | { .psz_name: "Coral" , .i_value: 0xFF7F50 }, |
253 | { .psz_name: "CornflowerBlue" , .i_value: 0x6495ED }, |
254 | { .psz_name: "Cornsilk" , .i_value: 0xFFF8DC }, |
255 | { .psz_name: "Crimson" , .i_value: 0xDC143C }, |
256 | { .psz_name: "Cyan" , .i_value: 0x00FFFF }, |
257 | { .psz_name: "DarkBlue" , .i_value: 0x00008B }, |
258 | { .psz_name: "DarkCyan" , .i_value: 0x008B8B }, |
259 | { .psz_name: "DarkGoldenRod" , .i_value: 0xB8860B }, |
260 | { .psz_name: "DarkGray" , .i_value: 0xA9A9A9 }, |
261 | { .psz_name: "DarkGrey" , .i_value: 0xA9A9A9 }, |
262 | { .psz_name: "DarkGreen" , .i_value: 0x006400 }, |
263 | { .psz_name: "DarkKhaki" , .i_value: 0xBDB76B }, |
264 | { .psz_name: "DarkMagenta" , .i_value: 0x8B008B }, |
265 | { .psz_name: "DarkOliveGreen" , .i_value: 0x556B2F }, |
266 | { .psz_name: "Darkorange" , .i_value: 0xFF8C00 }, |
267 | { .psz_name: "DarkOrchid" , .i_value: 0x9932CC }, |
268 | { .psz_name: "DarkRed" , .i_value: 0x8B0000 }, |
269 | { .psz_name: "DarkSalmon" , .i_value: 0xE9967A }, |
270 | { .psz_name: "DarkSeaGreen" , .i_value: 0x8FBC8F }, |
271 | { .psz_name: "DarkSlateBlue" , .i_value: 0x483D8B }, |
272 | { .psz_name: "DarkSlateGray" , .i_value: 0x2F4F4F }, |
273 | { .psz_name: "DarkSlateGrey" , .i_value: 0x2F4F4F }, |
274 | { .psz_name: "DarkTurquoise" , .i_value: 0x00CED1 }, |
275 | { .psz_name: "DarkViolet" , .i_value: 0x9400D3 }, |
276 | { .psz_name: "DeepPink" , .i_value: 0xFF1493 }, |
277 | { .psz_name: "DeepSkyBlue" , .i_value: 0x00BFFF }, |
278 | { .psz_name: "DimGray" , .i_value: 0x696969 }, |
279 | { .psz_name: "DimGrey" , .i_value: 0x696969 }, |
280 | { .psz_name: "DodgerBlue" , .i_value: 0x1E90FF }, |
281 | { .psz_name: "FireBrick" , .i_value: 0xB22222 }, |
282 | { .psz_name: "FloralWhite" , .i_value: 0xFFFAF0 }, |
283 | { .psz_name: "ForestGreen" , .i_value: 0x228B22 }, |
284 | { .psz_name: "Fuchsia" , .i_value: 0xFF00FF }, |
285 | { .psz_name: "Gainsboro" , .i_value: 0xDCDCDC }, |
286 | { .psz_name: "GhostWhite" , .i_value: 0xF8F8FF }, |
287 | { .psz_name: "Gold" , .i_value: 0xFFD700 }, |
288 | { .psz_name: "GoldenRod" , .i_value: 0xDAA520 }, |
289 | { .psz_name: "Gray" , .i_value: 0x808080 }, |
290 | { .psz_name: "Grey" , .i_value: 0x808080 }, |
291 | { .psz_name: "Green" , .i_value: 0x008000 }, |
292 | { .psz_name: "GreenYellow" , .i_value: 0xADFF2F }, |
293 | { .psz_name: "HoneyDew" , .i_value: 0xF0FFF0 }, |
294 | { .psz_name: "HotPink" , .i_value: 0xFF69B4 }, |
295 | { .psz_name: "IndianRed" , .i_value: 0xCD5C5C }, |
296 | { .psz_name: "Indigo" , .i_value: 0x4B0082 }, |
297 | { .psz_name: "Ivory" , .i_value: 0xFFFFF0 }, |
298 | { .psz_name: "Khaki" , .i_value: 0xF0E68C }, |
299 | { .psz_name: "Lavender" , .i_value: 0xE6E6FA }, |
300 | { .psz_name: "LavenderBlush" , .i_value: 0xFFF0F5 }, |
301 | { .psz_name: "LawnGreen" , .i_value: 0x7CFC00 }, |
302 | { .psz_name: "LemonChiffon" , .i_value: 0xFFFACD }, |
303 | { .psz_name: "LightBlue" , .i_value: 0xADD8E6 }, |
304 | { .psz_name: "LightCoral" , .i_value: 0xF08080 }, |
305 | { .psz_name: "LightCyan" , .i_value: 0xE0FFFF }, |
306 | { .psz_name: "LightGoldenRodYellow" , .i_value: 0xFAFAD2 }, |
307 | { .psz_name: "LightGray" , .i_value: 0xD3D3D3 }, |
308 | { .psz_name: "LightGrey" , .i_value: 0xD3D3D3 }, |
309 | { .psz_name: "LightGreen" , .i_value: 0x90EE90 }, |
310 | { .psz_name: "LightPink" , .i_value: 0xFFB6C1 }, |
311 | { .psz_name: "LightSalmon" , .i_value: 0xFFA07A }, |
312 | { .psz_name: "LightSeaGreen" , .i_value: 0x20B2AA }, |
313 | { .psz_name: "LightSkyBlue" , .i_value: 0x87CEFA }, |
314 | { .psz_name: "LightSlateGray" , .i_value: 0x778899 }, |
315 | { .psz_name: "LightSlateGrey" , .i_value: 0x778899 }, |
316 | { .psz_name: "LightSteelBlue" , .i_value: 0xB0C4DE }, |
317 | { .psz_name: "LightYellow" , .i_value: 0xFFFFE0 }, |
318 | { .psz_name: "Lime" , .i_value: 0x00FF00 }, |
319 | { .psz_name: "LimeGreen" , .i_value: 0x32CD32 }, |
320 | { .psz_name: "Linen" , .i_value: 0xFAF0E6 }, |
321 | { .psz_name: "Magenta" , .i_value: 0xFF00FF }, |
322 | { .psz_name: "Maroon" , .i_value: 0x800000 }, |
323 | { .psz_name: "MediumAquaMarine" , .i_value: 0x66CDAA }, |
324 | { .psz_name: "MediumBlue" , .i_value: 0x0000CD }, |
325 | { .psz_name: "MediumOrchid" , .i_value: 0xBA55D3 }, |
326 | { .psz_name: "MediumPurple" , .i_value: 0x9370D8 }, |
327 | { .psz_name: "MediumSeaGreen" , .i_value: 0x3CB371 }, |
328 | { .psz_name: "MediumSlateBlue" , .i_value: 0x7B68EE }, |
329 | { .psz_name: "MediumSpringGreen" , .i_value: 0x00FA9A }, |
330 | { .psz_name: "MediumTurquoise" , .i_value: 0x48D1CC }, |
331 | { .psz_name: "MediumVioletRed" , .i_value: 0xC71585 }, |
332 | { .psz_name: "MidnightBlue" , .i_value: 0x191970 }, |
333 | { .psz_name: "MintCream" , .i_value: 0xF5FFFA }, |
334 | { .psz_name: "MistyRose" , .i_value: 0xFFE4E1 }, |
335 | { .psz_name: "Moccasin" , .i_value: 0xFFE4B5 }, |
336 | { .psz_name: "NavajoWhite" , .i_value: 0xFFDEAD }, |
337 | { .psz_name: "Navy" , .i_value: 0x000080 }, |
338 | { .psz_name: "OldLace" , .i_value: 0xFDF5E6 }, |
339 | { .psz_name: "Olive" , .i_value: 0x808000 }, |
340 | { .psz_name: "OliveDrab" , .i_value: 0x6B8E23 }, |
341 | { .psz_name: "Orange" , .i_value: 0xFFA500 }, |
342 | { .psz_name: "OrangeRed" , .i_value: 0xFF4500 }, |
343 | { .psz_name: "Orchid" , .i_value: 0xDA70D6 }, |
344 | { .psz_name: "PaleGoldenRod" , .i_value: 0xEEE8AA }, |
345 | { .psz_name: "PaleGreen" , .i_value: 0x98FB98 }, |
346 | { .psz_name: "PaleTurquoise" , .i_value: 0xAFEEEE }, |
347 | { .psz_name: "PaleVioletRed" , .i_value: 0xD87093 }, |
348 | { .psz_name: "PapayaWhip" , .i_value: 0xFFEFD5 }, |
349 | { .psz_name: "PeachPuff" , .i_value: 0xFFDAB9 }, |
350 | { .psz_name: "Peru" , .i_value: 0xCD853F }, |
351 | { .psz_name: "Pink" , .i_value: 0xFFC0CB }, |
352 | { .psz_name: "Plum" , .i_value: 0xDDA0DD }, |
353 | { .psz_name: "PowderBlue" , .i_value: 0xB0E0E6 }, |
354 | { .psz_name: "Purple" , .i_value: 0x800080 }, |
355 | { .psz_name: "RebeccaPurple" , .i_value: 0x663399 }, |
356 | { .psz_name: "Red" , .i_value: 0xFF0000 }, |
357 | { .psz_name: "RosyBrown" , .i_value: 0xBC8F8F }, |
358 | { .psz_name: "RoyalBlue" , .i_value: 0x4169E1 }, |
359 | { .psz_name: "SaddleBrown" , .i_value: 0x8B4513 }, |
360 | { .psz_name: "Salmon" , .i_value: 0xFA8072 }, |
361 | { .psz_name: "SandyBrown" , .i_value: 0xF4A460 }, |
362 | { .psz_name: "SeaGreen" , .i_value: 0x2E8B57 }, |
363 | { .psz_name: "SeaShell" , .i_value: 0xFFF5EE }, |
364 | { .psz_name: "Sienna" , .i_value: 0xA0522D }, |
365 | { .psz_name: "Silver" , .i_value: 0xC0C0C0 }, |
366 | { .psz_name: "SkyBlue" , .i_value: 0x87CEEB }, |
367 | { .psz_name: "SlateBlue" , .i_value: 0x6A5ACD }, |
368 | { .psz_name: "SlateGray" , .i_value: 0x708090 }, |
369 | { .psz_name: "SlateGrey" , .i_value: 0x708090 }, |
370 | { .psz_name: "Snow" , .i_value: 0xFFFAFA }, |
371 | { .psz_name: "SpringGreen" , .i_value: 0x00FF7F }, |
372 | { .psz_name: "SteelBlue" , .i_value: 0x4682B4 }, |
373 | { .psz_name: "Tan" , .i_value: 0xD2B48C }, |
374 | { .psz_name: "Teal" , .i_value: 0x008080 }, |
375 | { .psz_name: "Thistle" , .i_value: 0xD8BFD8 }, |
376 | { .psz_name: "Tomato" , .i_value: 0xFF6347 }, |
377 | { .psz_name: "Turquoise" , .i_value: 0x40E0D0 }, |
378 | { .psz_name: "Violet" , .i_value: 0xEE82EE }, |
379 | { .psz_name: "Wheat" , .i_value: 0xF5DEB3 }, |
380 | { .psz_name: "White" , .i_value: 0xFFFFFF }, |
381 | { .psz_name: "WhiteSmoke" , .i_value: 0xF5F5F5 }, |
382 | { .psz_name: "Yellow" , .i_value: 0xFFFF00 }, |
383 | { .psz_name: "YellowGreen" , .i_value: 0x9ACD32 }, |
384 | |
385 | { NULL, .i_value: 0 } |
386 | }; |
387 | |
388 | /** |
389 | * Returns an integer representation of an HTML color. |
390 | * |
391 | * @param psz_value An HTML color, which can be either: |
392 | * - A standard HTML color (red, cyan, ...) as defined in p_html_colors |
393 | * - An hexadecimal color, of the form [#][AA]RRGGBB |
394 | * @param ok If non-null, true will be stored in this pointer to signal |
395 | * a successful conversion |
396 | */ |
397 | VLC_API unsigned int vlc_html_color( const char *psz_value, bool* ok ); |
398 | |
399 | #ifdef __cplusplus |
400 | } |
401 | #endif |
402 | |
403 | #endif /* VLC_TEXT_STYLE_H */ |
404 | |
405 | |