Exemplo n.º 1
0
        public virtual Size MeasureText(Graphics g, string text, Font font, int clipWidth, out int drawableLen)
        {
            //Logger.Debug("MeasureText clipped " + text);
            // todo: BlockRendererのMeasureVisualLines()でContract.Ensure()を満たさなくなる
            //if (Root.Canvas.UseGdiPlus) {
            //    var fmt = new StringFormat(StringFormat.GenericTypographic);
            //    var dummy = -1;
            //    var size = new SizeF(clipWidth, 20);
            //    return Size.Ceiling(g.MeasureString(text, font, size, fmt, out drawableLen, out dummy));

            //} else {
            using (var f = (Font)font.Clone())
                using (var renderer = new Gdi32TextRenderer(g, f)) {
                    //renderer.TextAlignMode = TextAlignModes.TA_LEFT | TextAlignModes.TA_TOP;
                    return(renderer.MeasureText(text, clipWidth, out drawableLen));
                }
            //}
        }
Exemplo n.º 2
0
        protected virtual void DrawTextCenter(
            Graphics g, string text, Font font, Rectangle rect, Color color
            )
        {
            if (Root.Canvas.UseGdiPlus)
            {
                using (var brush = new SolidBrush(color)) {
                    var fmt = (StringFormat)StringFormat.GenericTypographic.Clone();
                    fmt.Alignment     = StringAlignment.Center;
                    fmt.LineAlignment = StringAlignment.Center;
                    fmt.FormatFlags   =
                        StringFormatFlags.NoWrap |
                        StringFormatFlags.NoClip;
                    g.DrawString(text, font, brush, rect, fmt);
                }
            }
            else
            {
                //TextRenderer.DrawText(g, text, font, rect, color, GetBulletFormatFlags());

                using (var f = (Font)font.Clone())
                    using (var renderer = new Gdi32TextRenderer(g, f)) {
                        renderer.BkMode = BkMode.TRANSPARENT;
                        //renderer.TextAlignMode = TextAlignModes.TA_CENTER | TextAlignModes.TA_TOP;
                        renderer.TextColor = color;

                        var size   = renderer.MeasureText(text);
                        var left   = rect.Left + (rect.Width - size.Width) / 2 + 1;
                        var top    = rect.Top + (rect.Height - size.Height) / 2 + 1;
                        var width  = size.Width;
                        var height = size.Height;

                        var r = new Rectangle(
                            left + Root.Canvas.AutoScrollPosition.X - Root.Left,
                            top + Root.Canvas.AutoScrollPosition.Y - Root.Top,
                            width,
                            height
                            );

                        renderer.DrawText(text, r);
                    }
            }
        }
Exemplo n.º 3
0
        // ------------------------------
        // protected
        // ------------------------------
        // --- text ---
        protected virtual void DrawText(
            Graphics g, string text, Font font, Rectangle rect, Color color
            )
        {
            if (Root.Canvas.UseGdiPlus)
            {
                using (var brush = new SolidBrush(color)) {
                    var fmt = new StringFormat(StringFormat.GenericTypographic);
                    fmt.FormatFlags =
                        StringFormatFlags.NoWrap |
                        StringFormatFlags.NoClip;
                    g.DrawString(text, font, brush, rect.Location, fmt);
                }
            }
            else
            {
                using (var f = (Font)font.Clone())
                    using (var renderer = new Gdi32TextRenderer(g, f)) {
                        renderer.BkMode = BkMode.TRANSPARENT;
                        //renderer.TextAlignMode = TextAlignModes.TA_LEFT | TextAlignModes.TA_TOP;
                        renderer.TextColor = color;
                        var r = new Rectangle(
                            rect.Left + Root.Canvas.AutoScrollPosition.X - Root.Left,
                            rect.Top + Root.Canvas.AutoScrollPosition.Y - Root.Top,
                            rect.Width,
                            rect.Height
                            );
                        renderer.DrawText(text, r);
                    }
            }

            // for debug
            //Console.WriteLine("DrawText: " + text);
            //var trace = new System.Diagnostics.StackTrace();
            //for (int StackLoop = 0; StackLoop < trace.FrameCount; ++StackLoop) {
            //    var frame = trace.GetFrame(StackLoop);
            //    var method = frame.GetMethod();
            //    Console.WriteLine(method.ToString());
            //}
            //Console.WriteLine("---");
        }
Exemplo n.º 4
0
        // --- text ---
        public virtual Size MeasureText(Graphics g, string text, Font font, int proposedWidth)
        {
            if (Root != null && Root.Canvas.UseGdiPlus)
            {
                /// Feedbackの表示でRoot == nullのことがある

                var fmt = new StringFormat(StringFormat.GenericTypographic);
                fmt.FormatFlags =
                    StringFormatFlags.NoWrap |
                    StringFormatFlags.NoClip;
                return(Size.Ceiling(g.MeasureString(text, font, proposedWidth, fmt)));
            }
            else
            {
                using (var f = (Font)font.Clone())
                    using (var renderer = new Gdi32TextRenderer(g, f)) {
                        //renderer.TextAlignMode = TextAlignModes.TA_LEFT | TextAlignModes.TA_TOP;
                        return(renderer.MeasureText(text));
                    }
            }
        }