Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,85 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using awt = java.awt;
using geom = java.awt.geom;
namespace System.Drawing
{
/// <summary>
/// Summary description for BasicShape.
/// </summary>
public abstract class BasicShape : MarshalByRefObject, awt.Shape, IDisposable
{
awt.Shape _shape;
protected BasicShape(awt.Shape shape)
{
_shape = shape;
}
protected awt.Shape Shape {
get {
return _shape;
}
set {
_shape = value;
}
}
#region IDisposable
public void Dispose () {
Dispose (true);
}
void Dispose (bool disposing) {
}
#endregion
#region Shape Members
awt.Rectangle awt.Shape.getBounds() {
return Shape.getBounds();
}
bool awt.Shape.contains(double arg_0, double arg_1) {
return Shape.contains(arg_0, arg_1);
}
bool awt.Shape.contains(geom.Point2D arg_0) {
return Shape.contains(arg_0);
}
bool awt.Shape.contains(double arg_0, double arg_1, double arg_2, double arg_3) {
return Shape.contains(arg_0, arg_1, arg_2, arg_3);
}
bool awt.Shape.contains(geom.Rectangle2D arg_0) {
return Shape.contains(arg_0);
}
geom.PathIterator awt.Shape.getPathIterator(geom.AffineTransform arg_0) {
return Shape.getPathIterator(arg_0);
}
geom.PathIterator awt.Shape.getPathIterator(geom.AffineTransform arg_0, double arg_1) {
return Shape.getPathIterator(arg_0, arg_1);
}
geom.Rectangle2D awt.Shape.getBounds2D() {
return Shape.getBounds2D();
}
bool awt.Shape.intersects(double arg_0, double arg_1, double arg_2, double arg_3) {
return Shape.intersects(arg_0, arg_1, arg_2, arg_3);
}
bool awt.Shape.intersects(geom.Rectangle2D arg_0) {
return Shape.intersects(arg_0);
}
#endregion
}
}

View File

@ -0,0 +1,324 @@
//
// System.Drawing.Bitmap.cs
//
// Copyright (C) 2002 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004 Novell, Inc. http://www.novell.com
//
// Authors:
// Alexandre Pigolkine (pigolkine@gmx.de)
// Christian Meyer (Christian.Meyer@cs.tum.edu)
// Miguel de Icaza (miguel@ximian.com)
// Jordi Mas i Hernandez (jmas@softcatala.org)
// Ravindra (rkumar@novell.com)
//
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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 System.IO;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Security.Permissions;
namespace System.Drawing
{
[Serializable]
[ComVisible (true)]
[Editor ("System.Drawing.Design.BitmapEditor, " + Consts.AssemblySystem_Drawing_Design, typeof (System.Drawing.Design.UITypeEditor))]
public sealed class Bitmap : Image
{
#region constructors
// constructors
#if NET_2_0
// required for XmlSerializer (#323246)
private Bitmap ()
{
}
#endif
internal Bitmap (IntPtr ptr)
{
nativeObject = ptr;
}
// Usually called when cloning images that need to have
// not only the handle saved, but also the underlying stream
// (when using MS GDI+ and IStream we must ensure the stream stays alive for all the life of the Image)
internal Bitmap(IntPtr ptr, Stream stream)
{
// under Win32 stream is owned by SD/GDI+ code
if (GDIPlus.RunningOnWindows ())
this.stream = stream;
nativeObject = ptr;
}
public Bitmap (int width, int height) : this (width, height, PixelFormat.Format32bppArgb)
{
}
public Bitmap (int width, int height, Graphics g)
{
if (g == null)
throw new ArgumentNullException ("g");
IntPtr bmp;
Status s = GDIPlus.GdipCreateBitmapFromGraphics (width, height, g.nativeObject, out bmp);
GDIPlus.CheckStatus (s);
nativeObject = bmp;
}
public Bitmap (int width, int height, PixelFormat format)
{
IntPtr bmp;
Status s = GDIPlus.GdipCreateBitmapFromScan0 (width, height, 0, format, IntPtr.Zero, out bmp);
GDIPlus.CheckStatus (s);
nativeObject = bmp;
}
public Bitmap (Image original) : this (original, original.Width, original.Height) {}
public Bitmap (Stream stream) : this (stream, false) {}
public Bitmap (string filename) : this (filename, false) {}
public Bitmap (Image original, Size newSize) : this(original, newSize.Width, newSize.Height) {}
public Bitmap (Stream stream, bool useIcm)
{
// false: stream is owned by user code
nativeObject = InitFromStream (stream);
}
public Bitmap (string filename, bool useIcm)
{
if (filename == null)
throw new ArgumentNullException ("filename");
IntPtr imagePtr;
Status st;
if (useIcm)
st = GDIPlus.GdipCreateBitmapFromFileICM (filename, out imagePtr);
else
st = GDIPlus.GdipCreateBitmapFromFile (filename, out imagePtr);
GDIPlus.CheckStatus (st);
nativeObject = imagePtr;
}
public Bitmap (Type type, string resource)
{
if (resource == null)
throw new ArgumentException ("resource");
Stream s = type.Assembly.GetManifestResourceStream (type, resource);
if (s == null) {
string msg = Locale.GetText ("Resource '{0}' was not found.", resource);
throw new FileNotFoundException (msg);
}
nativeObject = InitFromStream (s);
// under Win32 stream is owned by SD/GDI+ code
if (GDIPlus.RunningOnWindows ())
stream = s;
}
public Bitmap (Image original, int width, int height) : this(width, height, PixelFormat.Format32bppArgb)
{
Graphics graphics = Graphics.FromImage(this);
graphics.DrawImage(original, 0, 0, width, height);
graphics.Dispose();
}
public Bitmap (int width, int height, int stride, PixelFormat format, IntPtr scan0)
{
IntPtr bmp;
Status status = GDIPlus.GdipCreateBitmapFromScan0 (width, height, stride, format, scan0, out bmp);
GDIPlus.CheckStatus (status);
nativeObject = bmp;
}
private Bitmap (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
#endregion
// methods
public Color GetPixel (int x, int y) {
int argb;
Status s = GDIPlus.GdipBitmapGetPixel(nativeObject, x, y, out argb);
GDIPlus.CheckStatus (s);
return Color.FromArgb(argb);
}
public void SetPixel (int x, int y, Color color)
{
Status s = GDIPlus.GdipBitmapSetPixel (nativeObject, x, y, color.ToArgb ());
if (s == Status.InvalidParameter) {
// check is done in case of an error only to avoid another
// unmanaged call for normal (successful) calls
if ((this.PixelFormat & PixelFormat.Indexed) != 0) {
string msg = Locale.GetText ("SetPixel cannot be called on indexed bitmaps.");
#if NET_2_0
throw new InvalidOperationException (msg);
#else
throw new Exception (msg);
#endif
}
}
GDIPlus.CheckStatus (s);
}
public Bitmap Clone (Rectangle rect, PixelFormat format)
{
IntPtr bmp;
Status status = GDIPlus.GdipCloneBitmapAreaI (rect.X, rect.Y, rect.Width, rect.Height,
format, nativeObject, out bmp);
GDIPlus.CheckStatus (status);
return new Bitmap (bmp);
}
public Bitmap Clone (RectangleF rect, PixelFormat format)
{
IntPtr bmp;
Status status = GDIPlus.GdipCloneBitmapArea (rect.X, rect.Y, rect.Width, rect.Height,
format, nativeObject, out bmp);
GDIPlus.CheckStatus (status);
return new Bitmap (bmp);
}
public static Bitmap FromHicon (IntPtr hicon)
{
IntPtr bitmap;
Status status = GDIPlus.GdipCreateBitmapFromHICON (hicon, out bitmap);
GDIPlus.CheckStatus (status);
return new Bitmap (bitmap);
}
public static Bitmap FromResource (IntPtr hinstance, string bitmapName) //TODO: Untested
{
IntPtr bitmap;
Status status = GDIPlus.GdipCreateBitmapFromResource (hinstance, bitmapName, out bitmap);
GDIPlus.CheckStatus (status);
return new Bitmap (bitmap);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
public IntPtr GetHbitmap ()
{
return GetHbitmap(Color.Gray);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
public IntPtr GetHbitmap (Color background)
{
IntPtr HandleBmp;
Status status = GDIPlus.GdipCreateHBITMAPFromBitmap (nativeObject, out HandleBmp, background.ToArgb ());
GDIPlus.CheckStatus (status);
return HandleBmp;
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
public IntPtr GetHicon ()
{
IntPtr HandleIcon;
Status status = GDIPlus.GdipCreateHICONFromBitmap (nativeObject, out HandleIcon);
GDIPlus.CheckStatus (status);
return HandleIcon;
}
public BitmapData LockBits (Rectangle rect, ImageLockMode flags, PixelFormat format)
{
BitmapData result = new BitmapData();
return LockBits (rect, flags, format, result);
}
#if NET_2_0
public
#endif
BitmapData LockBits (Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
{
Status status = GDIPlus.GdipBitmapLockBits (nativeObject, ref rect, flags, format, bitmapData);
//NOTE: scan0 points to piece of memory allocated in the unmanaged space
GDIPlus.CheckStatus (status);
return bitmapData;
}
public void MakeTransparent ()
{
Color clr = GetPixel(0,0);
MakeTransparent (clr);
}
public void MakeTransparent (Color transparentColor)
{
// We have to draw always over a 32-bitmap surface that supports alpha channel
Bitmap bmp = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
Graphics gr = Graphics.FromImage(bmp);
Rectangle destRect = new Rectangle(0, 0, Width, Height);
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorKey(transparentColor, transparentColor);
gr.DrawImage (this, destRect, 0, 0, Width, Height, GraphicsUnit.Pixel, imageAttr);
IntPtr oldBmp = nativeObject;
nativeObject = bmp.nativeObject;
bmp.nativeObject = oldBmp;
gr.Dispose();
bmp.Dispose();
imageAttr.Dispose();
}
public void SetResolution (float xDpi, float yDpi)
{
Status status = GDIPlus.GdipBitmapSetResolution (nativeObject, xDpi, yDpi);
GDIPlus.CheckStatus (status);
}
public void UnlockBits (BitmapData bitmapdata)
{
Status status = GDIPlus.GdipBitmapUnlockBits (nativeObject, bitmapdata);
GDIPlus.CheckStatus (status);
}
}
}

View File

@ -0,0 +1,427 @@
using System;
using System.IO;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using Mainsoft.Drawing.Imaging;
using io = java.io;
using imageio = javax.imageio;
using stream = javax.imageio.stream;
using spi = javax.imageio.spi;
using BufferedImage = java.awt.image.BufferedImage;
using JavaImage = java.awt.Image;
using awt = java.awt;
using image = java.awt.image;
namespace System.Drawing
{
public sealed class Bitmap : Image {
# region Static fields
static readonly image.ColorModel _jpegColorModel = new image.DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
#endregion
#region constructors
Bitmap (PlainImage orig) {
base.Initialize( orig, false );
}
[MonoTODO]
private Bitmap (SerializationInfo info, StreamingContext context) {
throw new NotImplementedException ();
}
public Bitmap (int width, int height, Graphics g)
:this (width, height, PixelFormat.Format32bppArgb) {
CurrentImage.HorizontalResolution = g.DpiX;
CurrentImage.VerticalResolution = g.DpiY;
}
public Bitmap (Image original)
:this (original, original.Size) {}
public Bitmap (Image orig, Size newSize)
:this (orig, newSize.Width, newSize.Height) {}
public Bitmap (Image orig, int width, int height)
:base (CreateScaledImage (orig, width, height), ImageFormat.MemoryBmp) {}
internal Bitmap (java.awt.Image nativeObject, ImageFormat format)
:base (nativeObject, format) {}
[MonoTODO]
private Bitmap (java.awt.Image nativeObject, ImageFormat format, PixelFormat pixFormat)
:this (nativeObject, format) {
if (pixFormat != this.PixelFormat)
throw new NotImplementedException ("Converting PixelFormat is not implemented yet.");
}
public Bitmap (int width, int height)
:this (width, height, PixelFormat.Format32bppArgb) {}
public Bitmap (int width, int height, PixelFormat format)
:base (
new java.awt.image.BufferedImage (width, height,
ToBufferedImageFormat (format)),
ImageFormat.Bmp) {
}
public Bitmap (Stream stream)
:this (stream, false) {}
public Bitmap (string filename)
:this (filename, false) {}
[MonoTODO]
public Bitmap (Stream stream, bool useIcm)
:this (stream, useIcm, null) {}
[MonoTODO]
public Bitmap (string filename, bool useIcm)
:this (filename, useIcm, null) {}
internal Bitmap (Stream stream, bool useIcm, ImageFormat format) {
// TBD: useIcm param
io.InputStream jis = vmw.common.IOUtils.ToInputStream (stream);
Initialize (new stream.MemoryCacheImageInputStream (jis), format);
}
internal Bitmap (string filename, bool useIcm, ImageFormat format) {
using(FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
// TBD: useIcm param
io.InputStream jis = vmw.common.IOUtils.ToInputStream (stream);
Initialize (new stream.MemoryCacheImageInputStream (jis), format);
}
}
public Bitmap (Type type, string resource) {
using (Stream s = type.Assembly.GetManifestResourceStream (resource)) {
if (s == null)
throw new ArgumentException("Resource '" + resource + "' could not be found in class '" + type.ToString() + "'");
io.InputStream jis = vmw.common.IOUtils.ToInputStream (s);
Initialize (new stream.MemoryCacheImageInputStream (jis), null);
}
}
#if INTPTR_SUPPORT
[MonoTODO]
public Bitmap (int width, int height, int stride, PixelFormat format, IntPtr scan0)
{
throw new NotImplementedException();
}
#endif
#endregion
#region Internal Initialization
private void Initialize (stream.ImageInputStream input, ImageFormat format) {
ImageCodec ic = null;
if (format == null)
ic = ImageCodec.CreateReader(input);
else
ic = ImageCodec.CreateReader(format);
if (ic == null)
throw new ArgumentException ("Parameter is not valid.");
try {
ic.NativeStream = input;
PlainImage pi = ic.ReadPlainImage();
base.Initialize( pi, false );
pi = ic.ReadNextPlainImage();
while ( pi != null) {
base.Initialize( pi, true );
pi = ic.ReadNextPlainImage();
}
_flags |= (int)(ImageFlags.ImageFlagsReadOnly | ImageFlags.ImageFlagsHasRealPixelSize);
}
catch (IOException ex) {
throw ex;
}
finally {
ic.Dispose();
}
}
#endregion
#region InternalSave
protected override void InternalSave (stream.ImageOutputStream output, Guid clsid) {
ImageCodec ic = ImageCodec.CreateWriter( clsid );
using (ic) {
PlainImage plainImage = CurrentImage;
plainImage.NativeImage.flush();
if ( ImageCodec.ClsidToImageFormat( clsid ).Equals( ImageFormat.Jpeg ) ) {
image.ColorModel cm = ((image.BufferedImage)CurrentImage.NativeImage).getColorModel();
if (cm.hasAlpha()) {
if (cm is image.DirectColorModel) {
image.Raster raster = ((image.BufferedImage)CurrentImage.NativeImage).getRaster();
image.DataBuffer db = raster.getDataBuffer();
image.DirectColorModel dcm = (image.DirectColorModel)cm;
image.SinglePixelPackedSampleModel jpegSampleModel = new image.SinglePixelPackedSampleModel(
db.getDataType(), Width, Height,
new int[] {dcm.getRedMask(), dcm.getGreenMask(), dcm.getBlueMask()} );
image.BufferedImage tb = new image.BufferedImage(
_jpegColorModel,
image.Raster.createWritableRaster( jpegSampleModel, db, null ),
false, null );
plainImage = new PlainImage( tb, plainImage.Thumbnails, ImageFormat.Jpeg, plainImage.HorizontalResolution, plainImage.VerticalResolution, plainImage.Dimension );
plainImage.NativeMetadata = plainImage.NativeMetadata;
}
}
}
ic.NativeStream = output;
ic.WritePlainImage( plainImage );
}
}
#endregion
#region private statics: ToBufferedImageFormat, CreateScaledImage
private static int ToBufferedImageFormat (PixelFormat format) {
switch(format) {
case PixelFormat.Format16bppGrayScale:
return BufferedImage.TYPE_USHORT_GRAY;
case PixelFormat.Format1bppIndexed:
return BufferedImage.TYPE_BYTE_GRAY;
case PixelFormat.Format32bppArgb:
return BufferedImage.TYPE_INT_ARGB;
case PixelFormat.Format32bppRgb:
return BufferedImage.TYPE_INT_RGB;
case PixelFormat.Format32bppPArgb:
return BufferedImage.TYPE_INT_ARGB_PRE;
case PixelFormat.Format16bppRgb555:
return BufferedImage.TYPE_USHORT_555_RGB;
case PixelFormat.Format16bppRgb565:
return BufferedImage.TYPE_USHORT_565_RGB;
case PixelFormat.Indexed:
return BufferedImage.TYPE_BYTE_INDEXED;
default:
return BufferedImage.TYPE_INT_ARGB;
}
}
private static java.awt.Image CreateScaledImage(Image original, int width, int height) {
JavaImage oldscaled = original.CurrentImage.NativeImage.getScaledInstance(width, height,
JavaImage.SCALE_DEFAULT);
BufferedImage newimage = new BufferedImage(oldscaled.getWidth(null),
oldscaled.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics2D graphics2d = newimage.createGraphics();
graphics2d.drawImage(oldscaled, 0, 0, null);
graphics2d.dispose();
return newimage;
}
#endregion
#region Get-SetPixel
public Color GetPixel (int x, int y)
{
int argb = NativeObject.getRGB(x,y);
return Color.FromArgb(argb);
}
public void SetPixel (int x, int y, Color color)
{
int rgb = color.ToArgb();
NativeObject.setRGB(x,y,rgb);
}
#endregion
#region Clone
public override object Clone () {
return new Bitmap ( (PlainImage)CurrentImage.Clone() );
}
public Bitmap Clone (Rectangle rect, PixelFormat pixFormat)
{
return Clone(new RectangleF( rect.X, rect.Y, rect.Width, rect.Height ), pixFormat);
}
public Bitmap Clone (RectangleF rect, PixelFormat pixFormat)
{
PlainImage plainImage = CurrentImage.Clone(false);
BufferedImage clone = new BufferedImage( (int)rect.Width, (int)rect.Height, ToBufferedImageFormat( pixFormat ) );
awt.Graphics2D g = clone.createGraphics();
try {
g.drawImage( NativeObject, -(int)rect.X, -(int)rect.Y, null );
}
finally {
g.dispose();
}
plainImage.NativeImage = clone;
return new Bitmap(plainImage);
}
#endregion
#region LockBits
[MonoTODO]
public BitmapData LockBits (Rectangle rect, ImageLockMode flags, PixelFormat format) {
throw new NotImplementedException();
}
#if NET_2_0
public
#endif
BitmapData LockBits (Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData) {
throw new NotImplementedException();
}
#endregion
#region MakeTransparent
public void MakeTransparent ()
{
Color clr = Color.FromArgb(0,0,0);
MakeTransparent (clr);
}
public void MakeTransparent (Color transparentColor)
{
image.WritableRaster raster = NativeObject.getRaster();
int numBands = raster.getNumBands();
if (numBands != 4)
return;
int maxWidth = raster.getWidth() + raster.getMinX();
int maxHeight = raster.getHeight() + raster.getMinY();
int[] srcPix = new int[numBands];
for (int y = raster.getMinY(); y < maxHeight; y++) {
for (int x = raster.getMinX(); x < maxWidth; x++) {
/*srcPix =*/ raster.getPixel(x, y, srcPix);
if (srcPix[0] == transparentColor.R &&
srcPix[1] == transparentColor.G &&
srcPix[2] == transparentColor.B) {
srcPix[3] = 0;
raster.setPixel(x, y, srcPix);
}
}
}
}
#endregion
#region SetResolution
public void SetResolution (float xDpi, float yDpi)
{
CurrentImage.HorizontalResolution = xDpi;
CurrentImage.VerticalResolution = yDpi;
}
#endregion
#region UnlockBits
[MonoTODO]
public void UnlockBits (BitmapData bitmap_data)
{
throw new NotImplementedException();
}
#endregion
#region NativeObject
internal new BufferedImage NativeObject {
get {
return (BufferedImage)base.NativeObject.CurrentImage.NativeImage;
}
}
protected override java.awt.Image[] CloneNativeObjects(java.awt.Image[] src) {
if (src == null)
return null;
awt.Image[] dst = new awt.Image[src.Length];
for (int i = 0; i < dst.Length; i++) {
BufferedImage image = src[i] as BufferedImage;
if (image == null)
throw new ArgumentException(String.Format("Unsupported image type '{0}'", src[i].ToString()), "src");
dst[i] = new BufferedImage(image.getColorModel(), image.copyData(null), image.isAlphaPremultiplied(), null);
}
return dst;
}
#endregion
#region InternalPixelFormat
protected override PixelFormat InternalPixelFormat {
get {
int t = NativeObject.getType();
switch(t) {
case 11://JavaImage.TYPE_USHORT_GRAY:
return PixelFormat.Format16bppGrayScale;
case 10://JavaImage.TYPE_BYTE_GRAY:
return PixelFormat.Format8bppIndexed;
case 1: //JavaImage.TYPE_INT_RGB
return PixelFormat.Format32bppRgb;
case 2: //JavaImage.TYPE_INT_ARGB:
return PixelFormat.Format32bppArgb;
case 3://JavaImage.TYPE_INT_ARGB_PRE:
return PixelFormat.Format32bppPArgb;
case 9://JavaImage.TYPE_USHORT_555_RGB:
return PixelFormat.Format16bppRgb555;
case 8://JavaImage.TYPE_USHORT_565_RGB:
return PixelFormat.Format16bppRgb565;
case 13://JavaImage.TYPE_BYTE_INDEXED:
return PixelFormat.Indexed;
//TBD: support this
case 12://JavaImage.TYPE_BYTE_BINARY:
case 0://JavaImage.TYPE_CUSTOM:
case 4://JavaImage.TYPE_INT_BGR:
case 5://JavaImage.TYPE_3BYTE_BGR:
case 6://JavaImage.TYPE_4BYTE_ABGR:
case 7://JavaImage.TYPE_4BYTE_ABGR_PRE:
default:
return PixelFormat.Undefined;
}
}
}
#endregion
#if INTPTR_SUPPORT
[MonoTODO]
public static Bitmap FromHicon (IntPtr hicon)
{
throw new NotImplementedException();
}
[MonoTODO]
public static Bitmap FromResource (IntPtr hinstance, string bitmapName) //TBD: Untested
{
throw new NotImplementedException();
}
[MonoTODO]
public IntPtr GetHbitmap ()
{
throw new NotImplementedException();
}
[MonoTODO]
public IntPtr GetHbitmap (Color background)
{
throw new NotImplementedException();
}
[MonoTODO]
public IntPtr GetHicon ()
{
throw new NotImplementedException();
}
#endif
}
}

View File

@ -0,0 +1,90 @@
//
// System.Drawing.Brush.cs
//
// Authors:
// Miguel de Icaza (miguel@ximian.com)
// Ravindra (rkumar@novell.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Drawing {
public abstract class Brush : MarshalByRefObject, ICloneable, IDisposable {
internal IntPtr nativeObject;
abstract public object Clone ();
internal Brush (IntPtr ptr)
{
nativeObject = ptr;
}
internal IntPtr NativeObject {
get {
return nativeObject;
}
set {
nativeObject = value;
}
}
#if NET_2_0
protected Brush ()
{
}
protected internal void SetNativeBrush (IntPtr brush)
{
nativeObject = brush;
}
#else
internal Brush ()
{
}
#endif
public void Dispose ()
{
Dispose (true);
System.GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
// NOTE: this has been known to fail in the past (cairo)
// but it's the only way to reclaim brush related memory
if (nativeObject != IntPtr.Zero) {
Status status = GDIPlus.GdipDeleteBrush (nativeObject);
nativeObject = IntPtr.Zero;
GDIPlus.CheckStatus (status);
}
}
~Brush ()
{
Dispose (false);
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using awt = java.awt;
using image = java.awt.image;
using geom = java.awt.geom;
namespace System.Drawing
{
public abstract class Brush : MarshalByRefObject, ICloneable, IDisposable, awt.Paint {
#region fields
private Matrix _brushTransform = new Matrix();
#endregion
protected abstract java.awt.Paint NativeObject {
get;
}
awt.PaintContext awt.Paint.createContext (image.ColorModel cm,
awt.Rectangle deviceBounds, geom.Rectangle2D userBounds, geom.AffineTransform xform,
awt.RenderingHints hints) {
return createContextInternal(cm, deviceBounds, userBounds, xform, hints);
}
protected virtual awt.PaintContext createContextInternal (image.ColorModel cm,
awt.Rectangle deviceBounds, geom.Rectangle2D userBounds, geom.AffineTransform xform,
awt.RenderingHints hints) {
Matrix.Multiply(xform, _brushTransform.NativeObject, MatrixOrder.Append);
return NativeObject.createContext (cm, deviceBounds, userBounds, xform, hints);
}
int awt.Transparency.getTransparency () {
return NativeObject.getTransparency ();
}
abstract public object Clone ();
public void Dispose () {
Dispose (true);
}
protected virtual void Dispose (bool disposing) {
}
protected Brush InternalClone() {
Brush brush = (Brush)this.MemberwiseClone();
brush._brushTransform = this._brushTransform.Clone();
return brush;
}
#region Brush transform
internal Matrix BrushTransform {
get { return _brushTransform.Clone(); }
set {
if (value == null)
throw new ArgumentNullException("matrix");
value.CopyTo( _brushTransform );
}
}
protected internal void BrushTranslateTransform (float dx, float dy) {
BrushTranslateTransform(dx, dy, MatrixOrder.Prepend);
}
protected internal void BrushTranslateTransform (float dx, float dy, MatrixOrder order) {
_brushTransform.Translate(dx,dy,order);
}
protected internal void BrushResetTransform () {
_brushTransform.Reset();
}
protected internal void BrushRotateTransform (float angle) {
BrushRotateTransform(angle, MatrixOrder.Prepend);
}
protected internal void BrushRotateTransform (float angle, MatrixOrder order) {
_brushTransform.Rotate(angle, order);
}
protected internal void BrushScaleTransform (float sx, float sy) {
BrushScaleTransform(sx, sy, MatrixOrder.Prepend);
}
protected internal void BrushScaleTransform (float sx, float sy, MatrixOrder order) {
_brushTransform.Scale(sx, sy, order);
}
protected internal void BrushMultiplyTransform (Matrix matrix) {
BrushMultiplyTransform(matrix, MatrixOrder.Prepend);
}
protected internal void BrushMultiplyTransform (Matrix matrix, MatrixOrder order) {
if (matrix == null)
throw new ArgumentNullException("matrix");
_brushTransform.Multiply(matrix, order);
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,118 @@
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Authors:
//
// Jordi Mas i Hernadez <jordimash@gmail.com>
//
//
#if NET_2_0
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Permissions;
namespace System.Drawing
{
public sealed class BufferedGraphics : IDisposable
{
private Rectangle size;
private Bitmap membmp = null;
private Graphics target = null;
private Graphics source = null;
private BufferedGraphics ()
{
}
internal BufferedGraphics (Graphics targetGraphics, Rectangle targetRectangle)
{
size = targetRectangle;
target = targetGraphics;
membmp = new Bitmap (size.Width, size.Height);
}
~BufferedGraphics ()
{
Dispose (false);
}
public Graphics Graphics {
get {
if (source == null) {
source = Graphics.FromImage (membmp);
}
return source;
}
}
public void Dispose ()
{
Dispose (true);
System.GC.SuppressFinalize (this);
}
private void Dispose (bool disposing)
{
if (disposing == false)
return;
if (membmp != null) {
membmp.Dispose ();
membmp = null;
}
if (source != null) {
source.Dispose ();
source = null;
}
target = null;
}
public void Render ()
{
Render (target);
}
public void Render (Graphics target)
{
if (target == null)
return;
target.DrawImage (membmp, size);
}
[MonoTODO ("The targetDC parameter has no equivalent in libgdiplus.")]
[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
public void Render (IntPtr targetDC)
{
throw new NotImplementedException ();
}
}
}
#endif

View File

@ -0,0 +1,87 @@
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Authors:
//
// Jordi Mas i Hernandez <jordimash@gmail.com>
//
//
#if NET_2_0
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Permissions;
namespace System.Drawing
{
public sealed class BufferedGraphicsContext : IDisposable
{
private Size max_buffer;
public BufferedGraphicsContext ()
{
max_buffer = Size.Empty;
}
~BufferedGraphicsContext ()
{
}
public BufferedGraphics Allocate (Graphics targetGraphics, Rectangle targetRectangle)
{
BufferedGraphics graphics = new BufferedGraphics (targetGraphics, targetRectangle);
return graphics;
}
[MonoTODO ("The targetDC parameter has no equivalent in libgdiplus.")]
[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
public BufferedGraphics Allocate (IntPtr targetDC, Rectangle targetRectangle)
{
throw new NotImplementedException ();
}
public void Dispose ()
{
System.GC.SuppressFinalize (this);
}
public void Invalidate ()
{
}
public Size MaximumBuffer {
get {return max_buffer; }
set {
if (value.Width <= 0 || value.Height <= 0) {
throw new ArgumentException ("The height or width of the size is less than or equal to zero.");
}
max_buffer = value;
}
}
}
}
#endif

View File

@ -0,0 +1,52 @@
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Authors:
//
// Jordi Mas i Hernadez <jordimash@gmail.com>
//
//
#if NET_2_0
namespace System.Drawing
{
public sealed class BufferedGraphicsManager
{
private static BufferedGraphicsContext graphics_context;
static BufferedGraphicsManager ()
{
graphics_context = new BufferedGraphicsContext ();
}
private BufferedGraphicsManager ()
{
}
public static BufferedGraphicsContext Current {
get { return graphics_context; }
}
}
}
#endif

View File

@ -0,0 +1 @@
3f744aa254fb0a42f54ccd43ccec505a28658bd0

View File

@ -0,0 +1,89 @@
//
// System.Windows.Drawing.CharacterRange.cs
//
// Authors:
// Dennis Hayes (dennish@raytek.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2002 Ximian, Inc http://www.ximian.com
// Copyright (C) 2004, 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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 System;
namespace System.Drawing
{
public struct CharacterRange
{
private int first;
private int length;
public CharacterRange (int First, int Length)
{
this.first = First;
this.length = Length;
}
public int First {
get {
return first;
}
set {
first = value;
}
}
public int Length {
get {
return length;
}
set {
length = value;
}
}
#if NET_2_0
public override bool Equals (object obj)
{
if (!(obj is CharacterRange))
return false;
CharacterRange cr = (CharacterRange) obj;
return this == cr;
}
public override int GetHashCode ()
{
return (first ^ length);
}
public static bool operator == (CharacterRange cr1, CharacterRange cr2)
{
return ((cr1.first == cr2.first) && (cr1.length == cr2.length));
}
public static bool operator != (CharacterRange cr1, CharacterRange cr2)
{
return ((cr1.first != cr2.first) || (cr1.length != cr2.length));
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,258 @@
//
// System.Drawing.ColorConverter
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Ravindra (rkumar@novell.com)
//
// Copyright (C) 2002 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004,2006,2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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 System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Text;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
namespace System.Drawing
{
public class ColorConverter : TypeConverter
{
static StandardValuesCollection cached;
static object creatingCached = new object ();
public ColorConverter () { }
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof (string))
return true;
return base.CanConvertFrom (context, sourceType);
}
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof (InstanceDescriptor))
return true;
return base.CanConvertTo (context, destinationType);
}
internal static Color StaticConvertFromString (ITypeDescriptorContext context, string s, CultureInfo culture)
{
if (culture == null)
culture = CultureInfo.InvariantCulture;
s = s.Trim ();
if (s.Length == 0)
return Color.Empty;
// Try to process both NamedColor and SystemColors from the KnownColor enumeration
if (Char.IsLetter (s [0])) {
KnownColor kc;
try {
kc = (KnownColor) Enum.Parse (typeof (KnownColor), s, true);
}
catch (Exception e) {
// whatever happens MS throws an basic Exception
string msg = Locale.GetText ("Invalid color name '{0}'.", s);
throw new Exception (msg, new FormatException (msg, e));
}
return KnownColors.FromKnownColor (kc);
}
String numSeparator = culture.TextInfo.ListSeparator;
Color result = Color.Empty;
if (s.IndexOf (numSeparator) == -1) {
bool sharp = (s[0] == '#');
int start = sharp ? 1 : 0;
bool hex = false;
// deal with #hex, 0xhex and #0xhex
if ((s.Length > start + 1) && (s[start] == '0')) {
hex = ((s[start + 1] == 'x') || (s[start + 1] == 'X'));
if (hex)
start += 2;
}
if (sharp || hex) {
s = s.Substring (start);
int argb;
try {
argb = Int32.Parse (s, NumberStyles.HexNumber);
}
catch (Exception e) {
// whatever happens MS throws an basic Exception
string msg = Locale.GetText ("Invalid Int32 value '{0}'.", s);
throw new Exception (msg, e);
}
// note that the default alpha value for a 6 hex digit (i.e. when none are present) is
// 0xFF while shorter string defaults to 0xFF - unless both # an 0x are specified
if ((s.Length < 6) || ((s.Length == 6) && sharp && hex))
argb &= 0x00FFFFFF;
else if ((argb >> 24) == 0)
argb |= unchecked((int)0xFF000000);
result = Color.FromArgb (argb);
}
}
if (result.IsEmpty) {
Int32Converter converter = new Int32Converter ();
String [] components = s.Split (numSeparator.ToCharArray ());
// MS seems to convert the indivual component to int before
// checking the number of components
int[] numComponents = new int[components.Length];
for (int i = 0; i < numComponents.Length; i++) {
numComponents[i] = (int) converter.ConvertFrom (context,
culture, components[i]);
}
switch (components.Length) {
case 1:
result = Color.FromArgb (numComponents[0]);
break;
case 3:
result = Color.FromArgb (numComponents[0], numComponents[1],
numComponents[2]);
break;
case 4:
result = Color.FromArgb (numComponents[0], numComponents[1],
numComponents[2], numComponents[3]);
break;
default:
throw new ArgumentException (s + " is not a valid color value.");
}
}
if (!result.IsEmpty) {
// Look for a named or system color with those values
Color known = KnownColors.FindColorMatch (result);
if (!known.IsEmpty)
return known;
}
return result;
}
public override object ConvertFrom (ITypeDescriptorContext context,
CultureInfo culture,
object value)
{
string s = value as string;
if (s == null)
return base.ConvertFrom (context, culture, value);
return StaticConvertFromString (context, s, culture);
}
public override object ConvertTo (ITypeDescriptorContext context,
CultureInfo culture,
object value,
Type destinationType)
{
if (value is Color) {
Color color = (Color) value;
if (destinationType == typeof (string)) {
if (color == Color.Empty)
return string.Empty;
if (color.IsKnownColor || color.IsNamedColor)
return color.Name;
String numSeparator = culture.TextInfo.ListSeparator;
StringBuilder sb = new StringBuilder ();
if (color.A != 255) {
sb.Append (color.A);
sb.Append (numSeparator);
sb.Append (" ");
}
sb.Append (color.R);
sb.Append (numSeparator);
sb.Append (" ");
sb.Append (color.G);
sb.Append (numSeparator);
sb.Append (" ");
sb.Append (color.B);
return sb.ToString ();
} else if (destinationType == typeof (InstanceDescriptor)) {
if (color.IsEmpty) {
return new InstanceDescriptor (typeof (Color).GetField ("Empty"), null);
} else if (color.IsSystemColor) {
return new InstanceDescriptor (typeof (SystemColors).GetProperty (color.Name), null);
} else if (color.IsKnownColor){
return new InstanceDescriptor (typeof (Color).GetProperty (color.Name), null);
} else {
MethodInfo met = typeof(Color).GetMethod ("FromArgb", new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) } );
return new InstanceDescriptor (met, new object[] {color.A, color.R, color.G, color.B });
}
}
}
return base.ConvertTo (context, culture, value, destinationType);
}
public override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
{
lock (creatingCached) {
if (cached != null)
return cached;
#if TARGET_JVM
Color [] colors = new Color [KnownColors.Values.Length - 1];
Array.Copy (KnownColors.Values, 1, colors, 0, colors.Length);
#else
Array colors = Array.CreateInstance (typeof (Color), KnownColors.ArgbValues.Length - 1);
for (int i=1; i < KnownColors.ArgbValues.Length; i++) {
colors.SetValue (KnownColors.FromKnownColor ((KnownColor)i), i - 1);
}
#endif
Array.Sort (colors, 0, colors.Length, new CompareColors ());
cached = new StandardValuesCollection (colors);
}
return cached;
}
public override bool GetStandardValuesSupported (ITypeDescriptorContext context)
{
return true;
}
sealed class CompareColors : IComparer {
public int Compare (object x, object y)
{
return String.Compare (((Color) x).Name, ((Color) y).Name);
}
}
}
}

View File

@ -0,0 +1,190 @@
//
// System.Drawing.ColorTranslator.cs
//
// Authors:
// Dennis Hayes (dennish@raytek.com)
// Ravindra (rkumar@novell.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2001 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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 System.ComponentModel;
using System.Globalization;
namespace System.Drawing {
public sealed class ColorTranslator {
private ColorTranslator ()
{
}
public static Color FromHtml (string htmlColor)
{
if ((htmlColor == null) || (htmlColor.Length == 0))
return Color.Empty;
switch (htmlColor.ToLowerInvariant ()) {
case "buttonface":
case "threedface":
return SystemColors.Control;
case "buttonhighlight":
case "threedlightshadow":
return SystemColors.ControlLightLight;
case "buttonshadow":
return SystemColors.ControlDark;
case "captiontext":
return SystemColors.ActiveCaptionText;
case "threeddarkshadow":
return SystemColors.ControlDarkDark;
case "threedhighlight":
return SystemColors.ControlLight;
case "background":
return SystemColors.Desktop;
case "buttontext":
return SystemColors.ControlText;
case "infobackground":
return SystemColors.Info;
// special case for Color.LightGray versus html's LightGrey (#340917)
case "lightgrey":
return Color.LightGray;
}
TypeConverter converter = TypeDescriptor.GetConverter (typeof (Color));
return (Color) converter.ConvertFromString (htmlColor);
}
internal static Color FromBGR (int bgr)
{
Color result = Color.FromArgb (0xFF, (bgr & 0xFF), ((bgr >> 8) & 0xFF), ((bgr >> 16) & 0xFF));
Color known = KnownColors.FindColorMatch (result);
return (known.IsEmpty) ? result : known;
}
public static Color FromOle (int oleColor)
{
// OleColor format is BGR
return FromBGR (oleColor);
}
public static Color FromWin32 (int win32Color)
{
// Win32Color format is BGR
return FromBGR (win32Color);
}
public static string ToHtml (Color c)
{
if (c.IsEmpty)
return String.Empty;
if (c.IsSystemColor) {
KnownColor kc = c.ToKnownColor ();
switch (kc) {
case KnownColor.ActiveBorder:
case KnownColor.ActiveCaption:
case KnownColor.AppWorkspace:
case KnownColor.GrayText:
case KnownColor.Highlight:
case KnownColor.HighlightText:
case KnownColor.InactiveBorder:
case KnownColor.InactiveCaption:
case KnownColor.InactiveCaptionText:
case KnownColor.InfoText:
case KnownColor.Menu:
case KnownColor.MenuText:
case KnownColor.ScrollBar:
case KnownColor.Window:
case KnownColor.WindowFrame:
case KnownColor.WindowText:
return KnownColors.GetName (kc).ToLower (CultureInfo.InvariantCulture);
case KnownColor.ActiveCaptionText:
return "captiontext";
case KnownColor.Control:
return "buttonface";
case KnownColor.ControlDark:
return "buttonshadow";
case KnownColor.ControlDarkDark:
return "threeddarkshadow";
case KnownColor.ControlLight:
return "buttonface";
case KnownColor.ControlLightLight:
return "buttonhighlight";
case KnownColor.ControlText:
return "buttontext";
case KnownColor.Desktop:
return "background";
case KnownColor.HotTrack:
return "highlight";
case KnownColor.Info:
return "infobackground";
default:
return String.Empty;
}
}
if (c.IsNamedColor) {
if (c == Color.LightGray)
return "LightGrey";
else
return c.Name;
}
return FormatHtml (c.R, c.G, c.B);
}
static char GetHexNumber (int b)
{
return (char) (b > 9 ? 55 + b : 48 + b);
}
static string FormatHtml (int r, int g, int b)
{
char [] htmlColor = new char [7];
htmlColor [0] = '#';
htmlColor [1] = GetHexNumber ((r >> 4) & 15);
htmlColor [2] = GetHexNumber (r & 15);
htmlColor [3] = GetHexNumber ((g >> 4) & 15);
htmlColor [4] = GetHexNumber (g & 15);
htmlColor [5] = GetHexNumber ((b >> 4) & 15);
htmlColor [6] = GetHexNumber (b & 15);
return new string (htmlColor);
}
public static int ToOle (Color c)
{
// OleColor format is BGR, same as Win32
return ((c.B << 16) | (c.G << 8) | c.R);
}
public static int ToWin32 (Color c)
{
// Win32Color format is BGR, Same as OleColor
return ((c.B << 16) | (c.G << 8) | c.R);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,201 @@
//
// System.Drawing.ComIStreamWrapper.cs
//
// Author:
// Kornél Pál <http://www.kornelpal.hu/>
//
// Copyright (C) 2005-2008 Kornél Pál
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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 System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
#if NET_2_0
using System.Runtime.InteropServices.ComTypes;
using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;
#else
using IStream = System.Runtime.InteropServices.UCOMIStream;
#endif
namespace System.Drawing
{
// Stream to IStream wrapper for COM interop
internal sealed class ComIStreamWrapper : IStream
{
private const int STG_E_INVALIDFUNCTION = unchecked((int)0x80030001);
private readonly Stream baseStream;
private long position = -1;
internal ComIStreamWrapper(Stream stream)
{
baseStream = stream;
}
private void SetSizeToPosition()
{
if (position != -1)
{
if (position > baseStream.Length)
baseStream.SetLength(position);
baseStream.Position = position;
position = -1;
}
}
public void Read(byte[] pv, int cb, IntPtr pcbRead)
{
int read = 0;
if (cb != 0)
{
SetSizeToPosition();
read = baseStream.Read(pv, 0, cb);
}
if (pcbRead != IntPtr.Zero)
Marshal.WriteInt32(pcbRead, read);
}
public void Write(byte[] pv, int cb, IntPtr pcbWritten)
{
if (cb != 0)
{
SetSizeToPosition();
baseStream.Write(pv, 0, cb);
}
if (pcbWritten != IntPtr.Zero)
Marshal.WriteInt32(pcbWritten, cb);
}
public void Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition)
{
long length = baseStream.Length;
long newPosition;
switch ((SeekOrigin)dwOrigin)
{
case SeekOrigin.Begin:
newPosition = dlibMove;
break;
case SeekOrigin.Current:
if (position == -1)
newPosition = baseStream.Position + dlibMove;
else
newPosition = position + dlibMove;
break;
case SeekOrigin.End:
newPosition = length + dlibMove;
break;
default:
throw new ExternalException(null, STG_E_INVALIDFUNCTION);
}
if (newPosition > length)
position = newPosition;
else
{
baseStream.Position = newPosition;
position = -1;
}
if (plibNewPosition != IntPtr.Zero)
Marshal.WriteInt64(plibNewPosition, newPosition);
}
public void SetSize(long libNewSize)
{
baseStream.SetLength(libNewSize);
}
public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
byte[] buffer;
long written = 0;
int read;
int count;
if (cb != 0)
{
if (cb < 4096)
count = (int)cb;
else
count = 4096;
buffer = new byte[count];
SetSizeToPosition();
while (true)
{
if ((read = baseStream.Read(buffer, 0, count)) == 0)
break;
pstm.Write(buffer, read, IntPtr.Zero);
written += read;
if (written >= cb)
break;
if (cb - written < 4096)
count = (int)(cb - written);
}
}
if (pcbRead != IntPtr.Zero)
Marshal.WriteInt64(pcbRead, written);
if (pcbWritten != IntPtr.Zero)
Marshal.WriteInt64(pcbWritten, written);
}
public void Commit(int grfCommitFlags)
{
baseStream.Flush();
SetSizeToPosition();
}
public void Revert()
{
throw new ExternalException(null, STG_E_INVALIDFUNCTION);
}
public void LockRegion(long libOffset, long cb, int dwLockType)
{
throw new ExternalException(null, STG_E_INVALIDFUNCTION);
}
public void UnlockRegion(long libOffset, long cb, int dwLockType)
{
throw new ExternalException(null, STG_E_INVALIDFUNCTION);
}
public void Stat(out STATSTG pstatstg, int grfStatFlag)
{
pstatstg = new STATSTG();
pstatstg.cbSize = baseStream.Length;
}
public void Clone(out IStream ppstm)
{
ppstm = null;
throw new ExternalException(null, STG_E_INVALIDFUNCTION);
}
}
}

View File

@ -0,0 +1,48 @@
//
// System.Drawing.ContentAlignment.cs
//
// Author: Dennis Hayes (dennish@raytek.com)
//
// (C) 2001 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// 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 System.ComponentModel;
namespace System.Drawing {
#if ONLY_1_1
[Serializable]
#endif
[Editor ("System.Drawing.Design.ContentAlignmentEditor, " + Consts.AssemblySystem_Drawing_Design, typeof (System.Drawing.Design.UITypeEditor))]
public enum ContentAlignment {
TopLeft = 0x001,
TopCenter = 0x002,
TopRight = 0x004,
MiddleLeft = 0x010,
MiddleCenter = 0x020,
MiddleRight = 0x040,
BottomLeft = 0x100,
BottomCenter = 0x200,
BottomRight = 0x400
}
}

View File

@ -0,0 +1,59 @@
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Authors:
//
// Jordi Mas i Hernandez <jordimash@gmail.com>
//
//
#if NET_2_0
using System;
using System.Runtime.InteropServices;
namespace System.Drawing
{
[ComVisibleAttribute(true)]
public enum CopyPixelOperation {
Blackness = 0x00000042,
CaptureBlt = 0x40000000,
DestinationInvert = 0x00550009,
MergeCopy = 0x00C000CA,
MergePaint = 0x00BB0226,
NoMirrorBitmap = -2147483648,
NotSourceCopy = 0x00330008,
NotSourceErase = 0x001100A6,
PatCopy = 0x00F00021,
PatInvert = 0x005A0049,
PatPaint = 0x00FB0A09,
SourceAnd = 0x008800C6,
SourceCopy = 0x00CC0020,
SourceErase = 0x00440328,
SourceInvert = 0x00660046,
SourcePaint = 0x00EE0086,
Whiteness = 0x00FF0062,
}
}
#endif

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More