dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing.Xsharp DrawingTexture


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing.Xsharp DrawingTextureBrush.cs,NONE,1.1 DrawingFont.cs,1.1,1.2 DrawingGraphics.cs,1.1,1.2DrawingToolkit.cs,1.1,1.2
Date: Mon, 09 Jun 2003 17:25:40 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Xsharp
In directory subversions:/tmp/cvs-serv18924/System.Drawing.Xsharp

Modified Files:
        DrawingFont.cs DrawingGraphics.cs DrawingToolkit.cs 
Added Files:
        DrawingTextureBrush.cs 
Log Message:


Font management; texture brushes; some type converters;
system brushes and pens.


--- NEW FILE ---
/*
 * DrawingTextureBrush.cs - Implementation of texture brushes.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing.Toolkit
{

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;
using System.Drawing.Imaging;
using Xsharp;

internal sealed class DrawingTextureBrush : IToolkitBrush
{
        // Internal state.
        private TextureBrush properties;
        private RectangleF dstRect;
        private ImageAttributes imageAttr;

        // Constructor.
        public DrawingTextureBrush(TextureBrush properties,
                                                           RectangleF dstRect,
                                                           ImageAttributes 
imageAttr)
                        {
                                this.properties = properties;
                                this.dstRect = dstRect;
                                this.imageAttr = imageAttr;
                        }

        // Select this brush into a graphics object.
        public void Select(IToolkitGraphics _graphics)
                        {
                                DrawingGraphics graphics = (_graphics as 
DrawingGraphics);
                                if(graphics != null)
                                {
                                        // TODO
                                }
                        }

        // Dispose of this brush.
        public void Dispose()
                        {
                                // Nothing to do here in this implementation.
                        }

}; // class DrawingTextureBrush

}; // namespace System.Drawing.Toolkit

Index: DrawingFont.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Xsharp/DrawingFont.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** DrawingFont.cs      7 Jun 2003 22:40:58 -0000       1.1
--- DrawingFont.cs      9 Jun 2003 21:25:37 -0000       1.2
***************
*** 32,35 ****
--- 32,36 ----
        // Internal state.
        private System.Drawing.Font properties;
+       private Xsharp.Font xfont;
  
        // Constructor.
***************
*** 37,40 ****
--- 38,42 ----
                        {
                                this.properties = properties;
+                               this.xfont = null;
                        }
  
***************
*** 45,49 ****
                                if(graphics != null)
                                {
!                                       // TODO
                                }
                        }
--- 47,61 ----
                                if(graphics != null)
                                {
!                                       lock(this)
!                                       {
!                                               if(xfont == null)
!                                               {
!                                                       xfont = new Xsharp.Font
!                                                               
(MapFamilyName(properties.Name),
!                                                                
(int)(properties.SizeInPoints * 10.0f),
!                                                                
(Xsharp.FontStyle)(properties.Style));
!                                               }
!                                               graphics.font = xfont;
!                                       }
                                }
                        }
***************
*** 53,56 ****
--- 65,109 ----
                        {
                                // Nothing to do here in this implementation.
+                       }
+ 
+       // Get the raw HFONT for this toolkit font.  IntPtr.Zero if none.
+       public IntPtr GetHfont()
+                       {
+                               // Nothing to do here in this implementation.
+                               return IntPtr.Zero;
+                       }
+ 
+       // Get the LOGFONT information for this toolkit font.
+       public void ToLogFont(Object lf, IToolkitGraphics graphics)
+                       {
+                               // Nothing to do here in this implementation.
+                       }
+ 
+       // Map a Windows-style family name to an Xsharp-style family name.
+       private static String MapFamilyName(String name)
+                       {
+                               if(String.Compare(name, "Times", true) == 0 ||
+                                  String.Compare(name, "Times New Roman", 
true) == 0)
+                               {
+                                       return Xsharp.Font.Serif;
+                               }
+                               else if(String.Compare(name, "Helvetica", true) 
== 0 ||
+                                       String.Compare(name, "Helv", true) == 0 
||
+                                       String.Compare
+                                                       (name, "Microsoft Sans 
Serif", true) == 0 ||
+                                       String.Compare(name, "Arial", true) == 
0 ||
+                                       String.Compare(name, 0, "Arial ", 0, 6, 
true) == 0)
+                               {
+                                       return Xsharp.Font.SansSerif;
+                               }
+                               else if(String.Compare(name, "Courier", true) 
== 0 ||
+                                       String.Compare(name, "Courier New", 
true) == 0)
+                               {
+                                       return Xsharp.Font.Fixed;
+                               }
+                               else
+                               {
+                                       return Xsharp.Font.Serif;
+                               }
                        }
  

Index: DrawingGraphics.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Xsharp/DrawingGraphics.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** DrawingGraphics.cs  7 Jun 2003 22:40:58 -0000       1.1
--- DrawingGraphics.cs  9 Jun 2003 21:25:37 -0000       1.2
***************
*** 32,35 ****
--- 32,36 ----
        // Internal state.
        internal Xsharp.Graphics graphics;
+       internal Xsharp.Font font;
  
        // Constructor.
***************
*** 38,41 ****
--- 39,43 ----
                        {
                                this.graphics = graphics;
+                               this.font = null;
                        }
  
***************
*** 153,156 ****
--- 155,179 ----
                        }
  
+       // Draw a string using the current font and brush.
+       public override void DrawString
+                               (String s, int x, int y, StringFormat format)
+                       {
+                               FontExtents extents = 
graphics.GetFontExtents(font);
+                               graphics.DrawString(x, y + extents.Ascent - 1, 
s, font);
+                       }
+ 
+       // Measure a string using the current font and a given layout rectangle.
+       public override Size MeasureString
+                               (String s, System.Drawing.Point[] 
layoutRectangle,
+                                StringFormat format, out int charactersFitted,
+                                out int linesFilled)
+                       {
+                               // TODO: line wrapping, etc
+                               int width, ascent, descent;
+                               graphics.MeasureString
+                                       (s, font, out width, out ascent, out 
descent);
+                               return new Size(width, ascent + descent);
+                       }
+ 
        // Flush the graphics subsystem
        public override void Flush(FlushIntention intention)
***************
*** 207,210 ****
--- 230,240 ----
                        {
                                // TODO
+                       }
+ 
+       // Get the line spacing for the font selected into this graphics object.
+       public override int GetLineSpacing()
+                       {
+                               FontExtents extents = 
graphics.GetFontExtents(font);
+                               return extents.Ascent + extents.Descent;
                        }
  

Index: DrawingToolkit.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Drawing.Xsharp/DrawingToolkit.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** DrawingToolkit.cs   7 Jun 2003 22:40:58 -0000       1.1
--- DrawingToolkit.cs   9 Jun 2003 21:25:37 -0000       1.2
***************
*** 26,29 ****
--- 26,31 ----
  using System.Drawing.Drawing2D;
  using System.Drawing.Toolkit;
+ using System.Drawing.Text;
+ using System.Drawing.Imaging;
  using Xsharp;
  
***************
*** 109,112 ****
--- 111,122 ----
                        }
  
+       // Create a texture brush.
+       public IToolkitBrush CreateTextureBrush
+                               (TextureBrush properties, RectangleF dstRect,
+                                ImageAttributes imageAttr)
+                       {
+                               return new DrawingTextureBrush(properties, 
dstRect, imageAttr);
+                       }
+ 
        // Create a toolkit pen from the properties in the specified object.
        // If the toolkit does not support the precise combination of pen
***************
*** 120,125 ****
        public IToolkitFont CreateFont(System.Drawing.Font font)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 130,134 ----
        public IToolkitFont CreateFont(System.Drawing.Font font)
                        {
!                               return new DrawingFont(font);
                        }
  
***************
*** 199,202 ****
--- 208,295 ----
                                return new Xsharp.Color((argb >> 16) & 0xFF,
                                                                                
(argb >> 8) & 0xFF, argb & 0xFF);
+                       }
+ 
+       // Get a list of all font families on this system, or all font
+       // families that are compatible with a particular IToolkitGraphics.
+       public FontFamily[] GetFontFamilies(IToolkitGraphics graphics)
+                       {
+                               // We only support three font families.  Extend 
later.
+                               return new FontFamily [] {
+                                       new FontFamily("Arial"),
+                                       new FontFamily("Times New Roman"),
+                                       new FontFamily("Courier New"),
+                               };
+                       }
+ 
+       // Get font family metric information.
+       public void GetFontFamilyMetrics(GenericFontFamilies genericFamily,
+                                                                        String 
name,
+                                                                        
System.Drawing.FontStyle style,
+                                                                        out 
int ascent, out int descent,
+                                                                        out 
int emHeight, out int lineSpacing)
+                       {
+                               // X doesn't have family metric information, so 
return
+                               // dummy information based on the generic font 
family.
+                               switch(genericFamily)
+                               {
+                                       case GenericFontFamilies.SansSerif:
+                                       default:
+                                       {
+                                               // Metrics for "Arial".
+                                               ascent = 1854;
+                                               descent = 434;
+                                               emHeight = 2048;
+                                               lineSpacing = 2355;
+                                       }
+                                       break;
+ 
+                                       case GenericFontFamilies.Serif:
+                                       {
+                                               // Metrics for "Times New 
Roman".
+                                               ascent = 1825;
+                                               descent = 443;
+                                               emHeight = 2048;
+                                               lineSpacing = 2355;
+                                       }
+                                       break;
+ 
+                                       case GenericFontFamilies.Monospace:
+                                       {
+                                               // Metrics for "Courier New".
+                                               ascent = 1705;
+                                               descent = 615;
+                                               emHeight = 2048;
+                                               lineSpacing = 2320;
+                                       }
+                                       break;
+                               }
+                       }
+ 
+       // Get the IToolkitFont that corresponds to a hdc's current font.
+       // Returns null if there is no way to obtain the information.
+       public IToolkitFont GetFontFromHdc(IntPtr hdc)
+                       {
+                               return null;
+                       }
+ 
+       // Get the IToolkitFont that corresponds to a native font object.
+       // Returns null if there is no way to obtain the information.
+       public IToolkitFont GetFontFromHfont(IntPtr hfont)
+                       {
+                               return null;
+                       }
+ 
+       // Get the IToolkitFont that corresponds to LOGFONT information.
+       // Returns null if there is no way to obtain the information.
+       public IToolkitFont GetFontFromLogFont(Object lf, IntPtr hdc)
+                       {
+                               return null;
+                       }
+ 
+       // Get the default IToolkitGraphics object to measure screen sizes.
+       public IToolkitGraphics GetDefaultGraphics()
+                       {
+                               return new DrawingGraphics
+                                       (this, new 
Xsharp.Graphics(placeholder));
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]