Example #1
0
        public void Clipping()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                // start with a blue background.
                using (var blueBrush = new SolidBrush(Color.Blue))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, 1000, 1000));

                    // Check that filling with a blue brush worked.
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Blue));

                    //
                    // Check that drawing using a VwGraphics works.
                    //

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(0, 0, 1000, 1000));
                    vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Red);
                    vwGraphics.DrawRectangle(0, 0, 1000, 1000);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();

                    gr.Graphics.Flush();

                    // Check that drawing a red rectangle using the VwGraphics Interface worked
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Red));

                    /////
                    // Check that VwGraphics doesn't draw outside its clip rect.
                    /////

                    vwGraphics.Initialize(gr.Graphics.GetHdc());
                    // make the clip rect not include the area we are going to draw to.
                    vwGraphics.PushClipRect(new Utils.Rect(100, 100, 200, 200));

                    // attempt to draw off the clip rect.
                    vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Green);
                    vwGraphics.DrawRectangle(400, 400, 600, 600);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();

                    gr.Graphics.Flush();

                    // Check that the green rectangle didn't appear on screen.
                    Assert.IsTrue(!ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Green));
                }
            }
        }
Example #2
0
        public void GetTextExtentWithEmptyString()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                const int areaWidth  = 1000;
                const int areaHeight = 1000;

                vwGraphics.Initialize(gr.Graphics.GetHdc());

                vwGraphics.PushClipRect(new Utils.Rect(0, 0, areaWidth, areaHeight));
                vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

                int extentX;
                int extentY;

                vwGraphics.GetTextExtent(0, String.Empty, out extentX, out extentY);

                Assert.That(extentX == 0, "extentX should equal 0");
                Assert.That(extentY > 0, "extentY should be greater than 0");

                vwGraphics.PopClipRect();

                vwGraphics.ReleaseDC();
                gr.Graphics.ReleaseHdc();
            }
        }
Example #3
0
        public void SimpleCreationAndRelease()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());
                vwGraphics.ReleaseDC();
            }
        }
Example #4
0
        public void LargeRectangles()
        {
            // EB/2011-02-08: this test is failing for me on Linux. Not sure if it should work
            // or what (see FWNX-449). Test is failing in FillRectangle similar to the failure
            // in the following comment
            // https://www.jira.insitehome.org/browse/FWNX-449?focusedCommentId=108054&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-108054
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            const int width  = 1241;
            const int height = 56080;             // something bigger than MAX_IMAGE_SIZE (32767)

            using (var gr = new GraphicsObjectFromImage(width, height))
            {
                // start with a blue background.
                using (var blueBrush = new SolidBrush(Color.Blue))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, width, height));

                    // Check that filling with a blue brush worked.
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(width - 1, height - 1), Color.Blue));

                    /////
                    // Check that drawing using a VwGraphics works.
                    ////

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(0, 0, width, height));
                    vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Red);
                    vwGraphics.DrawRectangle(0, 0, width, height);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();

                    gr.Graphics.Flush();

                    // Check that drawing a red rectangle using the VwGraphics Interface worked
                    Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(width - 1, height - 1), Color.Red));
                }
            }
        }
Example #5
0
        internal void TestGetTextExtentHelper(string testString)
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                const int areaWidth  = 500;
                const int areaHeight = 500;

                // start with a White background.
                using (var blueBrush = new SolidBrush(Color.White))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, areaWidth, areaHeight));

                    Assert.AreEqual(-1, SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #1");
                    Assert.AreEqual(-1, SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #2");

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(0, 0, areaWidth, areaHeight));
                    vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

                    int extentX;
                    int extentY;

                    vwGraphics.GetTextExtent(testString.Length, testString, out extentX, out extentY);

                    Assert.That(extentX > 0, "extentX should be greater than 0");
                    Assert.That(extentY > 0, "extentY should be greater than 0");

                    vwGraphics.DrawText(0, 0, testString.Length, testString, 0);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();
                    gr.Graphics.Flush();

                    Assert.That(SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= extentY, String.Format("Should be <= {0}", extentY));
                    Assert.That(SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= extentX, String.Format("Should be <= {0}", extentX));
                }
            }
        }
Example #6
0
        public void ComplexClipping()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());

                // Test on a single push
                int left, top, right, bottom;

                vwGraphics.PushClipRect(new Utils.Rect(50, 60, 500, 510));
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(60, top, "Top doesn't match");
                Assert.AreEqual(500, right, "Right doesn't match");
                Assert.AreEqual(510, bottom, "Bottom doesn't match");

                // Test on a second push
                vwGraphics.PushClipRect(new Utils.Rect(1, 1, 300, 310));
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(60, top, "Top doesn't match");
                Assert.AreEqual(300, right, "Right doesn't match");
                Assert.AreEqual(310, bottom, "Bottom doesn't match");

                vwGraphics.PopClipRect();
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(60, top, "Top doesn't match");
                Assert.AreEqual(500, right, "Right doesn't match");
                Assert.AreEqual(510, bottom, "Bottom doesn't match");
                vwGraphics.PopClipRect();
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.AreEqual(0, left, "Left doesn't match");
                Assert.AreEqual(0, top, "Top doesn't match");
                Assert.AreEqual(1000, right, "Right doesn't match");
                Assert.AreEqual(1000, bottom, "Bottom doesn't match");

                vwGraphics.ReleaseDC();
                gr.Graphics.ReleaseHdc();
            }
        }
Example #7
0
        public void TextClipping()
        {
            const string longString = "abcdefghijklmnopqrstuvwzyzabcdefghijklmnopqrstuvwzyzabcdefghijklmnopqrstuvwzyz";

            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                const int areaWidth  = 500;
                const int areaHeight = 500;

                const int clipLeft  = 300;
                const int clipRight = 400;

                // start with a White background.
                using (var blueBrush = new SolidBrush(Color.White))
                {
                    gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, areaWidth, areaHeight));

                    Assert.AreEqual(-1, SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #1");
                    Assert.AreEqual(-1, SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #2");

                    vwGraphics.Initialize(gr.Graphics.GetHdc());

                    vwGraphics.PushClipRect(new Utils.Rect(clipLeft, 0, clipRight, areaHeight));
                    vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

                    vwGraphics.DrawText(0, 0, longString.Length, longString, 0);

                    vwGraphics.PopClipRect();

                    vwGraphics.ReleaseDC();
                    gr.Graphics.ReleaseHdc();
                    gr.Graphics.Flush();

                    Assert.That(SearchForLeftMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) >= clipLeft, String.Format("Should be >= {0}", clipLeft));
                    Assert.That(SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= clipRight, String.Format("Should be <= {0}", clipRight));
                }
            }
        }
Example #8
0
        public void GetClipRect()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());

                var rect1 = new Utils.Rect(0, 0, 1000, 1000);
                var rect2 = new Utils.Rect(500, 500, 700, 700);

                vwGraphics.PushClipRect(rect1);

                int left, top, right, bottom;
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);

                Assert.IsTrue(left == rect1.left, "First push failed: left");
                Assert.IsTrue(right == rect1.right, "First push failed: right");
                Assert.IsTrue(top == rect1.top, "First push failed: top");
                Assert.IsTrue(bottom == rect1.bottom, "First push failed: bottom");

                // try a second rectangle
                vwGraphics.PushClipRect(rect2);

                vwGraphics.GetClipRect(out left, out top, out right, out bottom);
                Assert.IsTrue(left == rect2.left, "Second push failed: left");
                Assert.IsTrue(right == rect2.right, "Second push failed: right");
                Assert.IsTrue(top == rect2.top, "Second push failed: top");
                Assert.IsTrue(bottom == rect2.bottom, "Second push failed: bottom");

                vwGraphics.PopClipRect();
                vwGraphics.PopClipRect();

                vwGraphics.ReleaseDC();
                gr.Graphics.ReleaseHdc();
            }
        }
Example #9
0
        public void SetClipRect()
        {
            IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();

            Assert.IsNotNull(vwGraphics);

            using (var gr = new GraphicsObjectFromImage())
            {
                vwGraphics.Initialize(gr.Graphics.GetHdc());

                int left, top, right, bottom;

                var rect = new Utils.Rect(50, 25, 1000, 1000);
                vwGraphics.SetClipRect(ref rect);
                vwGraphics.GetClipRect(out left, out top, out right, out bottom);

                Assert.AreEqual(50, left, "Left doesn't match");
                Assert.AreEqual(25, top, "Top doesn't match");
                Assert.AreEqual(1000, right, "Right doesn't match");
                Assert.AreEqual(1000, bottom, "Bottom doesn't match");
            }
        }
Example #10
0
		public void TextClipping()
		{
			const string longString = "abcdefghijklmnopqrstuvwzyzabcdefghijklmnopqrstuvwzyzabcdefghijklmnopqrstuvwzyz";

			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				const int areaWidth = 500;
				const int areaHeight = 500;

				const int clipLeft = 300;
				const int clipRight = 400;

				// start with a White background.
				using (var blueBrush = new SolidBrush(Color.White))
				{
					gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, areaWidth, areaHeight));

					Assert.AreEqual(-1, SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #1");
					Assert.AreEqual(-1, SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #2");

					vwGraphics.Initialize(gr.Graphics.GetHdc());

					vwGraphics.PushClipRect(new Utils.Rect(clipLeft, 0, clipRight, areaHeight));
					vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

					vwGraphics.DrawText(0, 0, longString.Length, longString, 0);

					vwGraphics.PopClipRect();

					vwGraphics.ReleaseDC();
					gr.Graphics.ReleaseHdc();
					gr.Graphics.Flush();

					Assert.That(SearchForLeftMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) >= clipLeft, String.Format("Should be >= {0}", clipLeft));
					Assert.That(SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= clipRight, String.Format("Should be <= {0}", clipRight));
				}
			}
		}
Example #11
0
		public void GetTextExtentWithEmptyString()
		{
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				const int areaWidth = 1000;
				const int areaHeight = 1000;

				vwGraphics.Initialize(gr.Graphics.GetHdc());

				vwGraphics.PushClipRect(new Utils.Rect(0, 0, areaWidth, areaHeight));
				vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

				int extentX;
				int extentY;

				vwGraphics.GetTextExtent(0, String.Empty, out extentX, out extentY);

				Assert.That(extentX == 0, "extentX should equal 0");
				Assert.That(extentY > 0, "extentY should be greater than 0");

				vwGraphics.PopClipRect();

				vwGraphics.ReleaseDC();
				gr.Graphics.ReleaseHdc();
			}

		}
Example #12
0
		internal void TestGetTextExtentHelper(string testString)
		{
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				const int areaWidth = 500;
				const int areaHeight = 500;

				// start with a White background.
				using (var blueBrush = new SolidBrush(Color.White))
				{
					gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, areaWidth, areaHeight));

					Assert.AreEqual(-1, SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #1");
					Assert.AreEqual(-1, SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight), "Should all be white #2");

					vwGraphics.Initialize(gr.Graphics.GetHdc());

					vwGraphics.PushClipRect(new Utils.Rect(0, 0, areaWidth, areaHeight));
					vwGraphics.ForeColor = ConvertToVwGraphicsColor(Color.Black);

					int extentX;
					int extentY;

					vwGraphics.GetTextExtent(testString.Length, testString, out extentX, out extentY);

					Assert.That(extentX > 0, "extentX should be greater than 0");
					Assert.That(extentY > 0, "extentY should be greater than 0");

					vwGraphics.DrawText(0, 0, testString.Length, testString, 0);

					vwGraphics.PopClipRect();

					vwGraphics.ReleaseDC();
					gr.Graphics.ReleaseHdc();
					gr.Graphics.Flush();

					Assert.That(SearchForBottomMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= extentY, String.Format("Should be <= {0}", extentY));
					Assert.That(SearchForRightMostNonWhitePixel(gr.Bitmap, areaWidth, areaHeight) <= extentX, String.Format("Should be <= {0}", extentX));
				}
			}
		}
Example #13
0
		public void ComplexClipping()
		{
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				vwGraphics.Initialize(gr.Graphics.GetHdc());

				// Test on a single push
				int left, top, right, bottom;

				vwGraphics.PushClipRect(new Utils.Rect(50, 60, 500, 510));
				vwGraphics.GetClipRect(out left, out top, out right, out bottom);
				Assert.AreEqual(50, left, "Left doesn't match");
				Assert.AreEqual(60, top, "Top doesn't match");
				Assert.AreEqual(500, right, "Right doesn't match");
				Assert.AreEqual(510, bottom, "Bottom doesn't match");

				// Test on a second push
				vwGraphics.PushClipRect(new Utils.Rect(1, 1, 300, 310));
				vwGraphics.GetClipRect(out left, out top, out right, out bottom);
				Assert.AreEqual(50, left, "Left doesn't match");
				Assert.AreEqual(60, top, "Top doesn't match");
				Assert.AreEqual(300, right, "Right doesn't match");
				Assert.AreEqual(310, bottom, "Bottom doesn't match");

				vwGraphics.PopClipRect();
				vwGraphics.GetClipRect(out left, out top, out right, out bottom);
				Assert.AreEqual(50, left, "Left doesn't match");
				Assert.AreEqual(60, top, "Top doesn't match");
				Assert.AreEqual(500, right, "Right doesn't match");
				Assert.AreEqual(510, bottom, "Bottom doesn't match");
				vwGraphics.PopClipRect();
				vwGraphics.GetClipRect(out left, out top, out right, out bottom);
				Assert.AreEqual(0, left, "Left doesn't match");
				Assert.AreEqual(0, top, "Top doesn't match");
				Assert.AreEqual(1000, right, "Right doesn't match");
				Assert.AreEqual(1000, bottom, "Bottom doesn't match");

				vwGraphics.ReleaseDC();
				gr.Graphics.ReleaseHdc();
			}

		}
Example #14
0
		public void SetClipRect()
		{
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				vwGraphics.Initialize(gr.Graphics.GetHdc());

				int left, top, right, bottom;

				var rect = new Utils.Rect(50,25,1000,1000);
				vwGraphics.SetClipRect(ref rect);
				vwGraphics.GetClipRect(out left, out top, out right, out bottom);

				Assert.AreEqual(50, left, "Left doesn't match");
				Assert.AreEqual(25, top, "Top doesn't match");
				Assert.AreEqual(1000, right, "Right doesn't match");
				Assert.AreEqual(1000, bottom, "Bottom doesn't match");
			}
		}
Example #15
0
		public void Clipping()
		{
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				// start with a blue background.
				using (var blueBrush = new SolidBrush(Color.Blue))
				{
					gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, 1000, 1000));

					// Check that filling with a blue brush worked.
					Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Blue));

					//
					// Check that drawing using a VwGraphics works.
					//

					vwGraphics.Initialize(gr.Graphics.GetHdc());

					vwGraphics.PushClipRect(new Utils.Rect(0, 0, 1000, 1000));
					vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Red);
					vwGraphics.DrawRectangle(0, 0, 1000, 1000);

					vwGraphics.PopClipRect();

					vwGraphics.ReleaseDC();
					gr.Graphics.ReleaseHdc();

					gr.Graphics.Flush();

					// Check that drawing a red rectangle using the VwGraphics Interface worked
					Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Red));

					/////
					// Check that VwGraphics doesn't draw outside its clip rect.
					/////

					vwGraphics.Initialize(gr.Graphics.GetHdc());
					// make the clip rect not include the area we are going to draw to.
					vwGraphics.PushClipRect(new Utils.Rect(100, 100, 200, 200));

					// attempt to draw off the clip rect.
					vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Green);
					vwGraphics.DrawRectangle(400, 400, 600, 600);

					vwGraphics.PopClipRect();

					vwGraphics.ReleaseDC();
					gr.Graphics.ReleaseHdc();

					gr.Graphics.Flush();

					// Check that the green rectangle didn't appear on screen.
					Assert.IsTrue(!ColorCompare(gr.Bitmap.GetPixel(500, 500), Color.Green));
				}
			}
		}
Example #16
0
		public void LargeRectangles()
		{
			// EB/2011-02-08: this test is failing for me on Linux. Not sure if it should work
			// or what (see FWNX-449). Test is failing in FillRectangle similar to the failure
			// in the following comment
			// https://www.jira.insitehome.org/browse/FWNX-449?focusedCommentId=108054&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-108054
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			const int width = 1241;
			const int height = 56080; // something bigger than MAX_IMAGE_SIZE (32767)

			using (var gr = new GraphicsObjectFromImage(width, height))
			{
				// start with a blue background.
				using (var blueBrush = new SolidBrush(Color.Blue))
				{
					gr.Graphics.FillRectangle(blueBrush, new Rectangle(0, 0, width, height));

					// Check that filling with a blue brush worked.
					Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(width - 1, height - 1), Color.Blue));

					/////
					// Check that drawing using a VwGraphics works.
					////

					vwGraphics.Initialize(gr.Graphics.GetHdc());

					vwGraphics.PushClipRect(new Utils.Rect(0, 0, width, height));
					vwGraphics.BackColor = ConvertToVwGraphicsColor(Color.Red);
					vwGraphics.DrawRectangle(0, 0, width, height);

					vwGraphics.PopClipRect();

					vwGraphics.ReleaseDC();
					gr.Graphics.ReleaseHdc();

					gr.Graphics.Flush();

					// Check that drawing a red rectangle using the VwGraphics Interface worked
					Assert.IsTrue(ColorCompare(gr.Bitmap.GetPixel(width - 1, height - 1), Color.Red));
				}
			}
		}
Example #17
0
		public void SimpleCreationAndRelease()
		{
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				vwGraphics.Initialize(gr.Graphics.GetHdc());
				vwGraphics.ReleaseDC();
			}
		}
Example #18
0
		public void GetClipRect()
		{
			IVwGraphicsWin32 vwGraphics = VwGraphicsWin32Class.Create();
			Assert.IsNotNull(vwGraphics);

			using (var gr = new GraphicsObjectFromImage())
			{
				vwGraphics.Initialize(gr.Graphics.GetHdc());

				var rect1 = new Utils.Rect(0, 0, 1000, 1000);
				var rect2 = new Utils.Rect(500, 500, 700, 700);

				vwGraphics.PushClipRect(rect1);

				int left, top, right, bottom;
				vwGraphics.GetClipRect(out left, out top, out right, out bottom);

				Assert.IsTrue(left == rect1.left, "First push failed: left");
				Assert.IsTrue(right == rect1.right, "First push failed: right");
				Assert.IsTrue(top == rect1.top, "First push failed: top");
				Assert.IsTrue(bottom == rect1.bottom, "First push failed: bottom");

				// try a second rectangle
				vwGraphics.PushClipRect(rect2);

				vwGraphics.GetClipRect(out left, out top, out right, out bottom);
				Assert.IsTrue(left == rect2.left, "Second push failed: left");
				Assert.IsTrue(right == rect2.right, "Second push failed: right");
				Assert.IsTrue(top == rect2.top, "Second push failed: top");
				Assert.IsTrue(bottom == rect2.bottom, "Second push failed: bottom");

				vwGraphics.PopClipRect();
				vwGraphics.PopClipRect();

				vwGraphics.ReleaseDC();
				gr.Graphics.ReleaseHdc();
			}

		}