1 | #include <gtk/gtk.h> |
2 | |
3 | static GtkWidget *antialias; |
4 | static GtkWidget *subpixel; |
5 | static GtkWidget *hintstyle; |
6 | |
7 | static void |
8 | set_font_options (GtkWidget *label) |
9 | { |
10 | cairo_antialias_t aa; |
11 | cairo_subpixel_order_t sp; |
12 | cairo_hint_style_t hs; |
13 | cairo_font_options_t *options; |
14 | |
15 | aa = gtk_combo_box_get_active (GTK_COMBO_BOX (antialias)); |
16 | sp = gtk_combo_box_get_active (GTK_COMBO_BOX (subpixel)); |
17 | hs = gtk_combo_box_get_active (GTK_COMBO_BOX (hintstyle)); |
18 | |
19 | options = cairo_font_options_create (); |
20 | cairo_font_options_set_antialias (options, antialias: aa); |
21 | cairo_font_options_set_subpixel_order (options, subpixel_order: sp); |
22 | cairo_font_options_set_hint_style (options, hint_style: hs); |
23 | |
24 | gtk_widget_set_font_options (widget: label, options); |
25 | cairo_font_options_destroy (options); |
26 | |
27 | gtk_widget_queue_draw (widget: label); |
28 | } |
29 | |
30 | int |
31 | main (int argc, char *argv[]) |
32 | { |
33 | GtkWidget *window, *label, *grid, *demo; |
34 | |
35 | gtk_init (); |
36 | |
37 | window = gtk_window_new (); |
38 | grid = gtk_grid_new (); |
39 | gtk_grid_set_row_spacing (GTK_GRID (grid), spacing: 10); |
40 | gtk_grid_set_column_spacing (GTK_GRID (grid), spacing: 10); |
41 | gtk_window_set_child (GTK_WINDOW (window), child: grid); |
42 | label = gtk_label_new (str: "Default font options" ); |
43 | gtk_grid_attach (GTK_GRID (grid), child: label, column: 0, row: 0, width: 2, height: 1); |
44 | demo = gtk_label_new (str: "Custom font options" ); |
45 | gtk_grid_attach (GTK_GRID (grid), child: demo, column: 0, row: 1, width: 2, height: 1); |
46 | |
47 | antialias = gtk_combo_box_text_new (); |
48 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (antialias), text: "Default" ); |
49 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (antialias), text: "None" ); |
50 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (antialias), text: "Gray" ); |
51 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (antialias), text: "Subpixel" ); |
52 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (antialias), text: "Fast" ); |
53 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (antialias), text: "Good" ); |
54 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (antialias), text: "Best" ); |
55 | g_signal_connect_swapped (antialias, "changed" , G_CALLBACK (set_font_options), demo); |
56 | label = gtk_label_new (str: "Antialias" ); |
57 | gtk_grid_attach (GTK_GRID (grid), child: label, column: 0, row: 2, width: 1, height: 1); |
58 | gtk_grid_attach (GTK_GRID (grid), child: antialias, column: 1, row: 2, width: 1, height: 1); |
59 | |
60 | subpixel = gtk_combo_box_text_new (); |
61 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (subpixel), text: "Default" ); |
62 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (subpixel), text: "RGB" ); |
63 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (subpixel), text: "BGR" ); |
64 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (subpixel), text: "Vertical RGB" ); |
65 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (subpixel), text: "Vertical BGR" ); |
66 | g_signal_connect_swapped (subpixel, "changed" , G_CALLBACK (set_font_options), demo); |
67 | label = gtk_label_new (str: "Subpixel" ); |
68 | gtk_grid_attach (GTK_GRID (grid), child: label, column: 0, row: 3, width: 1, height: 1); |
69 | gtk_grid_attach (GTK_GRID (grid), child: subpixel, column: 1, row: 3, width: 1, height: 1); |
70 | |
71 | hintstyle = gtk_combo_box_text_new (); |
72 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (hintstyle), text: "Default" ); |
73 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (hintstyle), text: "None" ); |
74 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (hintstyle), text: "Slight" ); |
75 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (hintstyle), text: "Medium" ); |
76 | gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (hintstyle), text: "Full" ); |
77 | g_signal_connect_swapped (hintstyle, "changed" , G_CALLBACK (set_font_options), demo); |
78 | label = gtk_label_new (str: "Hintstyle" ); |
79 | gtk_grid_attach (GTK_GRID (grid), child: label, column: 0, row: 4, width: 1, height: 1); |
80 | gtk_grid_attach (GTK_GRID (grid), child: hintstyle, column: 1, row: 4, width: 1, height: 1); |
81 | |
82 | gtk_combo_box_set_active (GTK_COMBO_BOX (antialias), index_: 0); |
83 | gtk_combo_box_set_active (GTK_COMBO_BOX (subpixel), index_: 0); |
84 | gtk_combo_box_set_active (GTK_COMBO_BOX (hintstyle), index_: 0); |
85 | |
86 | gtk_widget_show (widget: window); |
87 | |
88 | while (TRUE) |
89 | g_main_context_iteration (NULL, TRUE); |
90 | |
91 | return 0; |
92 | } |
93 | |