3

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?

name1ess0ne
  • 868
  • 7
  • 17

1 Answers1

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.

behdad
  • 346
  • 1
  • 4
  • Is this still true and has someone a tutorial about the 'few calls to fontconfig'. As usual the terrible GTK stack documentation kills me here. – Lothar Aug 02 '18 at 18:13
  • http://mces.blogspot.com/2015/05/how-to-use-custom-application-fonts.html – behdad Aug 03 '18 at 19:08