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.
55 0xFF fully transparent */
56 int i_spacing
; /**< The spaceing between glyphs in pixels */
59 int i_outline_color
; /**< The color of the outline 0xRRGGBB */
60 uint8_t i_outline_alpha
; /**< The transparency of the outline.
62 0xFF fully transparent */
63 int i_outline_width
; /**< The width of the outline in pixels */
66 int i_shadow_color
; /**< The color of the shadow 0xRRGGBB */
67 uint8_t i_shadow_alpha
; /**< The transparency of the shadow.
69 0xFF fully transparent */
70 int i_shadow_width
; /**< The width of the shadow in pixels */
72 /* Background (and karaoke) */
73 int i_background_color
;/**< The color of the background 0xRRGGBB */
74 uint8_t i_background_alpha
;/**< The transparency of the background.
76 0xFF fully transparent */
77 int i_karaoke_background_color
;/**< Background color for karaoke 0xRRGGBB */
78 uint8_t i_karaoke_background_alpha
;/**< The transparency of the karaoke bg.
80 0xFF fully transparent */
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)
98 /* Style flags for \ref text_style_t */
99 #define STYLE_BOLD (1 << 0)
100 #define STYLE_ITALIC (1 << 1)
101 #define STYLE_OUTLINE (1 << 2)
102 #define STYLE_SHADOW (1 << 3)
103 #define STYLE_BACKGROUND (1 << 4)
104 #define STYLE_UNDERLINE (1 << 5)
105 #define STYLE_STRIKEOUT (1 << 6)
106 #define STYLE_HALFWIDTH (1 << 7)
107 #define STYLE_MONOSPACED (1 << 8)
109 #define STYLE_DEFAULT_FONT_SIZE 20
110 #define STYLE_DEFAULT_REL_FONT_SIZE 5.0
113 typedef struct text_segment_t text_segment_t
;
115 * Text segment for subtitles
117 * This structure is used to store a formatted text, with mixed styles
118 * Every segment is comprised of one text and a unique style
120 * On style change, a new segment is created with the next part of text
121 * and the new style, and chained to the list
123 * Create with text_segment_New and clean the chain with
124 * text_segment_ChainDelete
126 struct text_segment_t
{
127 char *psz_text
; /**< text string of the segment */
128 text_style_t
*style
; /**< style applied to this segment */
129 text_segment_t
*p_next
; /**< next segment */
133 * Create a default text style
135 VLC_API text_style_t
* text_style_New( void );
138 * Create a text style
140 * Set feature flags as argument if you want to set style defaults
142 VLC_API text_style_t
* text_style_Create( int );
145 * Copy a text style into another
147 VLC_API text_style_t
* text_style_Copy( text_style_t
*, const text_style_t
* );
150 * Duplicate a text style
152 VLC_API text_style_t
* text_style_Duplicate( const text_style_t
* );
155 * Merge two styles using non default values
157 * Set b_override to true if you also want to overwrite non-defaults
159 VLC_API
void text_style_Merge( text_style_t
*, const text_style_t
*, bool b_override
);
162 * Delete a text style created by text_style_New or text_style_Duplicate
164 VLC_API
void text_style_Delete( text_style_t
* );
167 * This function will create a new text segment.
169 * You should use text_segment_ChainDelete to destroy it, to clean all
170 * the linked segments, or text_segment_Delete to free a specic one
172 * This duplicates the string passed as argument
174 VLC_API text_segment_t
*text_segment_New( const char * );
177 * This function will create a new text segment and duplicates the style passed as argument
179 * You should use text_segment_ChainDelete to destroy it, to clean all
180 * the linked segments, or text_segment_Delete to free a specic one
182 * This doesn't initialize the text.
184 VLC_API text_segment_t
*text_segment_NewInheritStyle( const text_style_t
* p_style
);
187 * Delete a text segment and its content.
189 * This assumes the segment is not part of a chain
191 VLC_API
void text_segment_Delete( text_segment_t
* );
194 * This function will destroy a list of text segments allocated
195 * by text_segment_New.
197 * You may pass it NULL.
199 VLC_API
void text_segment_ChainDelete( text_segment_t
* );
202 * This function will copy a text_segment and its chain into a new one
204 * You may give it NULL, but it will return NULL.
206 VLC_API text_segment_t
* text_segment_Copy( text_segment_t
* );
212 #endif /* VLC_TEXT_STYLE_H */