Author: gonzalo
Date: 2006-06-02 18:45:53 -0400 (Fri, 02 Jun 2006)
New Revision: 61426
Modified:
trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
trunk/mcs/class/System.Drawing/System.Drawing/Color.cs
Log:
2006-06-02 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* Color.cs: when deserializing from an MS generated stream, the value
for known colors was 0. These changes make our Color handle that case.
We won't serialize the name for known colors either, but the value will
be there, so we only check for a 0 value on a known color once.
Fixes bug #78265.
Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2006-06-02
21:45:22 UTC (rev 61425)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2006-06-02
22:45:53 UTC (rev 61426)
@@ -1,3 +1,11 @@
+2006-06-02 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * Color.cs: when deserializing from an MS generated stream, the value
+ for known colors was 0. These changes make our Color handle that case.
+ We won't serialize the name for known colors either, but the value will
+ be there, so we only check for a 0 value on a known color once.
+ Fixes bug #78265.
+
2006-05-30 Sebastien Pouliot <[EMAIL PROTECTED]>
* Font.cs: Change default charset to 1. Ensure we always call the
Modified: trunk/mcs/class/System.Drawing/System.Drawing/Color.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Color.cs 2006-06-02
21:45:22 UTC (rev 61425)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Color.cs 2006-06-02
22:45:53 UTC (rev 61426)
@@ -58,18 +58,18 @@
private static Hashtable systemColors;
static Color [] knownColors;
- // Private transparancy (A) and R,G,B fields.
+ // Private transparency (A) and R,G,B fields.
private long value;
private static string creatingColorNames = "creatingColorNames";
- // The specs also indicate that all three of these propities
are true
+ // The specs also indicate that all three of these properties
are true
// if created with FromKnownColor or FromNamedColor, false
otherwise (FromARGB).
// Per Microsoft and ECMA specs these varibles are set by which
constructor is used, not by their values.
[Flags]
enum ColorType : short {
Empty=0,
- ARGB=1,
- Known=2,
+ Known=1,
+ ARGB=2,
Named=4,
System=8
}
@@ -88,8 +88,15 @@
public string Name {
get{
- if (name == null || name == String.Empty)
+ if (name == null) {
+ if (IsNamedColor) { // Can happen with
stuff deserialized from MS
+ FillColorNames ();
+ object o = knownColors
[knownColor];
+ if (o != null)
+ return ((Color) o).name;
+ }
return String.Format ("{0:x}", ToArgb
());
+ }
return name;
}
}
@@ -123,8 +130,7 @@
CheckARGBValues (alpha, red, green, blue);
Color color = new Color ();
color.state = (short) ColorType.ARGB;
- color.value = (alpha << 24) + (red << 16) + (green <<
8) + blue;
- color.name = String.Empty;
+ color.value = ((uint) alpha << 24) + (red << 16) +
(green << 8) + blue;
return color;
}
@@ -414,6 +420,15 @@
public byte A
{
get {
+ // Optimization for known colors that were
deserialized
+ // from an MS serialized stream.
+ if (value == 0 && IsKnownColor) {
+ FillColorNames ();
+ object o = knownColors [knownColor];
+ if (o != null) {
+ value = ((Color) o).ToArgb ();
+ }
+ }
return (byte) ((value >> 24 & 0x0ff));
}
}
@@ -429,6 +444,15 @@
public byte R
{
get {
+ // Optimization for known colors that were
deserialized
+ // from an MS serialized stream.
+ if (value == 0 && IsKnownColor) {
+ FillColorNames ();
+ object o = knownColors [knownColor];
+ if (o != null) {
+ value = ((Color) o).ToArgb ();
+ }
+ }
return (byte) ((value >> 16 & 0x0ff));
}
}
@@ -444,6 +468,15 @@
public byte G
{
get {
+ // Optimization for known colors that were
deserialized
+ // from an MS serialized stream.
+ if (value == 0 && IsKnownColor) {
+ FillColorNames ();
+ object o = knownColors [knownColor];
+ if (o != null) {
+ value = ((Color) o).ToArgb ();
+ }
+ }
return (byte) ((value >> 8 & 0x0ff));
}
}
@@ -459,6 +492,15 @@
public byte B
{
get {
+ // Optimization for known colors that were
deserialized
+ // from an MS serialized stream.
+ if (value == 0 && IsKnownColor) {
+ FillColorNames ();
+ object o = knownColors [knownColor];
+ if (o != null) {
+ value = ((Color) o).ToArgb ();
+ }
+ }
return (byte) (value & 0x0ff);
}
}
@@ -522,8 +564,9 @@
if (IsEmpty)
return "Color [Empty]";
- if (name != "")
- return "Color [" + name + "]";
+ // Use the property here, not the field.
+ if (IsNamedColor)
+ return "Color [" + Name + "]";
return String.Format ("Color [A={0}, R={1}, G={2},
B={3}]", A, R, G, B);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches