Beispiel #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));
                }
            }
        }
Beispiel #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();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draw the text using the FieldWorks IVwGraphicsWin32 interface.
        /// </summary>
        /// <remarks>Only used with Mono</remarks>
        private void DrawFwText(Graphics graphics, Rectangle cellBounds,
                                string text, DataGridViewCellStyle cellStyle, FwTextBoxColumn col)
        {
            Debug.Assert(Platform.IsMono, "This method is only needed on Mono");
            if (String.IsNullOrEmpty(text))
            {
                return;
            }
            IntPtr           hdc = graphics.GetHdc();
            IVwGraphicsWin32 vg  = VwGraphicsWin32Class.Create();               // actually VwGraphicsCairo

            try
            {
                vg.Initialize(hdc);
                var renderProps = GetRenderProps(cellStyle, col);
                vg.SetupGraphics(ref renderProps);
                int x;
                int y;
                GetLocationForText(cellBounds, (col.TextBoxControl.RightToLeft == RightToLeft.Yes),
                                   vg, text, out x, out y);
                vg.PushClipRect(cellBounds);
                vg.DrawText(x, y, text.Length, text, 0);
                vg.PopClipRect();
            }
            finally
            {
                vg.ReleaseDC();
                graphics.ReleaseHdc(hdc);
            }
        }
Beispiel #4
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();
            }
        }
Beispiel #5
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();
            }
        }
Beispiel #6
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));
                }
            }
        }
Beispiel #7
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));
                }
            }
        }
Beispiel #8
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));
                }
            }
        }