2017-04-15 5 views
0

GtkLabel Je sais que la même question a déjà été posée ici: How to get a current font for GtkTextView?Comment trouver la police actuelle pour

Mais

gtk_style_context_get_font a été dépréciées depuis la version 3.8 et ne doit pas être utilisé dans un nouveau code . Utilisez gtk_style_context_get() pour "font" ou subproperties à la place.

Et là, je suis coincé. Comment utiliser la nouvelle technique recommandée pour trouver la police actuelle pour le widget?

@EDIT Certains code:

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

'aléatoires' caractères imprimés, car pango_font_description_get_family renvoie un pointeur NULL.

imprime aussi « Pas une police »

Répondre

0

Ceci est juste une recherche rapide sur 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); 

Voir les numéros près de la ligne: 96 et 384

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

+0

Si le travail (en théorie), mais en fait quand je l'appelle pango_font_description_get_family() sur et font_desc je reçois un pointeur NULL. – ProNOOB