Author: mdk Date: 2008-02-21 06:09:07 -0500 (Thu, 21 Feb 2008) New Revision: 96333
Modified: trunk/moon/src/ChangeLog trunk/moon/src/color.cpp Log: 2008-02-21 Michael Dominic K. <[EMAIL PROTECTED]> * src/color.cpp: A slightly more relaxed/tolerant way of parsing the colors... it's the web and it's broken by default. Fixes: #362287 (the US candidates website). Modified: trunk/moon/src/ChangeLog =================================================================== --- trunk/moon/src/ChangeLog 2008-02-21 11:06:54 UTC (rev 96332) +++ trunk/moon/src/ChangeLog 2008-02-21 11:09:07 UTC (rev 96333) @@ -1,3 +1,9 @@ +2008-02-21 Michael Dominic K. <[EMAIL PROTECTED]> + + * src/color.cpp: A slightly more relaxed/tolerant way of parsing the + colors... it's the web and it's broken by default. Fixes: #362287 (the US + candidates website). + 2008-02-21 Stephane Delcroix <[EMAIL PROTECTED]> * text.h|cpp: compute GetOriginPoint and fix GetSizeForBrush Modified: trunk/moon/src/color.cpp =================================================================== --- trunk/moon/src/color.cpp 2008-02-21 11:06:54 UTC (rev 96332) +++ trunk/moon/src/color.cpp 2008-02-21 11:09:07 UTC (rev 96333) @@ -218,37 +218,35 @@ char g [3] = "FF"; char b [3] = "FF"; - switch (len - 1) { - case 3: - // rgb - r [1] = r [0] = name [1]; - g [1] = g [0] = name [2]; - b [1] = b [0] = name [3]; - break; - case 4: - // argb - a [1] = a [0] = name [1]; - r [1] = r [0] = name [2]; - g [1] = g [0] = name [3]; - b [1] = b [0] = name [4]; - break; - case 6: - // rrggbb - r [0] = name [1]; r [1] = name [2]; - g [0] = name [3]; g [1] = name [4]; - b [0] = name [5]; b [1] = name [6]; - break; - case 8: + // Relaxed parsing with some it's-the-web-and-it's-broken + // "error tolerance" + int real_len = len - 1; + if (real_len >= 8) { // aarrggbb a [0] = name [1]; a [1] = name [2]; r [0] = name [3]; r [1] = name [4]; g [0] = name [5]; g [1] = name [6]; b [0] = name [7]; b [1] = name [8]; - break; + } else if (real_len >= 6) { + // rrggbb + r [0] = name [1]; r [1] = name [2]; + g [0] = name [3]; g [1] = name [4]; + b [0] = name [5]; b [1] = name [6]; + } else if (real_len >= 4) { + // argb + a [1] = a [0] = name [1]; + r [1] = r [0] = name [2]; + g [1] = g [0] = name [3]; + b [1] = b [0] = name [4]; + } else if (real_len == 3) { + // rgb + r [1] = r [0] = name [1]; + g [1] = g [0] = name [2]; + b [1] = b [0] = name [3]; } return new Color (strtol (r, NULL, 16) / 255.0F, strtol (g, NULL, 16) / 255.0F, - strtol (b, NULL, 16) / 255.0F, strtol (a, NULL, 16) / 255.0F); + strtol (b, NULL, 16) / 255.0F, strtol (a, NULL, 16) / 255.0F); } if (name [0] == 's' && name [1] == 'c' && name [2] == '#') { _______________________________________________ Mono-patches maillist - Mono-patches@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-patches