本文介绍了如何在Pango和Mono中从文件设置字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,可以打印文本并确定其大小(以像素为单位).

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();
}

但是我想使用我自己的字体.如何从文件中加载我自己的字体并在Pango中的Pango中使用它?

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

推荐答案

简短的答案是:您不能在Pango中使用已卸载的字体. :(

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

更长的答案是:如果使用的是fontconfig后端,则可以(PangoFc;例如在Linux上).在这种情况下,您需要先对fontconfig进行一些调用使用Pango,使字体可用于fontconfig.但是我不认为Fontconfig具有Mono绑定.

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 beforeusing Pango, to make the fonts available to fontconfig. However, I don'tthink Fontconfig has Mono bindings.

所以,我怕你在这里不走运.

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

这篇关于如何在Pango和Mono中从文件设置字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 12:14