Font Fallback
View as MarkdownDraws multilanguage text with font fallback support.
Code Snippet
using (var bitmap = new Bitmap(400, 200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var graphics = bitmap.GetGraphics())
{
var fontRegistry = new CustomFontRegistry();
var lobsterPsName = fontRegistry.Add("Lobster.ttf")[0].PostscriptName;
var arialUnicodePsName = fontRegistry.Add("ARIALUNI.TTF")[0].PostscriptName;
fontRegistry.FallbackFonts.Add(arialUnicodePsName);
graphics.FontRegistry = fontRegistry;
var dummyText = "Lorem ipsum dolor sit amet, ex mel latine pertinax. 載自大制節規信兵著旋避漂。";
var boundedText = new BoundedText(dummyText, graphics.CreateFont(lobsterPsName, 32f), new SolidBrush(RgbColor.Black))
{
Rectangle = new System.Drawing.RectangleF(20f, 20f, 360f, 360f),
};
graphics.DrawText(boundedText);
bitmap.Save("FontFallback.png");
}
Input
Lobster.ttf
DownloadARIALUNI.TTF
DownloadOutput
FontFallback.png
Used APIs
- Aurigma.GraphicsMill.Bitmap.GetGraphics
- Aurigma.GraphicsMill.Drawing.BoundedText
- Aurigma.GraphicsMill.Drawing.BoundedText.Rectangle
- Aurigma.GraphicsMill.Drawing.CustomFontRegistry
- Aurigma.GraphicsMill.Drawing.CustomFontRegistry.Add(String)
- Aurigma.GraphicsMill.Drawing.FontAddResult.PostscriptName
- Aurigma.GraphicsMill.Drawing.FontRegistry.FallbackFonts
- Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)
- Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)
- Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry
- Aurigma.GraphicsMill.Drawing.SolidBrush