lib: media: fix libvlc_media_duplicate() behavior
[vlc.git] / include / vlc_text_style.h
blob709f5f734e79b6d4659e9f4c2ee0a94bf6d68604
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 */
66 int i_background_color;/**< The color of the background 0xRRGGBB */
67 uint8_t i_background_alpha;/**< The transparency of the background */
69 /* Line breaking */
70 enum
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;
78 #define STYLE_ALPHA_OPAQUE 0xFF
79 #define STYLE_ALPHA_TRANSPARENT 0x00
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)
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
113 typedef struct text_segment_t text_segment_t;
114 typedef struct text_segment_ruby_t text_segment_ruby_t;
117 * Text segment ruby for subtitles
118 * Each ruby has an anchor to the segment char.
120 struct text_segment_ruby_t
122 char *psz_base;
123 char *psz_rt;
124 text_segment_ruby_t *p_next;
128 * Text segment for subtitles
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
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
136 * Create with text_segment_New and clean the chain with
137 * text_segment_ChainDelete
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 */
147 * Create a default text style
149 VLC_API text_style_t * text_style_New( void );
152 * Create a text style
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).
160 VLC_API text_style_t * text_style_Create( int );
163 * Copy a text style into another
165 VLC_API text_style_t * text_style_Copy( text_style_t *, const text_style_t * );
168 * Duplicate a text style
170 VLC_API text_style_t * text_style_Duplicate( const text_style_t * );
173 * Merge two styles using non default values
175 * Set b_override to true if you also want to overwrite non-defaults
177 VLC_API void text_style_Merge( text_style_t *, const text_style_t *, bool b_override );
180 * Delete a text style created by text_style_New or text_style_Duplicate
182 VLC_API void text_style_Delete( text_style_t * );
185 * This function will create a new text segment.
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
190 * This duplicates the string passed as argument
192 VLC_API text_segment_t *text_segment_New( const char * );
195 * This function will create a new text segment and duplicates the style passed as argument
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
200 * This doesn't initialize the text.
202 VLC_API text_segment_t *text_segment_NewInheritStyle( const text_style_t* p_style );
205 * Delete a text segment and its content.
207 * This assumes the segment is not part of a chain
209 VLC_API void text_segment_Delete( text_segment_t * );
212 * This function will destroy a list of text segments allocated
213 * by text_segment_New.
215 * You may pass it NULL.
217 VLC_API void text_segment_ChainDelete( text_segment_t * );
220 * This function will copy a text_segment and its chain into a new one
222 * You may give it NULL, but it will return NULL.
224 VLC_API text_segment_t * text_segment_Copy( text_segment_t * );
227 * This function will create a ruby section for a text_segment
230 VLC_API text_segment_ruby_t *text_segment_ruby_New( const char *psz_base,
231 const char *psz_rt );
234 * Deletes a ruby sections chain
236 VLC_API void text_segment_ruby_ChainDelete( text_segment_ruby_t *p_ruby );
239 * This function creates a text segment from a ruby section,
240 * and creates fallback string.
242 VLC_API text_segment_t *text_segment_FromRuby( text_segment_ruby_t *p_ruby );
245 * Returns an integer representation of an HTML color.
247 * @param psz_value An HTML color, which can be either:
248 * - A standard HTML color (red, cyan, ...) as defined in p_html_colors
249 * - An hexadecimal color, of the form [#][AA]RRGGBB
250 * @param ok If non-null, true will be stored in this pointer to signal
251 * a successful conversion
253 VLC_API unsigned int vlc_html_color( const char *psz_value, bool* ok );
255 #ifdef __cplusplus
257 #endif
259 #endif /* VLC_TEXT_STYLE_H */