[vlc-commits] quartztext: add support for HTML color names within color tags

Felix Paul Kühne git at videolan.org
Fri Dec 28 11:15:49 CET 2012


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Thu Dec 27 17:44:22 2012 +0100| [bc4b7944679587878c1c17b062aa92a76a0905aa] | committer: Felix Paul Kühne

quartztext: add support for HTML color names within color tags

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

 modules/text_renderer/quartztext.c |   24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/modules/text_renderer/quartztext.c b/modules/text_renderer/quartztext.c
index ebcf93d..4f6a204 100644
--- a/modules/text_renderer/quartztext.c
+++ b/modules/text_renderer/quartztext.c
@@ -106,6 +106,11 @@ static const int pi_color_values[] = {
   0x00FF0000, 0x00FF00FF, 0x00FFFF00, 0x00808000, 0x00008000, 0x00008080,
   0x0000FF00, 0x00800080, 0x00000080, 0x000000FF, 0x0000FFFF };
 
+static const char *const ppsz_color_names[] = {
+    "black", "gray", "silver", "white", "maroon",
+    "red", "fuchsia", "yellow", "olive", "green",
+    "teal", "lime", "purple", "navy", "blue", "aqua" };
+
 static const char *const ppsz_color_descriptions[] = {
   N_("Black"), N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"),
   N_("Red"), N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"), N_("Teal"),
@@ -310,6 +315,7 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out,
     bool          b_bold, b_uline, b_italic;
     vlc_value_t val;
     b_bold = b_uline = b_italic = FALSE;
+    VLC_UNUSED(p_chroma_list);
 
     p_sys->i_font_size    = GetFontSize(p_filter);
 
@@ -492,9 +498,20 @@ static int HandleFontAttributes(xml_reader_t *p_xml_reader,
             }
             else
                 i_font_size = atoi(value);
-        } else if (!strcasecmp("color", attr)  && (value[0] == '#')) {
-            i_font_color = strtol(value + 1, NULL, 16);
-            i_font_color &= 0x00ffffff;
+        } else if (!strcasecmp("color", attr)) {
+            if (value[0] == '#') {
+                i_font_color = strtol(value + 1, NULL, 16);
+                i_font_color &= 0x00ffffff;
+            } else {
+                /* color detection fallback */
+                unsigned int count = sizeof(ppsz_color_names);
+                for (unsigned x = 0; x < count; x++) {
+                    if (!strcmp(value, ppsz_color_names[x])) {
+                        i_font_color = pi_color_values[x];
+                        break;
+                    }
+                }
+            }
         } else if (!strcasecmp("alpha", attr) && (value[0] == '#')) {
             i_font_alpha = strtol(value + 1, NULL, 16);
             i_font_alpha &= 0xff;
@@ -740,6 +757,7 @@ static int RenderHtml(filter_t *p_filter, subpicture_region_t *p_region_out,
     stream_t     *p_sub = NULL;
     xml_t        *p_xml = NULL;
     xml_reader_t *p_xml_reader = NULL;
+    VLC_UNUSED(p_chroma_list);
 
     if (!p_region_in || !p_region_in->psz_html)
         return VLC_EGENERIC;



More information about the vlc-commits mailing list