gpt4 book ai didi

c - 如何查找 GtkLabel 当前的字体

转载 作者:行者123 更新时间:2023-11-30 16:47:10 24 4
gpt4 key购买 nike

我知道这里已经提出了类似的问题:How to get a current font for GtkTextView?

但是

gtk_style_context_get_font has been deprecated since version 3.8 and should not be used in newly-written code. Use gtk_style_context_get() for "font" or subproperties instead.

我被困在这里了。如何使用新的推荐技术来找出小部件的当前字体?

@编辑一些代码:

PangoFontDescription *font_desc;
GtkStyleContext *style;
GdkRGBA fore_color;

font_desc = pango_font_description_new ();
style = gtk_widget_get_style_context (base);
gtk_style_context_get_color (style, GTK_STATE_FLAG_NORMAL, &fore_color);

gtk_style_context_save (style);
gtk_style_context_set_state (style, 0);
gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", font_desc, NULL);
gtk_style_context_restore (style);

if (G_TYPE_CHECK_INSTANCE_TYPE ((font_desc), PANGO_TYPE_FONT_DESCRIPTION)) {
printf("%s\n", "Is a font");
} else {
printf("%s\n", "Not a font");
}

printf("%s\n", pango_font_description_get_family (font_desc));

打印“随机”字符,因为 pango_font_description_get_family 返回 NULL 指针。

还打印“不是字体”

最佳答案

这只是在 Github 上快速搜索。

PangoFontDescription *font_desc;
GtkStyleContext *style_context;
style_context = gtk_widget_get_style_context (widget);
gtk_style_context_save (style_context);
gtk_style_context_set_state (style_context, 0);
gtk_style_context_get (style_context,
gtk_style_context_get_state(style_context), "font", &font_desc, NULL);
gtk_style_context_restore (style_context);

查看附近的行号:96 和 384

位于https://github.com/jessevdk/libgd/blob/master/libgd/gd-two-lines-renderer.c

关于c - 如何查找 GtkLabel 当前的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43425055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com