从 Gtk.FontButton 设置 Pango.FontDescription

Setting Pango.FontDescription from a Gtk.FontButton

在我的首选项对话框中,我有一个 Gtk.FontButton 供用户 select 字体,稍后我从 get_font_name () 字符串创建一个新的 Pango.FontDesciption。问题是从未设置字体大小。

var font = new Pango.FontDescription ();
var font_name = Window.SETTINGS.get_string ("room-font");
font.from_string (font_name);
stdout.puts (@"Font: $font_name, Size: $(font.get_size())");

这会打印 Font: Sans 12, Size: 0.

FontButton 的 documentation for from_string says "SIZE is a decimal number (size in points) or optionally followed by the unit modifier "px" for absolute size." which would seem to indicate that the size in Sans 12 is formatted wrong. But the documentation 表示 "If you want to render something with the font, use this string with from_string"。

我在这里错过了什么?

Pango.FontDescription.from_string()是静态方法;它 returns 一个新的 Pango.FontDescription。它没有改变 font,所以它仍然有默认值,默认大小似乎是 0。(为什么它是静态方法而不是构造函数是我无法理解的。)