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


C# Paint.GetFontMetrics方法代码示例

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


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

示例1: GetFontMetrics

        /// <summary>
        /// Gets font metrics for the font in the specified paint.
        /// </summary>
        /// <param name="paint">The paint.</param>
        /// <param name="defaultLineHeight">Default line height.</param>
        /// <param name="delta">The vertical delta.</param>
        private void GetFontMetrics(Paint paint, out float defaultLineHeight, out float delta)
        {
            var metrics = paint.GetFontMetrics();
            var ascent = -metrics.Ascent;
            var descent = metrics.Descent;
            var leading = metrics.Leading;

            //// http://stackoverflow.com/questions/5511830/how-does-line-spacing-work-in-core-text-and-why-is-it-different-from-nslayoutm

            leading = leading < 0 ? 0 : (float)Math.Floor(leading + 0.5f);
            var lineHeight = (float)Math.Floor(ascent + 0.5f) + (float)Math.Floor(descent + 0.5) + leading;
            var ascenderDelta = leading >= 0 ? 0 : (float)Math.Floor((0.2 * lineHeight) + 0.5);
            defaultLineHeight = lineHeight + ascenderDelta;
            delta = ascenderDelta - descent;
        }
开发者ID:Celderon,项目名称:oxyplot,代码行数:21,代码来源:CanvasRenderContext.cs

示例2: DrawIntoBitmap

            private void DrawIntoBitmap(Bitmap bm)
            {
                float x = bm.Width;
                float y = bm.Height;
                Canvas c = new Canvas (bm);
                Paint p = new Paint ();
                p.AntiAlias = true;

                p.Alpha = 0x80;
                c.DrawCircle (x / 2, y / 2, x / 2, p);

                p.Alpha = 0x30;
                p.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.Src));
                p.TextSize = 60;
                p.TextAlign = Paint.Align.Center;
                Paint.FontMetrics fm = p.GetFontMetrics ();
                c.DrawText ("Alpha", x / 2, (y - fm.Ascent) / 2, p);
            }
开发者ID:vkheleli,项目名称:monodroid-samples-master,代码行数:18,代码来源:AlphaBitmap.cs

示例3: MeasureString

        public Size MeasureString(string text, Font font)
        {
            using (var p = new Paint(this.paint))
            using (var bounds = new Rect())
            using (var fm = p.GetFontMetrics())
            {
                p.TextSize = font.Size;
                p.SetTypeface(font.FontFamily.Typeface);
                p.SetStyle(Paint.Style.Stroke);

                p.GetTextBounds(text, 0, text.Length, bounds);
                var width = bounds.Width();
                var height = -fm.Top + fm.Bottom;

                return new SizeF(width, height).ToSize();
            }
        }
开发者ID:majorsilence,项目名称:System.Drawing.Wrappers,代码行数:17,代码来源:Graphics.Android.cs


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