81089

How to set font from file in Pango and Mono

<h3>Question</h3>

I have simple application that prints text and determines its size in pixels.

static void Main(string[] args) { Application.Init(); var screen = Screen.Default; var layout = new Pango.Layout(PangoHelper.ContextGetForScreen(screen)); layout.FontDescription = new FontDescription(); layout.FontDescription.Family = "Times New Roman"; layout.FontDescription.Size = Units.FromPixels(18); layout.SetText("My Text"); int width; int height; layout.GetPixelSize(out width, out height); Console.WriteLine("{0} - width:{1} height:{2}", layout.Text, width, height); Console.ReadLine(); }

But I want to use my own font. How I can load my own font from file and use it in Pango in Mono?


<h3>Answer1:</h3>

Short answer is: you can't use uninstalled fonts with Pango. :(

Longer answer is: you can, if you are using the fontconfig backend (PangoFc; eg on Linux). In that case you need to make a few calls to fontconfig before using Pango, to make the fonts available to fontconfig. However, I don't think Fontconfig has Mono bindings.

So, I'm afraid you're out of luck here.

来源:https://stackoverflow.com/questions/16668056/how-to-set-font-from-file-in-pango-and-mono

Recommend