[vlc-commits] text_style: add text_style_Merge()

Francois Cartegnie git at videolan.org
Thu Aug 13 15:24:59 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Aug  9 00:13:50 2015 +0200| [e7e451fbc8d217a84eea7c0581e6982ba6a8e099] | committer: Francois Cartegnie

text_style: add text_style_Merge()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e7e451fbc8d217a84eea7c0581e6982ba6a8e099
---

 include/vlc_text_style.h |   22 +++++++++++++++++++++
 src/libvlccore.sym       |    1 +
 src/misc/text_style.c    |   48 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)

diff --git a/include/vlc_text_style.h b/include/vlc_text_style.h
index e0d53db..27c3abe 100644
--- a/include/vlc_text_style.h
+++ b/include/vlc_text_style.h
@@ -145,6 +145,28 @@ VLC_API text_style_t * text_style_Copy( text_style_t *, const text_style_t * );
 VLC_API text_style_t * text_style_Duplicate( const text_style_t * );
 
 /**
+ * Merge two styles using non default values
+ *
+ * Set b_override to true if you also want to overwrite non-defaults
+ */
+VLC_API void text_style_Merge( text_style_t *, const text_style_t *, bool b_override );
+
+inline void text_style_Reset( text_style_t *p_style )
+{
+    free(p_style->psz_fontname);
+    p_style->psz_fontname = NULL;
+    free(p_style->psz_monofontname);
+    p_style->psz_monofontname = NULL;
+    p_style->i_features = STYLE_NO_DEFAULTS;
+    p_style->i_style_flags = 0;
+    p_style->f_font_relsize = 0.0;
+    p_style->i_font_size = 0;
+    p_style->i_outline_width = 0;
+    p_style->i_shadow_width = 0;
+    p_style->i_spacing = -0;
+}
+
+/**
  * Delete a text style created by text_style_New or text_style_Duplicate
  */
 VLC_API void text_style_Delete( text_style_t * );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index d62d9ac..ed2136e 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -673,6 +673,7 @@ xml_Create
 text_style_Copy
 text_style_Delete
 text_style_Duplicate
+text_style_Merge
 text_style_New
 xml_Delete
 xml_ReaderCreate
diff --git a/src/misc/text_style.c b/src/misc/text_style.c
index 793c0a9..2a9696a 100644
--- a/src/misc/text_style.c
+++ b/src/misc/text_style.c
@@ -76,6 +76,54 @@ text_style_t *text_style_Copy( text_style_t *p_dst, const text_style_t *p_src )
     return p_dst;
 }
 
+#define MERGE(var, fflag) \
+    if( (p_src->i_features & fflag) && (b_override || !(p_dst->i_features & fflag)) )\
+        p_dst->var = p_src->var
+
+#define MERGE_SIZE(var) \
+    if( p_src->var > 0 && (b_override || p_dst->var <= 0) )\
+        p_dst->var = p_src->var
+
+void text_style_Merge( text_style_t *p_dst, const text_style_t *p_src, bool b_override )
+{
+    if( p_src->psz_fontname && (!p_dst->psz_fontname || b_override) )
+    {
+        free( p_dst->psz_fontname );
+        p_dst->psz_fontname = strdup( p_src->psz_fontname );
+    }
+
+    if( p_src->psz_monofontname && (!p_dst->psz_monofontname || b_override) )
+    {
+        free( p_dst->psz_monofontname );
+        p_dst->psz_monofontname = strdup( p_src->psz_monofontname );
+    }
+
+    if( p_src->i_features != STYLE_NO_DEFAULTS )
+    {
+        MERGE(i_font_color,         STYLE_HAS_FONT_COLOR);
+        MERGE(i_font_alpha,         STYLE_HAS_FONT_ALPHA);
+        MERGE(i_outline_color,      STYLE_HAS_OUTLINE_COLOR);
+        MERGE(i_outline_alpha,      STYLE_HAS_OUTLINE_ALPHA);
+        MERGE(i_shadow_color,       STYLE_HAS_SHADOW_COLOR);
+        MERGE(i_shadow_alpha,       STYLE_HAS_SHADOW_ALPHA);
+        MERGE(i_background_color,   STYLE_HAS_BACKGROUND_COLOR);
+        MERGE(i_background_alpha,   STYLE_HAS_BACKGROUND_ALPHA);
+        MERGE(i_karaoke_background_color, STYLE_HAS_K_BACKGROUND_COLOR);
+        MERGE(i_karaoke_background_alpha, STYLE_HAS_K_BACKGROUND_ALPHA);
+        p_dst->i_features |= p_src->i_features;
+        p_dst->i_style_flags |= p_src->i_style_flags;
+    }
+
+    MERGE_SIZE(f_font_relsize);
+    MERGE_SIZE(i_font_size);
+    MERGE_SIZE(i_outline_width);
+    MERGE_SIZE(i_shadow_width);
+    MERGE_SIZE(i_spacing);
+}
+
+#undef MERGE
+#undef MERGE_SIZE
+
 text_style_t *text_style_Duplicate( const text_style_t *p_src )
 {
     if( !p_src )



More information about the vlc-commits mailing list