public string lfFaceName = null;
}
+ // CustomLineCap
+
+ [Test]
+ public void CreateCustomLineCap ()
+ {
+ IntPtr cap;
+
+ IntPtr path;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
+
+ // test invalid conditions for #81829
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateCustomLineCap (IntPtr.Zero, path, LineCap.Flat, 1.0f, out cap), "GdipCreateCustomLineCap-FillPath-Null");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteCustomLineCap (cap), "GdipDeleteCustomLineCap-1");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateCustomLineCap (path, IntPtr.Zero, LineCap.Flat, 1.0f, out cap), "GdipCreateCustomLineCap-StrokePath-Null");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteCustomLineCap (cap), "GdipDeleteCustomLineCap-2");
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeletePath (path), "GdipDeletePath");
+ }
+
// FontFamily
[Test]
public void DeleteFontFamily ()
Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFontFamily (font_family), "second");
}
+ [Test]
+ public void CloneFontFamily ()
+ {
+ IntPtr font_family = IntPtr.Zero;
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCloneFontFamily (IntPtr.Zero, out font_family), "GdipCloneFontFamily(null)");
+
+ GDIPlus.GdipCreateFontFamilyFromName ("Arial", IntPtr.Zero, out font_family);
+ if (font_family != IntPtr.Zero) {
+ IntPtr clone;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCloneFontFamily (font_family, out clone), "GdipCloneFontFamily(arial)");
+ Assert.IsTrue (clone != IntPtr.Zero, "clone");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFontFamily (font_family), "GdipDeleteFontFamily(arial)");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFontFamily (clone), "GdipDeleteFontFamily(clone)");
+ } else
+ Assert.Ignore ("Arial isn't available on this platform");
+ }
+
// Font
[Test]
public void CreateFont ()
Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCreateBitmapFromScan0 (-1, 10, 10, PixelFormat.Format32bppArgb, IntPtr.Zero, out bmp), "negative width");
}
+ [Test]
+ public void Format1bppIndexed_GetSetPixel ()
+ {
+ IntPtr bmp;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format1bppIndexed, IntPtr.Zero, out bmp), "GdipCreateBitmapFromScan0");
+ Assert.IsTrue (bmp != IntPtr.Zero, "bmp");
+ try {
+ int argb;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipBitmapGetPixel (bmp, 0, 0, out argb), "GdipBitmapGetPixel");
+ Assert.AreEqual (-16777216, argb, "argb");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapSetPixel (bmp, 0, 0, argb), "GdipBitmapSetPixel");
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (bmp), "GdipDisposeImage");
+ }
+ }
+
+ [Test]
+ [Category ("NotWorking")] // libgdiplus doesn't support this format
+ public void Format16bppGrayScale_GetSetPixel ()
+ {
+ IntPtr bmp;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format16bppGrayScale, IntPtr.Zero, out bmp), "GdipCreateBitmapFromScan0");
+ Assert.IsTrue (bmp != IntPtr.Zero, "bmp");
+ try {
+ int argb = 0;
+ // and MS GDI+ can get or set pixels on it
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapGetPixel (bmp, 0, 0, out argb), "GdipBitmapGetPixel");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapSetPixel (bmp, 0, 0, argb), "GdipBitmapSetPixel");
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (bmp), "GdipDisposeImage");
+ }
+ }
+
[Test]
public void Unlock ()
{
Rectangle rect = new Rectangle (2, 2, 5, 5);
Assert.AreEqual (Status.Ok, GDIPlus.GdipBitmapLockBits (bmp, ref rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb, bd), "locked");
+ Assert.AreEqual (Status.Win32Error, GDIPlus.GdipBitmapLockBits (bmp, ref rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb, bd), "second lock");
+
Assert.AreEqual (rect.Width, bd.Width, "Width");
Assert.AreEqual (rect.Height, bd.Height, "Height");
Assert.AreEqual (PixelFormat.Format24bppRgb, bd.PixelFormat, "PixelFormat");
// Graphics
[Test]
- public void Graphics ()
+ public void GdipGetImageGraphicsContext_Null ()
{
IntPtr graphics;
Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImageGraphicsContext (IntPtr.Zero, out graphics), "GdipGetImageGraphicsContext");
+ }
+
+ private void Graphics_DrawImage (IntPtr image, bool metafile)
+ {
+ IntPtr graphics;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageGraphicsContext (image, out graphics), "GdipGetImageGraphicsContext");
+ Assert.IsTrue (graphics != IntPtr.Zero, "graphics");
+
+ if (metafile) {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, Single.MinValue, Single.MaxValue), "FloatMinMax");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, Int32.MinValue, Int32.MaxValue), "IntMinMax");
+ } else {
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, Single.MinValue, Single.MaxValue), "FloatOverflow");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, 1073741888, 0), "FloatXMax");
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, 1073741889, 0), "FloatXMaxOverflow");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, 0, 1073741888), "FloatYMax");
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, 0, 1073741889), "FloatYMaxOverflow");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, -1073741888, 0), "FloatXMin");
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, -1073741889, 0), "FloatXMinOverflow");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, 0, -1073741888), "FloatYMin");
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, 0, -1073741889), "FloatYMinOverflow");
+
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, Int32.MinValue, Int32.MaxValue), "IntOverflow");
+ // the real limit of MS GDI+ is 1073741951 but differs (by a very few) from the float limit
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, 1073741824, 0), "IntXMax");
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, 1073741952, 0), "IntXMaxOverflow");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, 0, 1073741824), "IntYMax");
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, 0, 1073741952), "IntYMaxOverflow");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, -1073741824, 0), "IntXMin");
+ // the real limit of MS GDI+ is -1073741825 but int-to-float convertion in libgdiplus turns this into a -1073741824
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, -1073741899, 0), "IntXMinOverflow");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, 0, -1073741824), "IntYMin");
+ Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, 0, -1073741899), "IntYMinOverflow");
+ }
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Display, IntPtr.Zero, null, IntPtr.Zero), "Display");
+ Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Document, IntPtr.Zero, null, IntPtr.Zero), "Document");
+ Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Inch, IntPtr.Zero, null, IntPtr.Zero), "Inch");
+ Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Millimeter, IntPtr.Zero, null, IntPtr.Zero), "Millimeter");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Pixel, IntPtr.Zero, null, IntPtr.Zero), "Pixel");
+ Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Point, IntPtr.Zero, null, IntPtr.Zero), "Point");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.World, IntPtr.Zero, null, IntPtr.Zero), "World");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, (GraphicsUnit) Int32.MinValue, IntPtr.Zero, null, IntPtr.Zero), "invalid");
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDeleteGraphics (IntPtr.Zero), "GdipDeleteGraphics-null");
+ }
+
+ [Test]
+ public void Graphics_FromImage_Bitmap ()
+ {
+ IntPtr image;
+ GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
+ Assert.IsTrue (image != IntPtr.Zero, "image");
+
+ Graphics_DrawImage (image, false);
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (image), "GdipDisposeImage");
+ }
+ [Test]
+ [Category ("NotWorking")] // incomplete GdipDrawImageRectRect[I] support
+ public void Graphics_FromImage_Metafile ()
+ {
+ using (Bitmap bmp = new Bitmap (100, 100, PixelFormat.Format32bppArgb)) {
+ using (Graphics g = Graphics.FromImage (bmp)) {
+ IntPtr metafile = IntPtr.Zero;
+ IntPtr hdc = g.GetHdc ();
+ try {
+ RectangleF rect = new RectangleF (10, 20, 100, 200);
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipRecordMetafileFileName ("test-drawimage.emf", hdc, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, null, out metafile), "GdipRecordMetafileFileName");
+ Assert.IsTrue (metafile != IntPtr.Zero, "image");
+
+ Graphics_DrawImage (metafile, true);
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (metafile), "GdipDisposeImage");
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void GdipCreateFromHDC_Null ()
+ {
+ IntPtr graphics;
+ Assert.AreEqual (Status.OutOfMemory, GDIPlus.GdipCreateFromHDC (IntPtr.Zero, out graphics), "GdipCreateFromHDC(null)");
+ }
+
+ [Test]
+ public void DrawRectangles ()
+ {
IntPtr image;
GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
Assert.IsTrue (image != IntPtr.Zero, "image");
+ IntPtr graphics;
Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageGraphicsContext (image, out graphics), "GdipGetImageGraphicsContext");
Assert.IsTrue (graphics != IntPtr.Zero, "graphics");
- Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
- Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDeleteGraphics (IntPtr.Zero), "GdipDeleteGraphics-null");
+ Rectangle[] r = new Rectangle[1] { new Rectangle (1, 2, -2, -1) };
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, IntPtr.Zero, r, 1), "GdipDrawRectanglesI-PenNull");
+ RectangleF[] rf = new RectangleF[2] { new RectangleF (1, 2, -2, -1), new RectangleF (0, 0, 10, 10) };
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, IntPtr.Zero, rf, 2), "GdipDrawRectanglesI-PenNull");
+
+ IntPtr pen;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen), "GdipCreatePen1");
+ Assert.IsTrue (pen != IntPtr.Zero, "pen");
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (IntPtr.Zero, pen, r, 1), "GdipDrawRectanglesI-GraphicsNull");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (IntPtr.Zero, pen, rf, 2), "GdipDrawRectangles-GraphicsNull");
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, pen, null, 1), "GdipDrawRectanglesI-RectanglesNull");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, pen, null, 1), "GdipDrawRectangles-RectanglesNull");
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, pen, new Rectangle[0], 0), "GdipDrawRectanglesI-RectanglesEmpty");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, pen, new RectangleF[0], 0), "GdipDrawRectangles-RectanglesEmpty");
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, pen, r, -1), "GdipDrawRectanglesI-RectanglesNegative");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, pen, rf, -1), "GdipDrawRectangles-RectanglesNegative");
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawRectanglesI (graphics, pen, r, 1), "GdipDrawRectanglesI-Rectangles1");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawRectangles (graphics, pen, rf, 2), "GdipDrawRectangles-Rectangles2");
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeletePen (pen), "GdipDeletePen");
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (image), "GdipDisposeImage");
}
public void Widen ()
{
IntPtr pen;
- Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen), "GdipCreatePen1");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen), "GdipCreatePen1");
IntPtr path;
Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetImagePalette (IntPtr.Zero, palette), "GdipSetImagePalette(null,palette)");
Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetImagePalette (bitmap, IntPtr.Zero), "GdipSetImagePalette(bitmap,null)");
Assert.AreEqual (Status.Ok, GDIPlus.GdipSetImagePalette (bitmap, palette), "GdipSetImagePalette");
-
- // change palette to 0 entries
- int flags = Marshal.ReadInt32 (palette);
- Marshal.WriteInt64 (palette, flags << 32);
- Assert.AreEqual (Status.Ok, GDIPlus.GdipSetImagePalette (bitmap, palette), "GdipSetImagePalette/Empty");
-
- Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePaletteSize (bitmap, out size), "GdipGetImagePaletteSize/Empty");
- Assert.AreEqual (8, size, "size");
}
finally {
Marshal.FreeHGlobal (palette);
}
[Test]
- [ExpectedException (typeof (FileNotFoundException))]
public void GdipLoadImageFromFile_FileNotFound ()
{
string filename = "filenotfound";
Assert.AreEqual (IntPtr.Zero, image, "image handle");
// this doesn't throw a OutOfMemoryException
- Image.FromFile (filename);
+ Assert.Throws<FileNotFoundException> (() => Image.FromFile (filename));
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void GdipCreateBitmapFromFile_FileNotFound ()
{
string filename = "filenotfound";
Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCreateBitmapFromFile (filename, out bitmap), "GdipCreateBitmapFromFile");
Assert.AreEqual (IntPtr.Zero, bitmap, "bitmap handle");
- new Bitmap (filename);
+ Assert.Throws<ArgumentException> (() => new Bitmap (filename));
}
[Test]
public void CreatePen ()
{
IntPtr pen;
- Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen), "GdipCreatePen1");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen), "GdipCreatePen1");
Assert.IsTrue (pen != IntPtr.Zero, "pen");
DashStyle ds;
Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDeletePen (IntPtr.Zero), "GdipDeletePen-null");
}
+ [Test]
+ public void PenColor_81266 ()
+ {
+ IntPtr pen;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0x7f0000ff, 1f, GraphicsUnit.Pixel, out pen), "GdipCreatePen1");
+ try {
+ int color = 0;
+ IntPtr brush;
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetPenBrushFill (IntPtr.Zero, out brush), "GdipGetPenBrushFill-null");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetPenBrushFill (pen, out brush), "GdipGetPenBrushFill");
+ try {
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetSolidFillColor (IntPtr.Zero, out color), "GdipGetSolidFillColor-null");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetSolidFillColor (brush, out color), "GdipGetSolidFillColor-0");
+ Assert.AreEqual (0x7f0000ff, color, "color-0");
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetPenColor (IntPtr.Zero, 0x7fff0000), "GdipSetPenColor-null");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipSetPenColor (pen, 0x7fff0000), "GdipSetPenColor");
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetSolidFillColor (brush, out color), "GdipGetSolidFillColor-1");
+ // previous brush color didn't change
+ Assert.AreEqual (0x7f0000ff, color, "color-1");
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteBrush (brush), "GdipDeleteBrush");
+ }
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetPenBrushFill (pen, out brush), "GdipGetPenBrushFill-2");
+ try {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetSolidFillColor (brush, out color), "GdipGetSolidFillColor-2");
+ // new brush color is updated
+ Assert.AreEqual (0x7fff0000, color, "color-2");
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteBrush (brush), "GdipDeleteBrush-2");
+ }
+ }
+ finally {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipDeletePen (pen), "GdipDeletePen");
+ }
+ }
+
// Region
[Test]
public void CreateRegionRgnData ()
out image);
GDIPlus.GdipGetImageGraphicsContext (image, out graphics);
- GDIPlus.GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen);
+ GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen);
// DrawCurve
"DrawCurve with 1 pt");
Assert.AreEqual (Status.Ok,
GDIPlus.GdipDrawCurveI (graphics, pen,
- new Point [] { new Point (1, 1),
- new Point (2, 2) }, 2),
+ new Point [] { new Point (1, 1),
+ new Point (2, 2) }, 2),
"DrawCurve with 2 pts");
// DrawClosedCurve
"DrawClosedCurve with no pts");
Assert.AreEqual (Status.InvalidParameter,
GDIPlus.GdipDrawClosedCurveI (graphics, pen,
- new Point [] { new Point (1, 1) }, 1),
+ new Point [] { new Point (1, 1) }, 1),
"DrawClosedCurve with 1 pt");
Assert.AreEqual (Status.InvalidParameter,
GDIPlus.GdipDrawClosedCurveI (graphics, pen,
- new Point [] { new Point (1, 1),
- new Point (2, 2) }, 2),
+ new Point [] { new Point (1, 1),
+ new Point (2, 2) }, 2),
"DrawClosedCurve with 2 pt2");
// DrawPolygon
"DrawPolygon with no pts");
Assert.AreEqual (Status.InvalidParameter,
GDIPlus.GdipDrawPolygonI (graphics, pen,
- new Point [] { new Point (1, 1) }, 1),
+ new Point [] { new Point (1, 1) }, 1),
"DrawPolygon with only one pt");
GDIPlus.GdipDeletePen (pen);
"FillClosedCurve with no pts");
Assert.AreEqual (Status.Ok,
GDIPlus.GdipFillClosedCurveI (graphics, brush,
- new Point [] { new Point (1, 1) }, 1),
+ new Point [] { new Point (1, 1) }, 1),
"FillClosedCurve with 1 pt");
Assert.AreEqual (Status.Ok,
GDIPlus.GdipFillClosedCurveI (graphics, brush,
- new Point [] { new Point (1, 1),
- new Point (2, 2) }, 2),
+ new Point [] { new Point (1, 1),
+ new Point (2, 2) }, 2),
"FillClosedCurve with 2 pts");
GDIPlus.GdipDeleteBrush (brush);
float width, height;
Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageDimension (image, out width, out height), "GdipGetImageDimension");
- Assert.AreEqual (12976.63, width, "GdipGetImageDimension/Width");
- Assert.AreEqual (17297.99, height, "GdipGetImageDimension/Height");
+ Assert.AreEqual (12976.6328f, width, 0.001f, "GdipGetImageDimension/Width");
+ Assert.AreEqual (17297.9863f, height, 0.001f, "GdipGetImageDimension/Height");
ImageType type;
Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageType (image, out type), "GdipGetImageType");
int numbers;
Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetPropertySize (image, out size, out numbers), "GdipGetPropertySize");
Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipRemovePropertyItem (image, 0), "GdipRemovePropertyItem");
- Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipSetPropertyItem (image, image), "GdipSetPropertyItem");
+ //Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipSetPropertyItem (image, image), "GdipSetPropertyItem");
Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetAllPropertyItems (image, 1000, 1, image), "GdipGetAllPropertyItems");
Guid wmf = ImageFormat.Wmf.Guid;
Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (metafile), "GdipDisposeImage");
}
}
+
+ private void RecordFileName (IntPtr hdc, EmfType type, MetafileFrameUnit unit)
+ {
+ string filename = String.Format ("test-{0}-{1}.emf", type, unit);
+ IntPtr metafile;
+ RectangleF rect = new RectangleF (10, 20, 100, 200);
+ Status status = GDIPlus.GdipRecordMetafileFileName (filename, hdc, type, ref rect, unit, filename, out metafile);
+ if (metafile != IntPtr.Zero)
+ GDIPlus.GdipDisposeImage (metafile);
+ if (status == Status.Ok)
+ File.Delete (filename);
+ Assert.AreEqual (Status.Ok, status, filename);
+ }
+
+ private Status RecordFileName_EmptyRectangle (IntPtr hdc, MetafileFrameUnit unit)
+ {
+ string filename = String.Format ("emptyrectangle-{0}.emf", unit);
+ IntPtr metafile = IntPtr.Zero;
+ RectangleF empty = new RectangleF ();
+ Status status = GDIPlus.GdipRecordMetafileFileName (filename, hdc, EmfType.EmfPlusDual, ref empty, unit, filename, out metafile);
+ if (metafile != IntPtr.Zero)
+ GDIPlus.GdipDisposeImage (metafile);
+ if (status == Status.Ok)
+ File.Delete (filename);
+ return status;
+ }
+
+ [Test]
+ public void RecordMetafileFileName ()
+ {
+ using (Bitmap bmp = new Bitmap (100, 100, PixelFormat.Format32bppArgb)) {
+ using (Graphics g = Graphics.FromImage (bmp)) {
+ IntPtr hdc = g.GetHdc ();
+ try {
+ IntPtr metafile;
+ RectangleF rect = new RectangleF ();
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName (null, hdc, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, "unit test", out metafile), "filename-null");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName ("a.emf", IntPtr.Zero, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, "unit test", out metafile), "hdc-null");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName ("b.emf", hdc, (EmfType)Int32.MaxValue, ref rect, MetafileFrameUnit.GdiCompatible, "unit test", out metafile), "type-invalid");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName ("c.emf", hdc, EmfType.EmfPlusOnly, ref rect, (MetafileFrameUnit)Int32.MaxValue, "unit test", out metafile), "unit-invalid");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipRecordMetafileFileName ("d.emf", hdc, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, null, out metafile), "description-null");
+ GDIPlus.GdipDisposeImage (metafile);
+ File.Delete ("d.emf");
+ // test some variations
+ Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Document), "EmptyRectangle-Document");
+ Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Inch), "EmptyRectangle-Inch");
+ Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Millimeter), "EmptyRectangle-Millimeter");
+ Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Pixel), "EmptyRectangle-Pixel");
+ Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Point), "EmptyRectangle-Point");
+ Assert.AreEqual (Status.Ok, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.GdiCompatible), "EmptyRectangle-GdiCompatible");
+ RecordFileName (hdc, EmfType.EmfOnly, MetafileFrameUnit.Document);
+ RecordFileName (hdc, EmfType.EmfPlusDual, MetafileFrameUnit.GdiCompatible);
+ RecordFileName (hdc, EmfType.EmfPlusOnly, MetafileFrameUnit.Inch);
+ RecordFileName (hdc, EmfType.EmfOnly, MetafileFrameUnit.Millimeter);
+ RecordFileName (hdc, EmfType.EmfPlusDual, MetafileFrameUnit.Pixel);
+ RecordFileName (hdc, EmfType.EmfPlusOnly, MetafileFrameUnit.Point);
+ }
+ finally {
+ g.ReleaseHdc (hdc);
+ }
+ }
+ }
+ }
}
}