[librsvg/gnome-3-2] Clamp opacity value to range 0 to 1



commit cc93d170cbc2b13fe950233411519f896456b6a0
Author: Kurosawa Takeshi <taken spc gmail com>
Date:   Thu Nov 24 18:03:18 2011 +0100

    Clamp opacity value to range 0 to 1
    
    Our opacity parsing function allows
    * number values outside range 0.0 to 1.0
    * %-values.
    
    However this is incorrect behavior.
    * http://www.w3.org/TR/SVG11/painting.html#FillOpacityProperty
    * http://www.w3.org/TR/SVGTiny12/painting.html#FillOpacityProperty

 rsvg-css.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/rsvg-css.c b/rsvg-css.c
index be9b7fa..fad6a19 100644
--- a/rsvg-css.c
+++ b/rsvg-css.c
@@ -556,13 +556,16 @@ rsvg_css_parse_color (const char *str, gboolean * inherit)
 guint
 rsvg_css_parse_opacity (const char *str)
 {
-    char *end_ptr;
+    char *end_ptr = NULL;
     double opacity;
 
     opacity = g_ascii_strtod (str, &end_ptr);
 
-    if (end_ptr && end_ptr[0] == '%')
-        opacity *= 0.01;
+    if ((opacity == -HUGE_VAL || opacity == HUGE_VAL) && (ERANGE == errno) ||
+        *end_ptr != '\0')
+        opacity = 1.;
+
+    opacity = CLAMP (opacity, 0., 1.);
 
     return (guint) floor (opacity * 255. + 0.5);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]