Beispiel #1
0
        protected void ProcessDrawText(IEnumerable <string> arguments)
        {
            try
            {
                int x = int.Parse(arguments.First());
                arguments = arguments.Skip(1);

                int y = int.Parse(arguments.First());
                arguments = arguments.Skip(1);

                int cch = int.Parse(arguments.First());
                arguments = arguments.Skip(1);

                string rgch = arguments.First();
                arguments = arguments.Skip(1);

                int stretch = int.Parse(arguments.First());
                arguments = arguments.Skip(1);

                m_vwGraphics32.DrawText(x, y, cch, rgch, stretch);

                // all argument should be used up.
                Debug.Assert(arguments.Count() == 0);
            }
            catch (Exception e)
            {
                Console.WriteLine("Warning could not parse line DrawText {0}", arguments.Aggregate((str, next) => (str + " " + next)));
            }
        }
Beispiel #2
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 #3
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 #4
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));
                }
            }
        }