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