Font API
View as MarkdownDraws text without text objects, only with getting char info + simple metrics.
Code Snippet
using (var bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var gr = bitmap.GetGraphics())
using (var fr = new CustomFontRegistry())
{
var psName = fr.Add("Lobster.ttf")[0].PostscriptName;
gr.FontRegistry = fr;
var font = gr.CreateFont(psName, 40);
string[] lines = new string[] { "SOME", "TEXT", "TO ADD" };
float x = 10f;
float y = 50f;
float offsetY = 0f;
foreach (string line in lines)
{
float offsetX = 0f;
for (int i = 0; i < line.Length; i++)
{
using (var charInfo = font.GetCharacterInfo(line[i]))
{
charInfo.Outline.Translate(x + offsetX, y + offsetY);
gr.FillPath(new SolidBrush(RgbColor.Black), charInfo.Outline);
offsetX += charInfo.AdvanceX;
}
}
offsetY += font.Metrics.Height;
}
bitmap.Save("FontAPI.png");
}
Input
Lobster.ttf
DownloadOutput
FontAPI.png
Used APIs
- Aurigma.GraphicsMill.Bitmap.GetGraphics
- Aurigma.GraphicsMill.Drawing.CharInfo.AdvanceX
- Aurigma.GraphicsMill.Drawing.CharInfo.Outline
- Aurigma.GraphicsMill.Drawing.CustomFontRegistry
- Aurigma.GraphicsMill.Drawing.CustomFontRegistry.Add(String)
- Aurigma.GraphicsMill.Drawing.Font.GetCharacterInfo(Char)
- Aurigma.GraphicsMill.Drawing.Font.Metrics
- Aurigma.GraphicsMill.Drawing.FontAddResult.PostscriptName
- Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)
- Aurigma.GraphicsMill.Drawing.Graphics.FillPath(Brush,Path)
- Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry
- Aurigma.GraphicsMill.Drawing.Path.Translate(Single,Single)
- Aurigma.GraphicsMill.Drawing.SolidBrush