[Mono-bugs] [Bug 61222][Nor] New - Fix to bug 60297 and 61148
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 6 Jul 2004 19:35:37 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by software@solmersa.com.
http://bugzilla.ximian.com/show_bug.cgi?id=61222
--- shadow/61222 2004-07-06 19:35:37.000000000 -0400
+++ shadow/61222.tmp.20172 2004-07-06 19:35:37.000000000 -0400
@@ -0,0 +1,158 @@
+Bug#: 61222
+Product: Mono: Class Libraries
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: Sys.Drawing.
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: software@solmersa.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Fix to bug 60297 and 61148
+
+Here are the changes using the mono 1.0 code. This fix is needed in mono
+1.0. Sorry, but when using diff the program marked the whole files like
+different so I think this (the code snippet) is better.
+
+I tested it on my machine Windows XP and it's working.
+
+SDavila
+
+
+ private IntPtr hFont = IntPtr.Zero;
+
+ public static Font FromHfont (IntPtr Hfont)
+ {
+ OperatingSystem osInfo = Environment.OSVersion;
+ IntPtr newObject;
+ IntPtr hdc;
+ IntPtr oldFont;
+ FontStyle newStyle =
+FontStyle.Regular;
+ float newSize;
+ LOGFONTA lf = new LOGFONTA ();
+
+ // Sanity. Should we throw an exception?
+ if (Hfont == IntPtr.Zero) {
+ Font result = new Font ("Arial", (float)
+10.0, FontStyle.Regular);
+ return(result);
+ }
+
+ if ((int) osInfo.Platform == 128) {
+ // If we're on Unix we use our private gdiplus
+API to avoid Wine
+ // dependencies in S.D
+
+ lock (typeof (Font))
+ {
+ Status s =
+GDIPlus.GdipCreateFontFromHfont (Hfont, out newObject, ref lf);
+ GDIPlus.CheckStatus (s);
+ }
+ } else {
+
+ // This needs testing
+ // GetDC, SelectObject, ReleaseDC
+GetTextMetric and
+ // GetFontFace are not really GDIPlus,
+see gdipFunctions.cs
+
+ newStyle = FontStyle.Regular;
+
+ lock (typeof (Font))
+ {
+ hdc = GDIPlus.GetDC (IntPtr.Zero);
+ int graphics;
+
+ if (hdc==IntPtr.Zero)
+ throw new
+ArgumentException ("hdc is zero");
+ GDIPlus.GdipCreateFromHDC(hdc,
+out graphics);
+ if (graphics == 0)
+ throw new
+ArgumentException ("Failed graphics creation");
+
+ oldFont = GDIPlus.SelectObject
+(hdc, Hfont);
+ if (oldFont == IntPtr.Zero)
+ throw new
+ArgumentException ("An error in select font object");
+
+
+ GDIPlus.CheckStatus
+(GDIPlus.GdipCreateFontFromDC (hdc, out newObject));
+ if (newObject == IntPtr.Zero)
+ throw new
+ArgumentException ("An error in createFontFromDC");
+
+ GDIPlus.CheckStatus
+(GDIPlus.GdipGetLogFontA (newObject, new System.IntPtr(graphics), ref
+lf));
+ GDIPlus.GdipDeleteGraphics(new
+System.IntPtr(graphics));
+ GDIPlus.SelectObject (hdc,
+oldFont);
+ GDIPlus.ReleaseDC (hdc);
+ }
+ }
+
+ if (lf.lfItalic != 0) {
+ newStyle |= FontStyle.Italic;
+ }
+
+ if (lf.lfUnderline != 0) {
+ newStyle |= FontStyle.Underline;
+ }
+
+ if (lf.lfStrikeOut != 0) {
+ newStyle |= FontStyle.Strikeout;
+ }
+
+ if (lf.lfWeight > 400) {
+ newStyle |= FontStyle.Bold;
+ }
+
+ if (lf.lfHeight < 0) {
+ newSize = lf.lfHeight * -1;
+ } else {
+ newSize = lf.lfHeight;
+ }
+
+ Font rFont = new Font(newObject, lf.lfFaceName,
+newStyle, newSize);
+ rFont.hFont = Hfont;
+
+ return (rFont);
+ }
+
+ public IntPtr ToHfont ()
+ {
+ IntPtr Hfont;
+ OperatingSystem osInfo = Environment.OSVersion;
+
+ // Sanity. Should we throw an exception?
+ if (fontObject == IntPtr.Zero) {
+ return IntPtr.Zero;
+ }
+
+ if ((int) osInfo.Platform == 128) {
+ // If we're on Unix we use our private
+gdiplus API
+ GDIPlus.CheckStatus (GDIPlus.GdipGetHfont
+(fontObject, out Hfont));
+ } else {
+ // This needs testing, but I don't have a
+working win32 mono
+ // environment.
+ return (hFont);
+ }
+ return Hfont;
+ }