Beispiel #1
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 #2
0
        /// <summary>
        /// Get the starting location for drawing the text.
        /// </summary>
        /// <remarks>Only used with Mono</remarks>
        private void GetLocationForText(Rectangle cellBounds, bool fRightToLeft,
                                        IVwGraphicsWin32 vg, string text, out int x, out int y)
        {
            Debug.Assert(Platform.IsMono, "This method is only needed on Mono");
            var contentBounds = cellBounds;

            contentBounds.Height -= 2;
            contentBounds.Width  -= 2;
            int dx0;
            int dy0;

            vg.GetTextExtent(text.Length, text, out dx0, out dy0);
            if (fRightToLeft)
            {
                x = contentBounds.Right - (dx0 + 4);
            }
            else
            {
                x = contentBounds.Left + 4;
            }
            int dy = (contentBounds.Height - dy0) / 2;

            if (dy > 0)
            {
                y = contentBounds.Top + dy;
            }
            else
            {
                y = contentBounds.Top;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get the starting location for drawing the text.
        /// </summary>
        private void GetLocationForText(Rectangle cellBounds, bool fRightToLeft,
                                        IVwGraphicsWin32 vg, string text, out int x, out int y)
        {
            var contentBounds = cellBounds;

            contentBounds.Height -= 2;
            contentBounds.Width  -= 2;
            int dx0;
            int dy0;

            vg.GetTextExtent(text.Length, text, out dx0, out dy0);
            if (fRightToLeft)
            {
                x = contentBounds.Right - (dx0 + 4);
            }
            else
            {
                x = contentBounds.Left + 4;
            }
            int dy = (contentBounds.Height - dy0) / 2;

            if (dy > 0)
            {
                y = contentBounds.Top + dy;
            }
            else
            {
                y = contentBounds.Top;
            }
        }
Beispiel #4
0
        protected void ProcessGetTextExtent(IEnumerable <string> arguments)
        {
            int cch = int.Parse(arguments.First());

            arguments = arguments.Skip(1);

            string rgch = arguments.First();

            arguments = arguments.Skip(1);

            int unusedX, unusedY;

            m_vwGraphics32.GetTextExtent(cch, rgch, out unusedX, out unusedY);
        }
Beispiel #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));
                }
            }
        }
Beispiel #6
0
		/// <summary>
		/// Get the starting location for drawing the text.
		/// </summary>
		private void GetLocationForText(Rectangle cellBounds, bool fRightToLeft,
			IVwGraphicsWin32 vg, string text, out int x, out int y)
		{
			var contentBounds = cellBounds;
			contentBounds.Height -= 2;
			contentBounds.Width -= 2;
			int dx0;
			int dy0;
			vg.GetTextExtent(text.Length, text, out dx0, out dy0);
			if (fRightToLeft)
			{
				x = contentBounds.Right - (dx0 + 4);
			}
			else
			{
				x = contentBounds.Left + 4;
			}
			int dy = (contentBounds.Height - dy0) / 2;
			if (dy > 0)
				y = contentBounds.Top + dy;
			else
				y = contentBounds.Top;
		}