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