How to set font from file in Pango and Mono

你说的曾经没有我的故事 提交于 2020-06-16 03:03:13

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!