new file added, DrawLine function, HBITMAP, InternalImageInfo from HBITMAP
authorAlexandre Pigolkine <pigolkine@mono-cvs.ximian.com>
Fri, 27 Jun 2003 18:09:32 +0000 (18:09 -0000)
committerAlexandre Pigolkine <pigolkine@mono-cvs.ximian.com>
Fri, 27 Jun 2003 18:09:32 +0000 (18:09 -0000)
svn path=/trunk/mcs/; revision=15688

mcs/class/System.Drawing/System.Drawing/impl/wine/Bitmap.cs
mcs/class/System.Drawing/System.Drawing/impl/wine/ChangeLog
mcs/class/System.Drawing/System.Drawing/impl/wine/FontFamily.cs [new file with mode: 0644]
mcs/class/System.Drawing/System.Drawing/impl/wine/Graphics.cs
mcs/class/System.Drawing/System.Drawing/impl/wine/Image.cs

index 1739107efe3cccb22981388ce3d98464891a028d..b26d264499ea9acce90eecb35233464525683a03 100644 (file)
@@ -56,7 +56,7 @@ namespace System.Drawing {
                {
                        #region constructors
                        // constructors
-                       public Bitmap (int width, int height) 
+                       public Bitmap (int width, int height) : this( width, height, PixelFormat.Format32bppArgb)
                        {
                        }
 
@@ -68,8 +68,26 @@ namespace System.Drawing {
                                g.ReleaseHdc(hdc);
                        }
 
-                       public Bitmap (int width, int heigth, System.Drawing.Imaging.PixelFormat format) {
-                               throw new NotImplementedException ();
+                       public Bitmap (int width, int height, System.Drawing.Imaging.PixelFormat format) {
+                               IntPtr hdc = Win32.GetDC(IntPtr.Zero);
+                               pixelFormat_ = format;
+                               BITMAPINFO_FLAT bmi = new BITMAPINFO_FLAT();
+                               bmi.bmiHeader_biSize = 40;
+                               bmi.bmiHeader_biWidth = width;
+                               bmi.bmiHeader_biHeight = height;
+                               bmi.bmiHeader_biPlanes = 1;
+                               bmi.bmiHeader_biBitCount = (short)System.Drawing.Image.GetPixelFormatSize(pixelFormat_);
+                               bmi.bmiHeader_biCompression = 0;
+                               bmi.bmiHeader_biSizeImage = 0;
+                               bmi.bmiHeader_biXPelsPerMeter = 0;
+                               bmi.bmiHeader_biYPelsPerMeter = 0;
+                               bmi.bmiHeader_biClrUsed = 0;
+                               bmi.bmiHeader_biClrImportant = 0;
+                               IntPtr bitsPtr;
+                               nativeObject_ = Win32.CreateDIBSection(hdc, ref bmi, DibUsage.DIB_RGB_COLORS,
+                                                               out bitsPtr, IntPtr.Zero, 0);
+                               imageSize_ = new Size(width, height);
+                               Win32.ReleaseDC( IntPtr.Zero, hdc);
                        }
                        
                        public Bitmap (Image origial) {
@@ -128,6 +146,7 @@ namespace System.Drawing {
                                        Win32.DeleteDC(memDC);
                                        imageSize_ = info.Size;
                                        imageFormat_ = info.RawFormat;
+                                       pixelFormat_ =  info.Format;
                                }
                        }
                        
index 513918700e4396120ed791c9a2698f9c7dfde7dd..ce7ca2282b575ca416296e3b02568b74c6302def 100644 (file)
@@ -1,3 +1,9 @@
+2003-06-27  Alexandre Pigolkine <pigolkine@gmx.de>
+       * FontFamily.cs added
+       * Graphics.cs   DrawLine functions
+       * Bitmap.cs             create HBITMAP in constructor
+       * Image.cs              create InternalImageInfo from HBITMAP
+
 2003-06-15  Alexandre Pigolkine <pigolkine@gmx.de>
        * Graphics.cs   image painting
        * Bitmap.cs             
diff --git a/mcs/class/System.Drawing/System.Drawing/impl/wine/FontFamily.cs b/mcs/class/System.Drawing/System.Drawing/impl/wine/FontFamily.cs
new file mode 100644 (file)
index 0000000..5554808
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// System.Drawing.Win32Impl.FontFamily.cs
+//
+// Author:
+//   Alexandre Pigolkine (pigolkine@gmx.de)
+//
+//
+
+using System;
+using System.Drawing;
+using System.Drawing.Text;
+
+namespace System.Drawing {
+       namespace Win32Impl     {
+
+               internal class FontFamilyFactory : IFontFamilyFactory {
+
+                       IFontFamily IFontFamilyFactory.FontFamily(GenericFontFamilies genericFamily){
+                               return new Win32FontFamily(genericFamily);
+                       }
+
+                       IFontFamily IFontFamilyFactory.FontFamily(string familyName){
+                               return new Win32FontFamily(familyName);
+                       }
+                       
+                       IFontFamily IFontFamilyFactory.FontFamily( string familyName, FontCollection collection){
+                               return new Win32FontFamily(familyName,collection);
+                       }
+                       
+                       IFontFamily[] IFontFamilyFactory.GetFamilies(System.Drawing.Graphics graphics) { 
+                               throw new NotImplementedException();
+                       }               
+                       
+               }
+
+               internal class Win32FontFamily : MarshalByRefObject, IFontFamily
+               {
+                       string name;
+                       static Win32FontFamily genericMonospace;
+                       static Win32FontFamily genericSansSerif;
+                       static Win32FontFamily genericSerif;
+                       
+                       public Win32FontFamily(GenericFontFamilies genericFamily) {
+                               throw new NotImplementedException();
+                       }
+               
+                       public Win32FontFamily(string familyName) {
+                               name = familyName;
+                       }
+               
+                       public Win32FontFamily(string familyName, FontCollection collection) {
+                               name = familyName;
+                       }
+               
+                       public string Name {
+                               get {
+                                       return name;
+                               }
+                       }
+               
+                       public int GetCellAscent (FontStyle style) {
+                               return 0;
+                       }
+               
+                       public int GetCellDescent (FontStyle style) {
+                               return 0;
+                       }
+               
+                       public int GetEmHeight (FontStyle style) {
+                               return 0;
+                       }
+               
+                       public int GetLineSpacing (FontStyle style) {
+                               return 0;
+                       }
+               
+                       public bool IsStyleAvailable (FontStyle style){
+                               return false;
+                       }
+                       
+                       public void Dispose() {
+                       }
+               }
+       }
+}
index 705150bae9b0c8ded5ff2ff8530f1fdd7327dcb0..b61dc5f23acf813a9613f567929970cb3339dfe4 100644 (file)
@@ -500,34 +500,46 @@ namespace System.Drawing
                                throw new NotImplementedException ();
                        }
 
+                       void DrawLine (Pen winePen, int x1, int y1, int x2, int y2)
+                       {
+                               POINT[] pts = new POINT[2];
+                               pts[0].x = x1;
+                               pts[0].y = y1;
+                               pts[1].x = x2;
+                               pts[1].y = y2;
+                               IntPtr oldPen = Win32.SelectObject(hdc_, winePen.hpen_);
+                               Win32.Polyline( hdc_, pts, 2);
+                               Win32.SelectObject(hdc_, oldPen);
+                       }
+
                        [MonoTODO]
                        void IGraphics.DrawLine (System.Drawing.Pen pen, PointF pt1, PointF pt2)
                        {
-                               throw new NotImplementedException ();
+                               DrawLine( ConvertPen(pen), (int)pt1.X, (int)pt1.Y, (int)pt2.X, (int)pt2.Y);
                        }
 
                        [MonoTODO]
                        void IGraphics.DrawLine (System.Drawing.Pen pen, Point pt1, Point pt2)
                        {
-                               throw new NotImplementedException ();
+                               DrawLine( ConvertPen(pen), (int)pt1.X, (int)pt1.Y, (int)pt2.X, (int)pt2.Y);
                        }
 
                        [MonoTODO]
                        void IGraphics.DrawLine (System.Drawing.Pen pen, int x1, int y1, int x2, int y2)
                        {
-                               throw new NotImplementedException ();
+                               DrawLine( ConvertPen(pen), x1, y1, x2, y2);
                        }
 
                        [MonoTODO]
                        void IGraphics.DrawLine (System.Drawing.Pen pen, float x1, float y1, float x2, float y2)
                        {
-                               throw new NotImplementedException ();
+                               DrawLine( ConvertPen(pen), (int)x1, (int)y1, (int)x2, (int)y2);
                        }
 
                        [MonoTODO]
                        void IGraphics.DrawLines (System.Drawing.Pen pen, PointF [] points)
                        {
-                               throw new NotImplementedException ();
+                               //throw new NotImplementedException ();
                        }
 
                        [MonoTODO]
@@ -1359,13 +1371,13 @@ namespace System.Drawing
                        [MonoTODO]
                        void IGraphics.Restore (GraphicsState gstate)
                        {
-                               throw new NotImplementedException ();
+                               //throw new NotImplementedException ();
                        }
 
                        [MonoTODO]
                        void IGraphics.RotateTransform (float angle)
                        {
-                               throw new NotImplementedException ();
+                               //throw new NotImplementedException ();
                        }
 
                        [MonoTODO]
@@ -1377,7 +1389,8 @@ namespace System.Drawing
                        [MonoTODO]
                        public GraphicsState Save ()
                        {
-                               throw new NotImplementedException ();
+                               //throw new NotImplementedException ();
+                               return new GraphicsState();
                        }
 
                        [MonoTODO]
@@ -1473,7 +1486,7 @@ namespace System.Drawing
                        [MonoTODO]
                        void IGraphics.TranslateTransform (float dx, float dy)
                        {
-                               throw new NotImplementedException ();
+                               //throw new NotImplementedException ();
                        }
 
                        [MonoTODO]
index 1b08d9fd4fca1dc7f5b53a85fd2245a85df9123c..bde740ec9ba179083d93dccd83f2d777cf6c53f2 100644 (file)
@@ -18,6 +18,7 @@ namespace System.Drawing {
                using System.Runtime.Serialization;
                using System.Drawing.Imaging;
                using System.IO;
+               using System.Runtime.InteropServices;
 
                //[Serializable]
                //[ComVisible(true)]
@@ -30,6 +31,7 @@ namespace System.Drawing {
 
                        protected Size imageSize_;
                        protected ImageFormat imageFormat_;
+                       protected PixelFormat pixelFormat_;
                        // constructor
                        public Image () {}
     
@@ -114,8 +116,54 @@ namespace System.Drawing {
                        protected InternalImageInfo createdFrom_ = null;
                        public InternalImageInfo ConvertToInternalImageInfo() {
                                InternalImageInfo result = new InternalImageInfo();
+                               IntPtr hTempBitmap = IntPtr.Zero;
+                               IntPtr hdc = IntPtr.Zero;
+                               result.Size = imageSize_;
+                               result.Format = pixelFormat_;
+                               //result.Stride = 
+                               if(selectedIntoGraphics_ != null) {
+                                       hdc = selectedIntoGraphics_.GetHdc();
+                                       hTempBitmap = Win32.CreateCompatibleBitmap(hdc,1,1);
+                                       Win32.SelectObject( hdc, hTempBitmap);
+                               }
+                               else {
+                                       hdc = Win32.GetDC(IntPtr.Zero);
+                               }
                                //nativeObject_;Win32.GetDIBits();
-                               return createdFrom_;
+                               BITMAPINFO_FLAT bmi = new BITMAPINFO_FLAT();
+                               bmi.bmiHeader_biSize = 40;
+                               bmi.bmiHeader_biWidth = imageSize_.Width;
+                               bmi.bmiHeader_biHeight = imageSize_.Height;
+                               bmi.bmiHeader_biPlanes = 1;
+                               bmi.bmiHeader_biBitCount = (short) System.Drawing.Image.GetPixelFormatSize(pixelFormat_);
+                               bmi.bmiHeader_biCompression = 0;
+                               bmi.bmiHeader_biSizeImage = 0;
+                               bmi.bmiHeader_biXPelsPerMeter = 0;
+                               bmi.bmiHeader_biYPelsPerMeter = 0;
+                               bmi.bmiHeader_biClrUsed = 0;
+                               bmi.bmiHeader_biClrImportant = 0;
+
+                               int res = Win32.GetDIBits(hdc, nativeObject_, 0, imageSize_.Height, 0, ref bmi, (int)DibUsage.DIB_RGB_COLORS);
+                               if( res != 0) {
+                                       IntPtr nativeBits = Marshal.AllocHGlobal(bmi.bmiHeader_biSizeImage);
+                                       res = Win32.GetDIBits(hdc, nativeObject_, 0, imageSize_.Height, nativeBits.ToInt32(), ref bmi, (int)DibUsage.DIB_RGB_COLORS);
+                                       result.RawImageBytes = new byte[bmi.bmiHeader_biSizeImage];
+                                       Marshal.Copy( nativeBits, result.RawImageBytes, 0, bmi.bmiHeader_biSizeImage);
+                                       Marshal.FreeHGlobal(nativeBits);
+                               }
+                               else {
+                                       uint err = Win32.GetLastError();
+                               }
+                               
+                               if(selectedIntoGraphics_ != null) {
+                                       Win32.SelectObject( hdc, nativeObject_);
+                                       Win32.DeleteObject(hTempBitmap);
+                                       selectedIntoGraphics_.ReleaseHdc(hdc);
+                               }
+                               else {
+                                       Win32.ReleaseDC(IntPtr.Zero,hdc);
+                               }
+                               return result;
                        }
 
                        public void Save (string filename)