1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
|
//
// Metafile class unit tests
//
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 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;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using NUnit.Framework;
using MonoTests.Helpers;
namespace MonoTests.System.Drawing.Imaging {
[TestFixture]
public class MetafileTest {
public static string Bitmap = TestResourceHelper.GetFullPathOfResource ("Test/System.Drawing/bitmaps/non-inverted.bmp");
public static string WmfPlaceable = TestResourceHelper.GetFullPathOfResource ("Test/System.Drawing/bitmaps/telescope_01.wmf");
public static string Emf = TestResourceHelper.GetFullPathOfResource ("Test/System.Drawing/bitmaps/milkmateya01.emf");
[Test]
public void Metafile_Stream_Null ()
{
Assert.Throws<ArgumentException> (() => new Metafile ((Stream)null));
}
[Test]
public void Metafile_String_Null ()
{
Assert.Throws<ArgumentNullException> (() => new Metafile ((string) null));
}
[Test]
public void Metafile_String_Empty ()
{
Assert.Throws<ArgumentException> (() => new Metafile (String.Empty));
}
[Test]
public void Metafile_String_FileDoesNotExists ()
{
string filename = "non_existing.wmf";
Assert.Throws<ExternalException> (() => new Metafile (filename));
}
[Test]
public void Metafile_String ()
{
string filename = WmfPlaceable;
Metafile mf = new Metafile (filename);
Metafile clone = (Metafile) mf.Clone ();
}
[Test]
public void GetMetafileHeader_Bitmap ()
{
Assert.Throws<ExternalException> (() => new Metafile (Bitmap));
}
static public void Check_MetaHeader_WmfPlaceable (MetaHeader mh)
{
Assert.AreEqual (9, mh.HeaderSize, "HeaderSize");
Assert.AreEqual (98, mh.MaxRecord, "MaxRecord");
Assert.AreEqual (3, mh.NoObjects, "NoObjects");
Assert.AreEqual (0, mh.NoParameters, "NoParameters");
Assert.AreEqual (1737, mh.Size, "Size");
Assert.AreEqual (1, mh.Type, "Type");
Assert.AreEqual (0x300, mh.Version, "Version");
}
public static void Check_MetafileHeader_WmfPlaceable (MetafileHeader header)
{
Assert.AreEqual (MetafileType.WmfPlaceable, header.Type, "Type");
Assert.AreEqual (0x300, header.Version, "Version");
// filesize - 22, which happens to be the size (22) of a PLACEABLEMETAHEADER struct
Assert.AreEqual (3474, header.MetafileSize, "MetafileSize");
Assert.AreEqual (-30, header.Bounds.X, "Bounds.X");
Assert.AreEqual (-40, header.Bounds.Y, "Bounds.Y");
Assert.AreEqual (3096, header.Bounds.Width, "Bounds.Width");
Assert.AreEqual (4127, header.Bounds.Height, "Bounds.Height");
Assert.AreEqual (606, header.DpiX, "DpiX");
Assert.AreEqual (606, header.DpiY, "DpiY");
Assert.AreEqual (0, header.EmfPlusHeaderSize, "EmfPlusHeaderSize");
Assert.AreEqual (0, header.LogicalDpiX, "LogicalDpiX");
Assert.AreEqual (0, header.LogicalDpiY, "LogicalDpiY");
Assert.IsNotNull (header.WmfHeader, "WmfHeader");
Check_MetaHeader_WmfPlaceable (header.WmfHeader);
Assert.IsFalse (header.IsDisplay (), "IsDisplay");
Assert.IsFalse (header.IsEmf (), "IsEmf");
Assert.IsFalse (header.IsEmfOrEmfPlus (), "IsEmfOrEmfPlus");
Assert.IsFalse (header.IsEmfPlus (), "IsEmfPlus");
Assert.IsFalse (header.IsEmfPlusDual (), "IsEmfPlusDual");
Assert.IsFalse (header.IsEmfPlusOnly (), "IsEmfPlusOnly");
Assert.IsTrue (header.IsWmf (), "IsWmf");
Assert.IsTrue (header.IsWmfPlaceable (), "IsWmfPlaceable");
}
[Test]
public void GetMetafileHeader_WmfPlaceable ()
{
using (Metafile mf = new Metafile (WmfPlaceable)) {
MetafileHeader header1 = mf.GetMetafileHeader ();
Check_MetafileHeader_WmfPlaceable (header1);
MetafileHeader header2 = mf.GetMetafileHeader ();
Assert.IsFalse (Object.ReferenceEquals (header1, header2), "Same object");
}
}
[Test]
public void GetMetafileHeader_FromFile_WmfPlaceable ()
{
using (Metafile mf = new Metafile (WmfPlaceable)) {
MetafileHeader header1 = mf.GetMetafileHeader ();
Check_MetafileHeader_WmfPlaceable (header1);
MetaHeader mh1 = header1.WmfHeader;
Check_MetaHeader_WmfPlaceable (mh1);
MetaHeader mh2 = mf.GetMetafileHeader ().WmfHeader;
Assert.IsFalse (Object.ReferenceEquals (mh1, mh2), "Same object");
}
}
[Test]
public void GetMetafileHeader_FromFileStream_WmfPlaceable ()
{
using (FileStream fs = File.OpenRead (WmfPlaceable)) {
using (Metafile mf = new Metafile (fs)) {
MetafileHeader header1 = mf.GetMetafileHeader ();
Check_MetafileHeader_WmfPlaceable (header1);
MetaHeader mh1 = header1.WmfHeader;
Check_MetaHeader_WmfPlaceable (mh1);
MetaHeader mh2 = mf.GetMetafileHeader ().WmfHeader;
Assert.IsFalse (Object.ReferenceEquals (mh1, mh2), "Same object");
}
}
}
[Test]
public void GetMetafileHeader_FromMemoryStream_WmfPlaceable ()
{
MemoryStream ms;
string filename = WmfPlaceable;
using (FileStream fs = File.OpenRead (filename)) {
byte[] data = new byte[fs.Length];
fs.Read (data, 0, data.Length);
ms = new MemoryStream (data);
}
using (Metafile mf = new Metafile (ms)) {
MetafileHeader header1 = mf.GetMetafileHeader ();
Check_MetafileHeader_WmfPlaceable (header1);
MetaHeader mh1 = header1.WmfHeader;
Check_MetaHeader_WmfPlaceable (mh1);
MetaHeader mh2 = mf.GetMetafileHeader ().WmfHeader;
Assert.IsFalse (Object.ReferenceEquals (mh1, mh2), "Same object");
}
ms.Close ();
}
public static void Check_MetafileHeader_Emf (MetafileHeader header)
{
Assert.AreEqual (MetafileType.Emf, header.Type, "Type");
Assert.AreEqual (65536, header.Version, "Version");
// extactly the filesize
Assert.AreEqual (20456, header.MetafileSize, "MetafileSize");
Assert.AreEqual (0, header.Bounds.X, "Bounds.X");
Assert.AreEqual (0, header.Bounds.Y, "Bounds.Y");
#if false
Assert.AreEqual (759, header.Bounds.Width, "Bounds.Width");
Assert.AreEqual (1073, header.Bounds.Height, "Bounds.Height");
Assert.AreEqual (96f, header.DpiX, 0.5f, "DpiX");
Assert.AreEqual (96f, header.DpiY, 0.5f, "DpiY");
Assert.AreEqual (6619188, header.EmfPlusHeaderSize, "EmfPlusHeaderSize");
Assert.AreEqual (3670064, header.LogicalDpiX, "LogicalDpiX");
Assert.AreEqual (3670064, header.LogicalDpiY, "LogicalDpiY");
#endif
try {
Assert.IsNotNull (header.WmfHeader, "WmfHeader");
Assert.Fail ("WmfHeader didn't throw an ArgumentException");
}
catch (ArgumentException) {
}
catch (Exception e) {
Assert.Fail ("WmfHeader didn't throw an ArgumentException but: {0}.", e.ToString ());
}
Assert.IsFalse (header.IsDisplay (), "IsDisplay");
Assert.IsTrue (header.IsEmf (), "IsEmf");
Assert.IsTrue (header.IsEmfOrEmfPlus (), "IsEmfOrEmfPlus");
Assert.IsFalse (header.IsEmfPlus (), "IsEmfPlus");
Assert.IsFalse (header.IsEmfPlusDual (), "IsEmfPlusDual");
Assert.IsFalse (header.IsEmfPlusOnly (), "IsEmfPlusOnly");
Assert.IsFalse (header.IsWmf (), "IsWmf");
Assert.IsFalse (header.IsWmfPlaceable (), "IsWmfPlaceable");
}
[Test]
public void GetMetafileHeader_FromFile_Emf ()
{
using (Metafile mf = new Metafile (Emf)) {
MetafileHeader header1 = mf.GetMetafileHeader ();
Check_MetafileHeader_Emf (header1);
}
}
[Test]
public void GetMetafileHeader_FromFileStream_Emf ()
{
using (FileStream fs = File.OpenRead (Emf)) {
using (Metafile mf = new Metafile (fs)) {
MetafileHeader header1 = mf.GetMetafileHeader ();
Check_MetafileHeader_Emf (header1);
}
}
}
[Test]
public void GetMetafileHeader_FromMemoryStream_Emf ()
{
MemoryStream ms;
string filename = Emf;
using (FileStream fs = File.OpenRead (filename)) {
byte[] data = new byte[fs.Length];
fs.Read (data, 0, data.Length);
ms = new MemoryStream (data);
}
using (Metafile mf = new Metafile (ms)) {
MetafileHeader header1 = mf.GetMetafileHeader ();
Check_MetafileHeader_Emf (header1);
}
ms.Close ();
}
[Test]
public void Static_GetMetafileHeader_Stream_Null ()
{
Assert.Throws<NullReferenceException> (() => Metafile.GetMetafileHeader ((Stream)null));
}
[Test]
public void Static_GetMetafileHeader_Stream ()
{
string filename = WmfPlaceable;
using (FileStream fs = File.OpenRead (filename)) {
MetafileHeader header = Metafile.GetMetafileHeader (fs);
Check_MetafileHeader_WmfPlaceable (header);
}
}
[Test]
public void Static_GetMetafileHeader_Filename_Null ()
{
Assert.Throws<ArgumentNullException> (() => Metafile.GetMetafileHeader ((string) null));
}
[Test]
public void Static_GetMetafileHeader_Filename ()
{
string filename = WmfPlaceable;
MetafileHeader header = Metafile.GetMetafileHeader (filename);
Check_MetafileHeader_WmfPlaceable (header);
}
}
[TestFixture]
public class MetafileFulltrustTest {
private Font test_font;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
try {
test_font = new Font (FontFamily.GenericMonospace, 12);
}
catch (ArgumentException) {
}
}
[Test]
public void Static_GetMetafileHeader_IntPtr_Zero ()
{
Assert.Throws<ArgumentException> (() => Metafile.GetMetafileHeader (IntPtr.Zero));
}
[Test]
public void Static_GetMetafileHeader_IntPtr ()
{
string filename = MetafileTest.WmfPlaceable;
using (Metafile mf = new Metafile (filename)) {
IntPtr hemf = mf.GetHenhmetafile ();
Assert.IsTrue (hemf != IntPtr.Zero, "GetHenhmetafile");
Assert.Throws<ArgumentException> (() => Metafile.GetMetafileHeader (hemf));
}
}
[Test]
public void Metafile_IntPtrBool_Zero ()
{
Assert.Throws<ArgumentException> (() => new Metafile (IntPtr.Zero, false));
}
[Test]
public void Metafile_IntPtrEmfType_Zero ()
{
Assert.Throws<ArgumentException> (() => new Metafile (IntPtr.Zero, EmfType.EmfOnly));
}
private void CheckEmptyHeader (Metafile mf, EmfType type)
{
MetafileHeader mh = mf.GetMetafileHeader ();
Assert.AreEqual (0, mh.Bounds.X, "Bounds.X");
Assert.AreEqual (0, mh.Bounds.Y, "Bounds.Y");
Assert.AreEqual (0, mh.Bounds.Width, "Bounds.Width");
Assert.AreEqual (0, mh.Bounds.Height, "Bounds.Height");
Assert.AreEqual (0, mh.MetafileSize, "MetafileSize");
switch (type) {
case EmfType.EmfOnly:
Assert.AreEqual (MetafileType.Emf, mh.Type, "Type");
break;
case EmfType.EmfPlusDual:
Assert.AreEqual (MetafileType.EmfPlusDual, mh.Type, "Type");
break;
case EmfType.EmfPlusOnly:
Assert.AreEqual (MetafileType.EmfPlusOnly, mh.Type, "Type");
break;
default:
Assert.Fail ("Unknown EmfType '{0}'", type);
break;
}
}
private void Metafile_IntPtrEmfType (EmfType type)
{
using (Bitmap bmp = new Bitmap (10, 10, PixelFormat.Format32bppArgb)) {
using (Graphics g = Graphics.FromImage (bmp)) {
IntPtr hdc = g.GetHdc ();
try {
Metafile mf = new Metafile (hdc, type);
CheckEmptyHeader (mf, type);
}
finally {
g.ReleaseHdc (hdc);
}
}
}
}
[Test]
public void Metafile_IntPtrEmfType_Invalid ()
{
Assert.Throws<ArgumentException> (() => Metafile_IntPtrEmfType ((EmfType)Int32.MinValue));
}
[Test]
public void Metafile_IntPtrEmfType_EmfOnly ()
{
Metafile_IntPtrEmfType (EmfType.EmfOnly);
}
[Test]
public void Metafile_IntPtrEmfType_EmfPlusDual ()
{
Metafile_IntPtrEmfType (EmfType.EmfPlusDual);
}
[Test]
public void Metafile_IntPtrEmfType_EmfPlusOnly ()
{
Metafile_IntPtrEmfType (EmfType.EmfPlusOnly);
}
[Test]
public void Metafile_IntPtrRectangle_Zero ()
{
Assert.Throws<ArgumentException> (() => new Metafile (IntPtr.Zero, new Rectangle (1, 2, 3, 4)));
}
[Test]
public void Metafile_IntPtrRectangle_Empty ()
{
using (Bitmap bmp = new Bitmap (10, 10, PixelFormat.Format32bppArgb)) {
using (Graphics g = Graphics.FromImage (bmp)) {
IntPtr hdc = g.GetHdc ();
try {
Metafile mf = new Metafile (hdc, new Rectangle ());
CheckEmptyHeader (mf, EmfType.EmfPlusDual);
}
finally {
g.ReleaseHdc (hdc);
}
}
}
}
[Test]
public void Metafile_IntPtrRectangleF_Zero ()
{
Assert.Throws<ArgumentException> (() => new Metafile (IntPtr.Zero, new RectangleF (1, 2, 3, 4)));
}
[Test]
public void Metafile_IntPtrRectangleF_Empty ()
{
using (Bitmap bmp = new Bitmap (10, 10, PixelFormat.Format32bppArgb)) {
using (Graphics g = Graphics.FromImage (bmp)) {
IntPtr hdc = g.GetHdc ();
try {
Metafile mf = new Metafile (hdc, new RectangleF ());
CheckEmptyHeader (mf, EmfType.EmfPlusDual);
}
finally {
g.ReleaseHdc (hdc);
}
}
}
}
private void Metafile_StreamEmfType (Stream stream, EmfType type)
{
using (Bitmap bmp = new Bitmap (10, 10, PixelFormat.Format32bppArgb)) {
using (Graphics g = Graphics.FromImage (bmp)) {
IntPtr hdc = g.GetHdc ();
try {
Metafile mf = new Metafile (stream, hdc, type);
CheckEmptyHeader (mf, type);
}
finally {
g.ReleaseHdc (hdc);
}
}
}
}
[Test]
public void Metafile_StreamIntPtrEmfType_Null ()
{
Assert.Throws<NullReferenceException> (() => Metafile_StreamEmfType (null, EmfType.EmfOnly));
}
[Test]
public void Metafile_StreamIntPtrEmfType_EmfOnly ()
{
using (MemoryStream ms = new MemoryStream ()) {
Metafile_StreamEmfType (ms, EmfType.EmfOnly);
}
}
[Test]
public void Metafile_StreamIntPtrEmfType_Invalid ()
{
using (MemoryStream ms = new MemoryStream ()) {
Assert.Throws<ArgumentException> (() => Metafile_StreamEmfType (ms, (EmfType)Int32.MinValue));
}
}
private void CreateFilename (EmfType type, bool single)
{
string name = String.Format ("{0}-{1}.emf", type, single ? "Single" : "Multiple");
string filename = Path.Combine (Path.GetTempPath (), name);
Metafile mf;
using (Bitmap bmp = new Bitmap (100, 100, PixelFormat.Format32bppArgb)) {
using (Graphics g = Graphics.FromImage (bmp)) {
IntPtr hdc = g.GetHdc ();
try {
mf = new Metafile (filename, hdc, type);
Assert.AreEqual (0, new FileInfo (filename).Length, "Empty");
}
finally {
g.ReleaseHdc (hdc);
}
}
long size = 0;
using (Graphics g = Graphics.FromImage (mf)) {
g.FillRectangle (Brushes.BlueViolet, 10, 10, 80, 80);
size = new FileInfo (filename).Length;
Assert.AreEqual (0, size, "Still-Empty");
}
// FIXME / doesn't work on mono yet
// size = new FileInfo (filename).Length;
// Assert.IsTrue (size > 0, "Non-Empty/GraphicsDisposed");
if (!single) {
// can we append stuff ?
using (Graphics g = Graphics.FromImage (mf)) {
g.DrawRectangle (Pens.Azure, 10, 10, 80, 80);
// happily no :)
}
}
mf.Dispose ();
Assert.AreEqual (size, new FileInfo (filename).Length, "Non-Empty/MetafileDisposed");
}
}
[Test]
public void CreateFilename_SingleGraphics_EmfOnly ()
{
CreateFilename (EmfType.EmfOnly, true);
}
[Test]
public void CreateFilename_SingleGraphics_EmfPlusDual ()
{
CreateFilename (EmfType.EmfPlusDual, true);
}
[Test]
public void CreateFilename_SingleGraphics_EmfPlusOnly ()
{
CreateFilename (EmfType.EmfPlusOnly, true);
}
[Test]
public void CreateFilename_MultipleGraphics_EmfOnly ()
{
Assert.Throws<OutOfMemoryException> (() => CreateFilename (EmfType.EmfOnly, false));
}
[Test]
public void CreateFilename_MultipleGraphics_EmfPlusDual ()
{
Assert.Throws<OutOfMemoryException> (() => CreateFilename (EmfType.EmfPlusDual, false));
}
[Test]
public void CreateFilename_MultipleGraphics_EmfPlusOnly ()
{
Assert.Throws<OutOfMemoryException> (() => CreateFilename (EmfType.EmfPlusOnly, false));
}
[Test]
public void Measure ()
{
if (test_font == null)
Assert.Ignore ("No font family could be found.");
Metafile mf;
using (Bitmap bmp = new Bitmap (100, 100, PixelFormat.Format32bppArgb)) {
using (Graphics g = Graphics.FromImage (bmp)) {
IntPtr hdc = g.GetHdc ();
try {
mf = new Metafile (hdc, EmfType.EmfPlusOnly);
}
finally {
g.ReleaseHdc (hdc);
}
}
using (Graphics g = Graphics.FromImage (mf)) {
string text = "this\nis a test";
CharacterRange[] ranges = new CharacterRange[2];
ranges[0] = new CharacterRange (0, 5);
ranges[1] = new CharacterRange (5, 9);
SizeF size = g.MeasureString (text, test_font);
Assert.IsFalse (size.IsEmpty, "MeasureString");
StringFormat sf = new StringFormat ();
sf.FormatFlags = StringFormatFlags.NoClip;
sf.SetMeasurableCharacterRanges (ranges);
RectangleF rect = new RectangleF (0, 0, size.Width, size.Height);
Region[] region = g.MeasureCharacterRanges (text, test_font, rect, sf);
Assert.AreEqual (2, region.Length, "MeasureCharacterRanges");
}
mf.Dispose ();
}
}
[Test]
public void WorldTransforms ()
{
Metafile mf;
using (Bitmap bmp = new Bitmap (100, 100, PixelFormat.Format32bppArgb)) {
using (Graphics g = Graphics.FromImage (bmp)) {
IntPtr hdc = g.GetHdc ();
try {
mf = new Metafile (hdc, EmfType.EmfPlusOnly);
}
finally {
g.ReleaseHdc (hdc);
}
}
using (Graphics g = Graphics.FromImage (mf)) {
Assert.IsTrue (g.Transform.IsIdentity, "Initial/IsIdentity");
g.ScaleTransform (2f, 0.5f);
Assert.IsFalse (g.Transform.IsIdentity, "Scale/IsIdentity");
g.RotateTransform (90);
g.TranslateTransform (-2, 2);
Matrix m = g.Transform;
g.MultiplyTransform (m);
// check
float[] elements = g.Transform.Elements;
Assert.AreEqual (-1f, elements[0], 0.00001f, "a0");
Assert.AreEqual (0f, elements[1], 0.00001f, "a1");
Assert.AreEqual (0f, elements[2], 0.00001f, "a2");
Assert.AreEqual (-1f, elements[3], 0.00001f, "a3");
Assert.AreEqual (-2f, elements[4], 0.00001f, "a4");
Assert.AreEqual (-3f, elements[5], 0.00001f, "a5");
g.Transform = m;
elements = g.Transform.Elements;
Assert.AreEqual (0f, elements[0], 0.00001f, "b0");
Assert.AreEqual (0.5f, elements[1], 0.00001f, "b1");
Assert.AreEqual (-2f, elements[2], 0.00001f, "b2");
Assert.AreEqual (0f, elements[3], 0.00001f, "b3");
Assert.AreEqual (-4f, elements[4], 0.00001f, "b4");
Assert.AreEqual (-1f, elements[5], 0.00001f, "b5");
g.ResetTransform ();
Assert.IsTrue (g.Transform.IsIdentity, "Reset/IsIdentity");
}
mf.Dispose ();
}
}
}
}
|