public void MeasureText(string text, out int width, out int height, string fontFamily, int fontSize, FontWeight fontWeight) { FontDescription desc = new FontDescription(); desc.Family = fontFamily; desc.Size = Pango.Units.FromPixels(fontSize); desc.Weight = WeightToPangoWeight(fontWeight); layout.FontDescription = desc; layout.SetMarkup(GLib.Markup.EscapeText(text)); layout.GetPixelSize(out width, out height); }
Weight WeightToPangoWeight(FontWeight value) { Weight weight = Weight.Normal; switch (value) { case FontWeight.Light: weight = Weight.Light; break; case FontWeight.Bold: weight = Weight.Semibold; break; case FontWeight.Normal: weight = Weight.Normal; break; } return(weight); }