Author: pbartok
Date: 2005-12-05 22:48:14 -0500 (Mon, 05 Dec 2005)
New Revision: 53963

Modified:
   trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/System.Drawing/Font.cs
   trunk/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs
   trunk/mcs/class/System.Drawing/System.Drawing/gdipStructs.cs
   trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/Test/System.Drawing/TestFont.cs
Log:
2005-12-05  Peter Dennis Bartok  <[EMAIL PROTECTED]>

        * Font.cs: 
          - Implemented FromLogFont
          - Implemented ToLogFont
          - Whitespace fixes
        * gdipFunctions.cs:
          - Added GdipGetLogFontW method
          - Specified charset for GdipGetLogFontA method
        * gdipStructs.cs: Added LOGFONTW structure

2005-12-05  Peter Dennis Bartok  <[EMAIL PROTECTED]>

        * TestFont.cs: Added test for LogFont conversion



Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2005-12-06 
01:14:20 UTC (rev 53962)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2005-12-06 
03:48:14 UTC (rev 53963)
@@ -1,3 +1,14 @@
+2005-12-05  Peter Dennis Bartok  <[EMAIL PROTECTED]>
+
+       * Font.cs: 
+         - Implemented FromLogFont
+         - Implemented ToLogFont
+         - Whitespace fixes
+       * gdipFunctions.cs:
+         - Added GdipGetLogFontW method
+         - Specified charset for GdipGetLogFontA method
+       * gdipStructs.cs: Added LOGFONTW structure
+
 2005-12-05 Gert Driesen <[EMAIL PROTECTED]>
 
        * BufferedGraphics.cs: Removed duplicate class. Set eol-style to

Modified: trunk/mcs/class/System.Drawing/System.Drawing/Font.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Font.cs       2005-12-06 
01:14:20 UTC (rev 53962)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Font.cs       2005-12-06 
03:48:14 UTC (rev 53963)
@@ -46,7 +46,7 @@
        public sealed class Font : MarshalByRefObject, ISerializable, 
ICloneable, IDisposable
        {
                private IntPtr  fontObject = IntPtr.Zero;
-               private string systemFontName;
+               private string  systemFontName;
 
                private void CreateFont(string familyName, float emSize, 
FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical) {
                         Status         status;                  
@@ -202,12 +202,10 @@
                        }
 
                        if ((int) osInfo.Platform == 128 || (int) 
osInfo.Platform == 4) {
-                       // If we're on Unix we use our private gdiplus API to 
avoid Wine 
-                       // dependencies in S.D
-
+                               // If we're on Unix we use our private gdiplus 
API to avoid Wine 
+                               // dependencies in S.D
                                Status s = GDIPlus.GdipCreateFontFromHfont 
(Hfont, out newObject, ref lf);
                                GDIPlus.CheckStatus (s);
-                               
                        } else {
 
                                // This needs testing
@@ -221,7 +219,7 @@
                                GDIPlus.ReleaseDC (hdc);
                                return f;                               
                        }
-
+                       
                        if (lf.lfItalic != 0) {
                                newStyle |= FontStyle.Italic;
                        }
@@ -370,13 +368,15 @@
                                        fontObject = value;
                        }
                }
-#if NET_2_0
-               internal string SysFontName {
-                       set {
-                               systemFontName = value;
-                       }
-               }
-#endif
+
+#if NET_2_0
+               internal string SysFontName {
+                       set {
+                               systemFontName = value;
+                       }
+               }
+#endif
+
                private bool _bold;
 
                [DesignerSerializationVisibility 
(DesignerSerializationVisibility.Hidden)]
@@ -420,18 +420,18 @@
                        }
                }
 
-#if NET_2_0
+#if NET_2_0
                [Browsable(false)]
-               public bool IsSystemFont {
-                       get {
-                               if (systemFontName == null)
-                                       return false;
+               public bool IsSystemFont {
+                       get {
+                               if (systemFontName == null)
+                                       return false;
+
+                               return StringComparer.InvariantCulture.Compare 
(systemFontName, string.Empty) != 0;
+                       }
+               }
+#endif
 
-                               return StringComparer.InvariantCulture.Compare 
(systemFontName, string.Empty) != 0;                             
-                       }
-               }
-#endif
-
                private bool _italic;
 
                [DesignerSerializationVisibility 
(DesignerSerializationVisibility.Hidden)]
@@ -486,14 +486,14 @@
                        }
                }
 
-#if NET_2_0
-               [Browsable(false)]
-               public string SystemFontName {
-                       get {
-                               return systemFontName;
-                       }
-               }
-#endif
+#if NET_2_0
+               [Browsable(false)]
+               public string SystemFontName {
+                       get {
+                               return systemFontName;
+                       }
+               }
+#endif
                private bool _underline;
 
                [DesignerSerializationVisibility 
(DesignerSerializationVisibility.Hidden)]
@@ -553,28 +553,96 @@
                        return GetHeight (Graphics.systemDpiY);
                }
 
-               [MonoTODO]
                public static Font FromLogFont (object lf)
                {
-                       throw new NotImplementedException ();
+                       if ((int) Environment.OSVersion.Platform == 128 || 
(int) Environment.OSVersion.Platform == 4) {
+                               return FromLogFont(lf, IntPtr.Zero);
+                       } else {
+                               IntPtr  hDC;
+
+                               hDC = IntPtr.Zero;
+
+                               try {
+                                       hDC = GDIPlus.GetDC(IntPtr.Zero);
+                                       return FromLogFont (lf, hDC);
+                               }
+
+                               finally {
+                                       GDIPlus.ReleaseDC(hDC);
+                               }
+                       }
+
                }
 
                public void ToLogFont (object logFont)
                {
-                       using (Graphics g = Graphics.FromHdc (GDIPlus.GetDC 
(IntPtr.Zero))) {
-                               ToLogFont (logFont, g);
+                       Graphics g;
+
+                       g = null;
+
+                       if ((int) Environment.OSVersion.Platform == 128 || 
(int) Environment.OSVersion.Platform == 4) {
+                               // Unix
+                               Bitmap  img;
+
+                               img = null;
+
+                               try {
+                                       // We don't have a window we could 
associate the DC with
+                                       // so we use an image instead
+                                       img = new Bitmap(1, 1, 
Imaging.PixelFormat.Format32bppArgb);
+                                       g = Graphics.FromImage(img);
+                                       ToLogFont(logFont, g);
+                               }
+
+                               finally {
+                                       if (g != null) {
+                                               g.Dispose();
+                                       }
+
+                                       if (img != null) {
+                                               img.Dispose();
+                                       }
+                               }
+                       } else {
+                               // Windows
+                               IntPtr  hDC;
+
+                               hDC = IntPtr.Zero;
+
+                               try {
+
+                                       hDC = GDIPlus.GetDC(IntPtr.Zero);
+                                       g = Graphics.FromHdc(hDC);
+
+                                       ToLogFont (logFont, g);
+                               }
+
+                               finally {
+                                       if (g != null) {
+                                               g.Dispose();
+                                       }
+
+                                       GDIPlus.ReleaseDC(hDC);
+                               }
                        }
                }
 
                public void ToLogFont (object logFont, Graphics graphics)
                {
+                       IntPtr lf;
+
                        if (graphics == null) {
                                throw new ArgumentNullException ("graphics");
                        }
 
-                       // TODO: Does it make a sense to deal with LOGFONTW ?
-                       LOGFONTA o = (LOGFONTA)logFont;
-                       GDIPlus.CheckStatus 
(GDIPlus.GdipGetLogFontA(NativeObject, graphics.NativeObject, ref o));
+                       lf = 
Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LOGFONTW)));
+                       if (lf == IntPtr.Zero) {
+                               throw new OutOfMemoryException("Could not 
allocate logfont structure memory");
+                       }
+                       GDIPlus.CheckStatus 
(GDIPlus.GdipGetLogFontW(NativeObject, graphics.NativeObject, lf));
+
+                       Marshal.PtrToStructure(lf, logFont);
+                       Marshal.FreeHGlobal(lf);
                }
 
                public float GetHeight (Graphics graphics)

Modified: trunk/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs      
2005-12-06 01:14:20 UTC (rev 53962)
+++ trunk/mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs      
2005-12-06 03:48:14 UTC (rev 53963)
@@ -1365,9 +1365,12 @@
                internal static extern Status GdipCreateFont (IntPtr 
fontFamily, float emSize, FontStyle style, GraphicsUnit  unit,  out IntPtr 
font);
                [DllImport("gdiplus.dll")]                   
                internal static extern Status GdipDeleteFont (IntPtr font);     
        
+               [DllImport("gdiplus.dll", CharSet=CharSet.Ansi)]
+               internal static extern Status GdipGetLogFontA(IntPtr font, 
IntPtr graphics, IntPtr logfontA);
+               [DllImport("gdiplus.dll", CharSet=CharSet.Unicode)]
+               internal static extern Status GdipGetLogFontW(IntPtr font, 
IntPtr graphics, IntPtr logfontW);
+
                [DllImport("gdiplus.dll")]                   
-               internal static extern Status GdipGetLogFontA(IntPtr font, 
IntPtr graphics, ref LOGFONTA logfontA);
-               [DllImport("gdiplus.dll")]                   
                internal static extern Status GdipCreateFontFromDC(IntPtr hdc, 
out IntPtr font);
                [DllImport("gdiplus.dll", SetLastError=true)]
                internal static extern Status GdipCreateFontFromLogfontA(IntPtr 
hdc, ref LOGFONTA lf, out IntPtr ptr);

Modified: trunk/mcs/class/System.Drawing/System.Drawing/gdipStructs.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/gdipStructs.cs        
2005-12-06 01:14:20 UTC (rev 53962)
+++ trunk/mcs/class/System.Drawing/System.Drawing/gdipStructs.cs        
2005-12-06 03:48:14 UTC (rev 53963)
@@ -106,6 +106,26 @@
        }  
        
        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
+       internal  struct LOGFONTW
+       {
+               internal int    lfHeight;
+               internal uint   lfWidth;
+               internal uint   lfEscapement;
+               internal uint   lfOrientation;
+               internal uint   lfWeight;
+               internal byte   lfItalic;
+               internal byte   lfUnderline;
+               internal byte   lfStrikeOut;
+               internal byte   lfCharSet;
+               internal byte   lfOutPrecision;
+               internal byte   lfClipPrecision;
+               internal byte   lfQuality;
+               internal byte   lfPitchAndFamily;
+               [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
+               internal string lfFaceName;
+       }  
+       
+       [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
        internal struct GdipImageCodecInfo      /*Size 76 bytes*/
        {
                internal Guid Clsid;                    

Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog        
2005-12-06 01:14:20 UTC (rev 53962)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog        
2005-12-06 03:48:14 UTC (rev 53963)
@@ -1,3 +1,7 @@
+2005-12-05  Peter Dennis Bartok  <[EMAIL PROTECTED]>
+
+       * TestFont.cs: Added test for LogFont conversion
+
 2005-12-05 Jordi Mas i Hernandez <[EMAIL PROTECTED]>
 
        * TestPoint.cs: Test new methods for .Net 2.0

Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/TestFont.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/TestFont.cs      
2005-12-06 01:14:20 UTC (rev 53962)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/TestFont.cs      
2005-12-06 03:48:14 UTC (rev 53963)
@@ -4,8 +4,10 @@
 // Author:
 //
 //      Jordi Mas i Hernandez, [EMAIL PROTECTED]
+//      Peter Dennis Bartok, [EMAIL PROTECTED]
 //
-// (C) 2004 Ximian, Inc.  http://www.ximian.com
+// (C) 2003 Ximian, Inc.  http://www.ximian.com
+// (C) 2004-2005 Novell, Inc.  http://www.novell.com
 //
 
 //
@@ -30,11 +32,12 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
+using NUnit.Framework;
 using System;
 using System.Drawing;
 using System.Drawing.Imaging;
 using System.Security.Permissions;
-using NUnit.Framework;
+using System.Runtime.InteropServices;
 
 namespace MonoTests.System.Drawing{
 
@@ -72,6 +75,39 @@
                        AssertEquals (f.Underline, f2.Underline);
                        AssertEquals (f.Unit, f2.Unit);
                }
-               
+
+               [ StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode) ]
+               class LOGFONT {
+                       public int lfHeight = 0;
+                       public int lfWidth = 0;
+                       public int lfEscapement = 0;
+                       public int lfOrientation = 0;
+                       public int lfWeight = 0;
+                       public byte lfItalic = 0;
+                       public byte lfUnderline = 0;
+                       public byte lfStrikeOut = 0;
+                       public byte lfCharSet = 0;
+                       public byte lfOutPrecision = 0;
+                       public byte lfClipPrecision = 0;
+                       public byte lfQuality = 0;
+                       public byte lfPitchAndFamily = 0;
+                       [ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32) ]
+                       public string lfFaceName = null;
+               }
+
+               [Test]
+               public void TestToLogFont() {
+                       Font f;
+                       LOGFONT lf;
+
+                       lf = new LOGFONT();
+                       f = new Font("Arial", 10);
+
+                       f.ToLogFont(lf);
+                       AssertEquals("lf1", -13, lf.lfHeight);
+                       AssertEquals("lf2", 400, lf.lfWeight);
+                       AssertEquals("lf3", 1, lf.lfCharSet);
+                       AssertEquals("lf4", f.Name, lf.lfFaceName);
+               }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to