本文整理汇总了C#中System.Drawing.Font.GetKerningInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Font.GetKerningInfo方法的具体用法?C# Font.GetKerningInfo怎么用?C# Font.GetKerningInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Font
的用法示例。
在下文中一共展示了Font.GetKerningInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Loads the glyphs from a font.
/// </summary>
/// <param name="font">The font.</param>
/// <returns>The <see cref="Task" /> that represents the asynchronous operation.</returns>
private async Task Load(Font font)
{
using (font)
{
var size = (int)Math.Ceiling(font.GetHeight());
var rows = (int)Math.Ceiling(Math.Sqrt(characters.Length));
var columns = (int)Math.Ceiling(characters.Length / (double)rows);
using (var drawing = new Drawing(size * columns, size * rows))
{
await Task.Run(delegate
{
drawing.Draw(g =>
{
var format = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center,
FormatFlags = StringFormatFlags.MeasureTrailingSpaces,
};
g.CompositingMode = CompositingMode.SourceCopy;
g.Clear(Color.FromArgb(1, 255, 255, 255));
g.CompositingMode = CompositingMode.SourceOver;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
for (var i = 0; i < characters.Length; i++)
{
var row = i / columns;
var col = i % columns;
g.DrawString(characters[i].ToString(), font, Brushes.White, new RectangleF(col * size, row * size, size, size), format);
}
var kerningInfo = font.GetKerningInfo();
for (var i = 0; i < this.glyphs.Length; i++)
{
var kerning = new float[this.characters.Length];
var spacing = Math.Max(1, size * SpacingFactor);
for (var c = 0; c < this.characters.Length; c++)
{
var info = kerningInfo.GetValueOrDefault(this.characters[i]);
if (info != null)
{
kerning[c] = spacing + info.GetValueOrDefault(this.characters[c]);
}
else
{
kerning[c] = spacing;
}
}
this.glyphs[i] = new BitmapGlyph(this.Texture, this.characters, kerning);
}
this.whitespace.Width = Math.Max(8, size * EscapementFactor);
this.whitespace.Height = size;
});
drawing.Scan(this.glyphs, columns, SpriteScanOptions.ScanHorizontally);
});
drawing.CopyTo(this.Texture.Image);
}
}
}