1 /*****************************************************************************
2 * vlc_text_style.h: text_style_t definition and helpers.
3 *****************************************************************************
4 * Copyright (C) 1999-2010 VLC authors and VideoLAN
7 * Authors: Derk-Jan Hartman <hartman _AT_ videolan _DOT_ org>
8 * basOS G <noxelia 4t gmail , com>
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.
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.
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 *****************************************************************************/
25 #ifndef VLC_TEXT_STYLE_H
26 #define VLC_TEXT_STYLE_H 1
35 * A text style is used to specify the formatting of text.
36 * A font renderer can use the supplied information to render the
41 /* Family font names */
42 char * psz_fontname
; /**< The name of the font */
43 char * psz_monofontname
; /**< The name of the mono font */
45 uint16_t i_features
; /**< Feature flags (means non default) */
46 uint16_t i_style_flags
; /**< Formatting style flags */
49 float f_font_relsize
; /**< The font size in % */
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 */
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 */
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 */
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 */
73 #define STYLE_ALPHA_OPAQUE 0xFF
74 #define STYLE_ALPHA_TRANSPARENT 0x00
76 /* Features flags for \ref i_features */
77 #define STYLE_NO_DEFAULTS 0x0
78 #define STYLE_FULLY_SET 0xFFFF
79 #define STYLE_HAS_FONT_COLOR (1 << 0)
80 #define STYLE_HAS_FONT_ALPHA (1 << 1)
81 #define STYLE_HAS_FLAGS (1 << 2)
82 #define STYLE_HAS_OUTLINE_COLOR (1 << 3)
83 #define STYLE_HAS_OUTLINE_ALPHA (1 << 4)
84 #define STYLE_HAS_SHADOW_COLOR (1 << 5)
85 #define STYLE_HAS_SHADOW_ALPHA (1 << 6)
86 #define STYLE_HAS_BACKGROUND_COLOR (1 << 7)
87 #define STYLE_HAS_BACKGROUND_ALPHA (1 << 8)
88 #define STYLE_HAS_K_BACKGROUND_COLOR (1 << 9)
89 #define STYLE_HAS_K_BACKGROUND_ALPHA (1 << 10)
91 /* Style flags for \ref text_style_t */
92 #define STYLE_BOLD (1 << 0)
93 #define STYLE_ITALIC (1 << 1)
94 #define STYLE_OUTLINE (1 << 2)
95 #define STYLE_SHADOW (1 << 3)
96 #define STYLE_BACKGROUND (1 << 4)
97 #define STYLE_UNDERLINE (1 << 5)
98 #define STYLE_STRIKEOUT (1 << 6)
99 #define STYLE_HALFWIDTH (1 << 7)
100 #define STYLE_MONOSPACED (1 << 8)
101 #define STYLE_DOUBLEWIDTH (1 << 9)
103 #define STYLE_DEFAULT_FONT_SIZE 20
104 #define STYLE_DEFAULT_REL_FONT_SIZE 6.25
107 typedef struct text_segment_t text_segment_t
;
109 * Text segment for subtitles
111 * This structure is used to store a formatted text, with mixed styles
112 * Every segment is comprised of one text and a unique style
114 * On style change, a new segment is created with the next part of text
115 * and the new style, and chained to the list
117 * Create with text_segment_New and clean the chain with
118 * text_segment_ChainDelete
120 struct text_segment_t
{
121 char *psz_text
; /**< text string of the segment */
122 text_style_t
*style
; /**< style applied to this segment */
123 text_segment_t
*p_next
; /**< next segment */
127 * Create a default text style
129 VLC_API text_style_t
* text_style_New( void );
132 * Create a text style
134 * Set feature flags as argument if you want to set style defaults
136 VLC_API text_style_t
* text_style_Create( int );
139 * Copy a text style into another
141 VLC_API text_style_t
* text_style_Copy( text_style_t
*, const text_style_t
* );
144 * Duplicate a text style
146 VLC_API text_style_t
* text_style_Duplicate( const text_style_t
* );
149 * Merge two styles using non default values
151 * Set b_override to true if you also want to overwrite non-defaults
153 VLC_API
void text_style_Merge( text_style_t
*, const text_style_t
*, bool b_override
);
156 * Delete a text style created by text_style_New or text_style_Duplicate
158 VLC_API
void text_style_Delete( text_style_t
* );
161 * This function will create a new text segment.
163 * You should use text_segment_ChainDelete to destroy it, to clean all
164 * the linked segments, or text_segment_Delete to free a specic one
166 * This duplicates the string passed as argument
168 VLC_API text_segment_t
*text_segment_New( const char * );
171 * This function will create a new text segment and duplicates the style passed as argument
173 * You should use text_segment_ChainDelete to destroy it, to clean all
174 * the linked segments, or text_segment_Delete to free a specic one
176 * This doesn't initialize the text.
178 VLC_API text_segment_t
*text_segment_NewInheritStyle( const text_style_t
* p_style
);
181 * Delete a text segment and its content.
183 * This assumes the segment is not part of a chain
185 VLC_API
void text_segment_Delete( text_segment_t
* );
188 * This function will destroy a list of text segments allocated
189 * by text_segment_New.
191 * You may pass it NULL.
193 VLC_API
void text_segment_ChainDelete( text_segment_t
* );
196 * This function will copy a text_segment and its chain into a new one
198 * You may give it NULL, but it will return NULL.
200 VLC_API text_segment_t
* text_segment_Copy( text_segment_t
* );
202 static const struct {
203 const char *psz_name
;
205 } p_html_colors
[] = {
206 /* Official html colors */
207 { "Aqua", 0x00FFFF },
208 { "Black", 0x000000 },
209 { "Blue", 0x0000FF },
210 { "Fuchsia", 0xFF00FF },
211 { "Gray", 0x808080 },
212 { "Green", 0x008000 },
213 { "Lime", 0x00FF00 },
214 { "Maroon", 0x800000 },
215 { "Navy", 0x000080 },
216 { "Olive", 0x808000 },
217 { "Purple", 0x800080 },
219 { "Silver", 0xC0C0C0 },
220 { "Teal", 0x008080 },
221 { "White", 0xFFFFFF },
222 { "Yellow", 0xFFFF00 },
225 { "AliceBlue", 0xF0F8FF },
226 { "AntiqueWhite", 0xFAEBD7 },
227 { "Aqua", 0x00FFFF },
228 { "Aquamarine", 0x7FFFD4 },
229 { "Azure", 0xF0FFFF },
230 { "Beige", 0xF5F5DC },
231 { "Bisque", 0xFFE4C4 },
232 { "Black", 0x000000 },
233 { "BlanchedAlmond", 0xFFEBCD },
234 { "Blue", 0x0000FF },
235 { "BlueViolet", 0x8A2BE2 },
236 { "Brown", 0xA52A2A },
237 { "BurlyWood", 0xDEB887 },
238 { "CadetBlue", 0x5F9EA0 },
239 { "Chartreuse", 0x7FFF00 },
240 { "Chocolate", 0xD2691E },
241 { "Coral", 0xFF7F50 },
242 { "CornflowerBlue", 0x6495ED },
243 { "Cornsilk", 0xFFF8DC },
244 { "Crimson", 0xDC143C },
245 { "Cyan", 0x00FFFF },
246 { "DarkBlue", 0x00008B },
247 { "DarkCyan", 0x008B8B },
248 { "DarkGoldenRod", 0xB8860B },
249 { "DarkGray", 0xA9A9A9 },
250 { "DarkGrey", 0xA9A9A9 },
251 { "DarkGreen", 0x006400 },
252 { "DarkKhaki", 0xBDB76B },
253 { "DarkMagenta", 0x8B008B },
254 { "DarkOliveGreen", 0x556B2F },
255 { "Darkorange", 0xFF8C00 },
256 { "DarkOrchid", 0x9932CC },
257 { "DarkRed", 0x8B0000 },
258 { "DarkSalmon", 0xE9967A },
259 { "DarkSeaGreen", 0x8FBC8F },
260 { "DarkSlateBlue", 0x483D8B },
261 { "DarkSlateGray", 0x2F4F4F },
262 { "DarkSlateGrey", 0x2F4F4F },
263 { "DarkTurquoise", 0x00CED1 },
264 { "DarkViolet", 0x9400D3 },
265 { "DeepPink", 0xFF1493 },
266 { "DeepSkyBlue", 0x00BFFF },
267 { "DimGray", 0x696969 },
268 { "DimGrey", 0x696969 },
269 { "DodgerBlue", 0x1E90FF },
270 { "FireBrick", 0xB22222 },
271 { "FloralWhite", 0xFFFAF0 },
272 { "ForestGreen", 0x228B22 },
273 { "Fuchsia", 0xFF00FF },
274 { "Gainsboro", 0xDCDCDC },
275 { "GhostWhite", 0xF8F8FF },
276 { "Gold", 0xFFD700 },
277 { "GoldenRod", 0xDAA520 },
278 { "Gray", 0x808080 },
279 { "Grey", 0x808080 },
280 { "Green", 0x008000 },
281 { "GreenYellow", 0xADFF2F },
282 { "HoneyDew", 0xF0FFF0 },
283 { "HotPink", 0xFF69B4 },
284 { "IndianRed", 0xCD5C5C },
285 { "Indigo", 0x4B0082 },
286 { "Ivory", 0xFFFFF0 },
287 { "Khaki", 0xF0E68C },
288 { "Lavender", 0xE6E6FA },
289 { "LavenderBlush", 0xFFF0F5 },
290 { "LawnGreen", 0x7CFC00 },
291 { "LemonChiffon", 0xFFFACD },
292 { "LightBlue", 0xADD8E6 },
293 { "LightCoral", 0xF08080 },
294 { "LightCyan", 0xE0FFFF },
295 { "LightGoldenRodYellow", 0xFAFAD2 },
296 { "LightGray", 0xD3D3D3 },
297 { "LightGrey", 0xD3D3D3 },
298 { "LightGreen", 0x90EE90 },
299 { "LightPink", 0xFFB6C1 },
300 { "LightSalmon", 0xFFA07A },
301 { "LightSeaGreen", 0x20B2AA },
302 { "LightSkyBlue", 0x87CEFA },
303 { "LightSlateGray", 0x778899 },
304 { "LightSlateGrey", 0x778899 },
305 { "LightSteelBlue", 0xB0C4DE },
306 { "LightYellow", 0xFFFFE0 },
307 { "Lime", 0x00FF00 },
308 { "LimeGreen", 0x32CD32 },
309 { "Linen", 0xFAF0E6 },
310 { "Magenta", 0xFF00FF },
311 { "Maroon", 0x800000 },
312 { "MediumAquaMarine", 0x66CDAA },
313 { "MediumBlue", 0x0000CD },
314 { "MediumOrchid", 0xBA55D3 },
315 { "MediumPurple", 0x9370D8 },
316 { "MediumSeaGreen", 0x3CB371 },
317 { "MediumSlateBlue", 0x7B68EE },
318 { "MediumSpringGreen", 0x00FA9A },
319 { "MediumTurquoise", 0x48D1CC },
320 { "MediumVioletRed", 0xC71585 },
321 { "MidnightBlue", 0x191970 },
322 { "MintCream", 0xF5FFFA },
323 { "MistyRose", 0xFFE4E1 },
324 { "Moccasin", 0xFFE4B5 },
325 { "NavajoWhite", 0xFFDEAD },
326 { "Navy", 0x000080 },
327 { "OldLace", 0xFDF5E6 },
328 { "Olive", 0x808000 },
329 { "OliveDrab", 0x6B8E23 },
330 { "Orange", 0xFFA500 },
331 { "OrangeRed", 0xFF4500 },
332 { "Orchid", 0xDA70D6 },
333 { "PaleGoldenRod", 0xEEE8AA },
334 { "PaleGreen", 0x98FB98 },
335 { "PaleTurquoise", 0xAFEEEE },
336 { "PaleVioletRed", 0xD87093 },
337 { "PapayaWhip", 0xFFEFD5 },
338 { "PeachPuff", 0xFFDAB9 },
339 { "Peru", 0xCD853F },
340 { "Pink", 0xFFC0CB },
341 { "Plum", 0xDDA0DD },
342 { "PowderBlue", 0xB0E0E6 },
343 { "Purple", 0x800080 },
344 { "RebeccaPurple", 0x663399 },
346 { "RosyBrown", 0xBC8F8F },
347 { "RoyalBlue", 0x4169E1 },
348 { "SaddleBrown", 0x8B4513 },
349 { "Salmon", 0xFA8072 },
350 { "SandyBrown", 0xF4A460 },
351 { "SeaGreen", 0x2E8B57 },
352 { "SeaShell", 0xFFF5EE },
353 { "Sienna", 0xA0522D },
354 { "Silver", 0xC0C0C0 },
355 { "SkyBlue", 0x87CEEB },
356 { "SlateBlue", 0x6A5ACD },
357 { "SlateGray", 0x708090 },
358 { "SlateGrey", 0x708090 },
359 { "Snow", 0xFFFAFA },
360 { "SpringGreen", 0x00FF7F },
361 { "SteelBlue", 0x4682B4 },
363 { "Teal", 0x008080 },
364 { "Thistle", 0xD8BFD8 },
365 { "Tomato", 0xFF6347 },
366 { "Turquoise", 0x40E0D0 },
367 { "Violet", 0xEE82EE },
368 { "Wheat", 0xF5DEB3 },
369 { "White", 0xFFFFFF },
370 { "WhiteSmoke", 0xF5F5F5 },
371 { "Yellow", 0xFFFF00 },
372 { "YellowGreen", 0x9ACD32 },
378 * Returns an integer representation of an HTML color.
380 * @param psz_value An HTML color, which can be either:
381 * - A standard HTML color (red, cyan, ...) as defined in p_html_colors
382 * - An hexadecimal color, of the form [#][AA]RRGGBB
383 * @param ok If non-null, true will be stored in this pointer to signal
384 * a successful conversion
386 VLC_API
unsigned int vlc_html_color( const char *psz_value
, bool* ok
);
392 #endif /* VLC_TEXT_STYLE_H */