当前位置: 首页>>代码示例>>C#>>正文


C# IGraphics.PushFont方法代码示例

本文整理汇总了C#中IGraphics.PushFont方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphics.PushFont方法的具体用法?C# IGraphics.PushFont怎么用?C# IGraphics.PushFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGraphics的用法示例。


在下文中一共展示了IGraphics.PushFont方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHitTestInfo

        public override HitTestInfo GetHitTestInfo(IGraphics gr, int x, int y, Point pt)
        {
            // caller will have tested if point is within bounding rect
            // taking into account additional ascent/descent on the line

            Debug.Assert(style != null, "No class attached to TextFragment!!");

            string text=ProcessText(Text);

            gr.PushFont(gr.GetFontHandle(style.FontDesc));
            try
            {
                BinaryChopper bc=new BinaryChopper(text);
                int w=0;
                while ( bc.CanMove )
                {
                    // TODO: L: this could be optimised by calculating the shift
                    // left and right in pixels rather than measuring from zero
                    w=gr.MeasureText(bc.Text).Width;
                    if ( pt.X < x+w )
                        bc.TooLong();
                    else
                        bc.TooShort();
                }
                int cw=gr.MeasureText(text[bc.Position].ToString()).Width;
                bool after=(float) 1.0 * x + w - cw / 2 < pt.X;

                Debug.Assert(start+bc.Position < Node.Value.Length, "Invalid TextSelectionPoint!");
                SelectionPoint sp=new TextSelectionPoint(Node, start+bc.Position);

                Line l=(Line) Parent;
                LineItemContext ili=new LineItemContext(l.Height, l.Baseline, this, new Point(x,y));
                HitTestInfo ht=new HitTestInfo(sp, ili, after);
                return ht;
            }
            finally
            {
                gr.PopFont();
            }
        }
开发者ID:jugglingcats,项目名称:XEditNet,代码行数:40,代码来源:textlayout.cs

示例2: Bind

        public void Bind(IGraphics gr, Stylesheet s)
        {
            stylesheet=s;
            FontDesc fd=desc;
            if ( fd.Family == null )
                fd=s.DefaultFont;

            object fontHandle=gr.GetFontHandle(fd);
            gr.PushFont(fontHandle);
            fontAscent=gr.GetFontAscent();
            fontHeight=gr.GetFontHeight();
            gr.PopFont();
        }
开发者ID:jugglingcats,项目名称:XEditNet,代码行数:13,代码来源:Styles.cs

示例3: GetCaretPosition

        public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
        {
            // TODO: M: this is very innefficient since it is called for all text nodes during search
            if ( !ContainsSelectionPoint(sp) )
            {
                cpi.UpdateLocation(x+Width, y, Height, CaretSetting.Fallback);
                return;
            }

            TextSelectionPoint tsp=(TextSelectionPoint) sp;

            CaretSetting mode=CaretSetting.Absolute;

            gr.PushFont(gr.GetFontHandle(style.FontDesc));
            try
            {
                int n=tsp.Index-start;
                if ( n < 0 )
                {
                    // position is not in visible part of the string, it's
                    // in whitespace that has been trimmed.
                    cpi.UseSecondary=true;
                    return;
                } else if ( tsp.Index == 0 )
                {
                    // caret can be put somewhere else if necessary
                    // TODO: L: this is a bit simplistic - will be wrong if text nodes are
                    //			split and first node ends with space and ends a line (!)
                    mode=CaretSetting.Accurate;
                }

                string text=Text;

                if ( n > text.Length )
                    // TODO: L: not sure exactly when this happens
                    n=text.Length;

                text=ProcessText(text.Substring(0, n));

                int w=gr.MeasureText(text).Width;
                cpi.UpdateLocation(x+w, y, Height, mode);
            }
            finally
            {
                gr.PopFont();
            }
        }
开发者ID:jugglingcats,项目名称:XEditNet,代码行数:47,代码来源:textlayout.cs

示例4: Recurse

            private static void Recurse(int depth, IGraphics gr, Rectangle rc)
            {
                object o;
                FontDesc fd;
                fd=new FontDesc("Arial", 10, false, false, false);
                o=gr.GetFontHandle(fd);
                gr.PushFont(o);
                gr.MeasureText("my name is alfie");
                gr.DrawText(rc, 20, "hello", Color.Black, Color.White, -1, -1);

                fd=new FontDesc("Times New Roman", 10, false, false, false);
                o=gr.GetFontHandle(fd);
                gr.PushFont(o);
                gr.MeasureText("my name is alfie");

                fd=new FontDesc("Arial", 10, false, false, false);
                o=gr.GetFontHandle(fd);
                gr.PushFont(o);
                gr.MeasureText("my name is alfie");

                if ( depth < 100 )
                    Recurse(depth+1, gr, rc);

                gr.PopFont();
                gr.PopFont();
            }
开发者ID:jugglingcats,项目名称:XEditNet,代码行数:26,代码来源:LayoutTests.cs


注:本文中的IGraphics.PushFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。