本文整理汇总了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;
}
示例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);
}
示例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();
}
}