]> git.saurik.com Git - wxWidgets.git/commitdiff
CSS colour compatibility after #1473731.
authorWłodzimierz Skiba <abx@abx.art.pl>
Fri, 5 May 2006 17:38:58 +0000 (17:38 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Fri, 5 May 2006 17:38:58 +0000 (17:38 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/colourcmn.cpp

index 114dd597a6b989b0014e56bc313fc9cc91e8dee5..3969790771510fde07ba214fc63e4c8601769740 100644 (file)
@@ -21,6 +21,7 @@
 
 #ifndef WX_PRECOMP
     #include "wx/log.h"
+    #include "wx/utils.h"
 #endif
 
 #include "wx/gdicmn.h"
@@ -38,12 +39,16 @@ bool wxColourBase::FromString(const wxChar *str)
     if ( wxStrncmp(str, wxT("RGB"), 3) == 0 ||
          wxStrncmp(str, wxT("rgb"), 3) == 0 )
     {
-        // RGB specification CSS-like
+        // CSS-like RGB specification
+        // according to http://www.w3.org/TR/REC-CSS2/syndata.html#color-units
+        // values outside 0-255 range are allowed but should be clipped
         int red, green, blue;
         if (wxSscanf(&str[3], wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
             return false;
 
-        Set((unsigned char)red, (unsigned char)green, (unsigned char)blue);
+        Set((unsigned char)wxClip(red,0,255),
+            (unsigned char)wxClip(green,0,255),
+            (unsigned char)wxClip(blue,0,255));
     }
     else if ( str[0] == wxT('#') && wxStrlen(str) == 7 )
     {