Author: spouliot
Date: 2006-08-05 19:06:59 -0400 (Sat, 05 Aug 2006)
New Revision: 63398
Modified:
trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
trunk/mcs/class/System.Drawing/System.Drawing/Font.cs
Log:
2006-08-05 Sebastien Pouliot <[EMAIL PROTECTED]>
* Font.cs: Avoid double cast in Equals. Return lfCharSet as 1 in
ToLogFont even if GDI+ has that value to 0.
Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2006-08-05
23:05:04 UTC (rev 63397)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2006-08-05
23:06:59 UTC (rev 63398)
@@ -1,3 +1,8 @@
+2006-08-05 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * Font.cs: Avoid double cast in Equals. Return lfCharSet as 1 in
+ ToLogFont even if GDI+ has that value to 0.
+
2006-08-04 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* Icon.cs: when converting to Bitmap, handle the 24 bits separately.
Modified: trunk/mcs/class/System.Drawing/System.Drawing/Font.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Font.cs 2006-08-05
23:05:04 UTC (rev 63397)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Font.cs 2006-08-05
23:06:59 UTC (rev 63398)
@@ -49,6 +49,8 @@
private float _size;
private const byte DefaultCharSet = 1;
+ private static int CharSetOffset = -1;
+ private static int FaceNameOffset = -1;
private void CreateFont (string familyName, float emSize,
FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical)
{
@@ -517,11 +519,10 @@
public override bool Equals (object obj)
{
- if (! (obj is Font))
+ Font fnt = (obj as Font);
+ if (fnt == null)
return false;
-
- Font fnt = (Font) obj;
-
+
if (fnt.FontFamily.Equals (FontFamily) && fnt.Size ==
Size &&
fnt.Style == Style && fnt.Unit == Unit &&
fnt.GdiCharSet == GdiCharSet &&
@@ -639,8 +640,35 @@
throw new ArgumentNullException ("graphics");
}
- if (Marshal.SizeOf(logFont) >=
Marshal.SizeOf(typeof(LOGFONT))) {
- GDIPlus.CheckStatus
(GDIPlus.GdipGetLogFont(NativeObject, graphics.NativeObject, logFont));
+ Type lf = typeof (LOGFONT);
+ if (Marshal.SizeOf (logFont) >= Marshal.SizeOf (lf)) {
+ Status status = GDIPlus.GdipGetLogFont
(NativeObject, graphics.NativeObject, logFont);
+
+ // lfCharSet is always 1 from S.D. (even on
error) but GDI+ returns 0
+ if (CharSetOffset == -1) {
+ CharSetOffset = (int) Marshal.OffsetOf
(lf, "lfCharSet");
+ FaceNameOffset = (int) Marshal.OffsetOf
(lf, "lfFaceName");
+ }
+
+ // note: Marshal.WriteByte(object,*) methods
are unimplemented on Mono
+ GCHandle gch = GCHandle.Alloc (logFont,
GCHandleType.Pinned);
+ try {
+ IntPtr ptr = gch.AddrOfPinnedObject ();
+ // if status isn't Ok then everything
(except lfCharSet and lfFaceName)
+ // gets zeroized in managed code
+ if (status != Status.Ok) {
+ byte[] zero = new byte
[FaceNameOffset];
+ Marshal.Copy (zero, 0, ptr,
FaceNameOffset);
+ }
+ // set lfCharSet to 1
+ Marshal.WriteByte (ptr, CharSetOffset,
1);
+ }
+ finally {
+ gch.Free ();
+ }
+
+ // now we can throw, if required
+ GDIPlus.CheckStatus (status);
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches