| 1 |
/* Pango/Font Features |
| 2 |
* |
| 3 |
* This example demonstrates support for OpenType font features with |
| 4 |
* Pango attributes. The attributes can be used manually or via Pango |
| 5 |
* markup. |
| 6 |
* |
| 7 |
* It can also be used to explore available features in OpenType fonts |
| 8 |
* and their effect. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <gtk/gtk.h> |
| 12 |
|
| 13 |
#if PANGO_VERSION_CHECK(1,44,0) |
| 14 |
# if !HB_VERSION_ATLEAST(2,2,0) |
| 15 |
# define FONT_FEATURES_USE_PANGOFT2 1 |
| 16 |
# endif |
| 17 |
#else |
| 18 |
# define FONT_FEATURES_USE_PANGOFT2 1 |
| 19 |
#endif |
| 20 |
|
| 21 |
#ifdef FONT_FEATURES_USE_PANGOFT2 |
| 22 |
#include <pango/pangofc-font.h> |
| 23 |
#include <hb.h> |
| 24 |
#include <hb-ot.h> |
| 25 |
#include <hb-ft.h> |
| 26 |
#else |
| 27 |
#include <hb-ot.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
static GtkWidget *label; |
| 31 |
static GtkWidget *settings; |
| 32 |
static GtkWidget *font; |
| 33 |
static GtkWidget *script_lang; |
| 34 |
static GtkWidget *resetbutton; |
| 35 |
static GtkWidget *numcasedefault; |
| 36 |
static GtkWidget *numspacedefault; |
| 37 |
static GtkWidget *fractiondefault; |
| 38 |
static GtkWidget *stack; |
| 39 |
static GtkWidget *entry; |
| 40 |
|
| 41 |
#define num_features 40 |
| 42 |
|
| 43 |
static GtkWidget *toggle[num_features]; |
| 44 |
static GtkWidget *icon[num_features]; |
| 45 |
static const char *feature_names[num_features] = { |
| 46 |
"kern", "liga", "dlig", "hlig", "clig", "smcp", "c2sc", "pcap", "c2pc", "unic", |
| 47 |
"cpsp", "case", "lnum", "onum", "pnum", "tnum", "frac", "afrc", "zero", "nalt", |
| 48 |
"sinf", "swsh", "cswh", "locl", "calt", "hist", "salt", "titl", "rand", "subs", |
| 49 |
"sups", "init", "medi", "fina", "isol", "ss01", "ss02", "ss03", "ss04", "ss05" |
| 50 |
}; |
| 51 |
|
| 52 |
static void |
| 53 |
update_display (void) |
| 54 |
{ |
| 55 |
GString *s; |
| 56 |
char *font_desc; |
| 57 |
char *font_settings; |
| 58 |
const char *text; |
| 59 |
gboolean has_feature; |
| 60 |
int i; |
| 61 |
hb_tag_t lang_tag; |
| 62 |
GtkTreeModel *model; |
| 63 |
GtkTreeIter iter; |
| 64 |
const char *lang; |
| 65 |
|
| 66 |
text = gtk_entry_get_text (GTK_ENTRY (entry)); |
| 67 |
|
| 68 |
font_desc = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (font)); |
| 69 |
|
| 70 |
s = g_string_new (""); |
| 71 |
|
| 72 |
has_feature = FALSE; |
| 73 |
for (i = 0; i < num_features; i++) |
| 74 |
{ |
| 75 |
if (!gtk_widget_is_sensitive (toggle[i])) |
| 76 |
continue; |
| 77 |
|
| 78 |
if (GTK_IS_RADIO_BUTTON (toggle[i])) |
| 79 |
{ |
| 80 |
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle[i]))) |
| 81 |
{ |
| 82 |
if (has_feature) |
| 83 |
g_string_append (s, ", "); |
| 84 |
g_string_append (s, gtk_buildable_get_name (GTK_BUILDABLE (toggle[i]))); |
| 85 |
g_string_append (s, " 1"); |
| 86 |
has_feature = TRUE; |
| 87 |
} |
| 88 |
} |
| 89 |
else |
| 90 |
{ |
| 91 |
if (has_feature) |
| 92 |
g_string_append (s, ", "); |
| 93 |
g_string_append (s, gtk_buildable_get_name (GTK_BUILDABLE (toggle[i]))); |
| 94 |
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle[i]))) |
| 95 |
g_string_append (s, " 1"); |
| 96 |
else |
| 97 |
g_string_append (s, " 0"); |
| 98 |
has_feature = TRUE; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
font_settings = g_string_free (s, FALSE); |
| 103 |
|
| 104 |
gtk_label_set_text (GTK_LABEL (settings), font_settings); |
| 105 |
|
| 106 |
|
| 107 |
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (script_lang), &iter)) |
| 108 |
{ |
| 109 |
model = gtk_combo_box_get_model (GTK_COMBO_BOX (script_lang)); |
| 110 |
gtk_tree_model_get (model, &iter, |
| 111 |
3, &lang_tag, |
| 112 |
-1); |
| 113 |
|
| 114 |
lang = hb_language_to_string (hb_ot_tag_to_language (lang_tag)); |
| 115 |
} |
| 116 |
else |
| 117 |
lang = NULL; |
| 118 |
|
| 119 |
s = g_string_new (""); |
| 120 |
g_string_append_printf (s, "<span font_desc='%s' font_features='%s'", font_desc, font_settings); |
| 121 |
if (lang) |
| 122 |
g_string_append_printf (s, " lang='%s'", lang); |
| 123 |
g_string_append_printf (s, ">%s</span>", text); |
| 124 |
|
| 125 |
gtk_label_set_markup (GTK_LABEL (label), s->str); |
| 126 |
|
| 127 |
g_string_free (s, TRUE); |
| 128 |
|
| 129 |
g_free (font_desc); |
| 130 |
g_free (font_settings); |
| 131 |
} |
| 132 |
|
| 133 |
static PangoFont * |
| 134 |
get_pango_font (void) |
| 135 |
{ |
| 136 |
PangoFontDescription *desc; |
| 137 |
PangoContext *context; |
| 138 |
PangoFontMap *map; |
| 139 |
|
| 140 |
desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (font)); |
| 141 |
context = gtk_widget_get_pango_context (font); |
| 142 |
map = pango_context_get_font_map (context); |
| 143 |
|
| 144 |
return pango_font_map_load_font (map, context, desc); |
| 145 |
} |
| 146 |
|
| 147 |
static struct { const char *name; hb_script_t script; } script_names[] = { |
| 148 |
{ "Common", HB_SCRIPT_COMMON }, |
| 149 |
{ "Inherited", HB_SCRIPT_INHERITED }, |
| 150 |
{ "Unknown", HB_SCRIPT_UNKNOWN }, |
| 151 |
{ "Arabic", HB_SCRIPT_ARABIC }, |
| 152 |
{ "Armenian", HB_SCRIPT_ARMENIAN }, |
| 153 |
{ "Bengali", HB_SCRIPT_BENGALI }, |
| 154 |
{ "Cyrillic", HB_SCRIPT_CYRILLIC }, |
| 155 |
{ "Devanagari", HB_SCRIPT_DEVANAGARI }, |
| 156 |
{ "Georgian", HB_SCRIPT_GEORGIAN }, |
| 157 |
{ "Greek", HB_SCRIPT_GREEK }, |
| 158 |
{ "Gujarati", HB_SCRIPT_GUJARATI }, |
| 159 |
{ "Gurmukhi", HB_SCRIPT_GURMUKHI }, |
| 160 |
{ "Hangul", HB_SCRIPT_HANGUL }, |
| 161 |
{ "Han", HB_SCRIPT_HAN }, |
| 162 |
{ "Hebrew", HB_SCRIPT_HEBREW }, |
| 163 |
{ "Hiragana", HB_SCRIPT_HIRAGANA }, |
| 164 |
{ "Kannada", HB_SCRIPT_KANNADA }, |
| 165 |
{ "Katakana", HB_SCRIPT_KATAKANA }, |
| 166 |
{ "Lao", HB_SCRIPT_LAO }, |
| 167 |
{ "Latin", HB_SCRIPT_LATIN }, |
| 168 |
{ "Malayalam", HB_SCRIPT_MALAYALAM }, |
| 169 |
{ "Oriya", HB_SCRIPT_ORIYA }, |
| 170 |
{ "Tamil", HB_SCRIPT_TAMIL }, |
| 171 |
{ "Telugu", HB_SCRIPT_TELUGU }, |
| 172 |
{ "Thai", HB_SCRIPT_THAI }, |
| 173 |
{ "Tibetan", HB_SCRIPT_TIBETAN }, |
| 174 |
{ "Bopomofo", HB_SCRIPT_BOPOMOFO } |
| 175 |
/* FIXME: complete */ |
| 176 |
}; |
| 177 |
|
| 178 |
static struct { const char *name; hb_tag_t tag; } language_names[] = { |
| 179 |
{ "Arabic", HB_TAG ('A','R','A',' ') }, |
| 180 |
{ "Romanian", HB_TAG ('R','O','M',' ') }, |
| 181 |
{ "Skolt Sami", HB_TAG ('S','K','S',' ') }, |
| 182 |
{ "Northern Sami", HB_TAG ('N','S','M',' ') }, |
| 183 |
{ "Kildin Sami", HB_TAG ('K','S','M',' ') }, |
| 184 |
{ "Moldavian", HB_TAG ('M','O','L',' ') }, |
| 185 |
{ "Turkish", HB_TAG ('T','R','K',' ') }, |
| 186 |
{ "Azerbaijani", HB_TAG ('A','Z','E',' ') }, |
| 187 |
{ "Crimean Tatar", HB_TAG ('C','R','T',' ') }, |
| 188 |
{ "Serbian", HB_TAG ('S','R','B',' ') }, |
| 189 |
{ "German", HB_TAG ('D','E','U',' ') } |
| 190 |
/* FIXME: complete */ |
| 191 |
}; |
| 192 |
|
| 193 |
typedef struct { |
| 194 |
hb_tag_t script_tag; |
| 195 |
hb_tag_t lang_tag; |
| 196 |
unsigned int script_index; |
| 197 |
unsigned int lang_index; |
| 198 |
} TagPair; |
| 199 |
|
| 200 |
static guint |
| 201 |
tag_pair_hash (gconstpointer data) |
| 202 |
{ |
| 203 |
const TagPair *pair = data; |
| 204 |
|
| 205 |
return pair->script_tag + pair->lang_tag; |
| 206 |
} |
| 207 |
|
| 208 |
static gboolean |
| 209 |
tag_pair_equal (gconstpointer a, gconstpointer b) |
| 210 |
{ |
| 211 |
const TagPair *pair_a = a; |
| 212 |
const TagPair *pair_b = b; |
| 213 |
|
| 214 |
return pair_a->script_tag == pair_b->script_tag && pair_a->lang_tag == pair_b->lang_tag; |
| 215 |
} |
| 216 |
|
| 217 |
static void |
| 218 |
update_script_combo (void) |
| 219 |
{ |
| 220 |
GtkListStore *store; |
| 221 |
hb_font_t *hb_font = NULL; |
| 222 |
gint i, j, k, l; |
| 223 |
PangoFont *pango_font; |
| 224 |
GHashTable *tags; |
| 225 |
GHashTableIter iter; |
| 226 |
TagPair *pair; |
| 227 |
gboolean cleanup_hb_face = FALSE; |
| 228 |
|
| 229 |
#ifdef FONT_FEATURES_USE_PANGOFT2 |
| 230 |
FT_Face ft_face; |
| 231 |
#endif |
| 232 |
|
| 233 |
store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT); |
| 234 |
|
| 235 |
pango_font = get_pango_font (); |
| 236 |
|
| 237 |
#ifdef FONT_FEATURES_USE_PANGOFT2 |
| 238 |
if (PANGO_IS_FC_FONT (pango_font)) |
| 239 |
{ |
| 240 |
ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)), |
| 241 |
hb_font = hb_ft_font_create (ft_face, NULL); |
| 242 |
cleanup_hb_face = TRUE; |
| 243 |
} |
| 244 |
#else |
| 245 |
hb_font = pango_font_get_hb_font (pango_font); |
| 246 |
#endif |
| 247 |
|
| 248 |
tags = g_hash_table_new_full (tag_pair_hash, tag_pair_equal, g_free, NULL); |
| 249 |
|
| 250 |
pair = g_new (TagPair, 1); |
| 251 |
pair->script_tag = HB_OT_TAG_DEFAULT_SCRIPT; |
| 252 |
pair->lang_tag = HB_OT_TAG_DEFAULT_LANGUAGE; |
| 253 |
g_hash_table_insert (tags, pair, g_strdup ("Default")); |
| 254 |
|
| 255 |
if (hb_font) |
| 256 |
{ |
| 257 |
hb_tag_t tables[2] = { HB_OT_TAG_GSUB, HB_OT_TAG_GPOS }; |
| 258 |
hb_face_t *hb_face; |
| 259 |
|
| 260 |
hb_face = hb_font_get_face (hb_font); |
| 261 |
|
| 262 |
for (i= 0; i < 2; i++) |
| 263 |
{ |
| 264 |
hb_tag_t scripts[80]; |
| 265 |
unsigned int script_count = G_N_ELEMENTS (scripts); |
| 266 |
|
| 267 |
hb_ot_layout_table_get_script_tags (hb_face, tables[i], 0, &script_count, scripts); |
| 268 |
for (j = 0; j < script_count; j++) |
| 269 |
{ |
| 270 |
hb_tag_t languages[80]; |
| 271 |
unsigned int language_count = G_N_ELEMENTS (languages); |
| 272 |
|
| 273 |
pair = g_new (TagPair, 1); |
| 274 |
pair->script_tag = scripts[j]; |
| 275 |
pair->lang_tag = HB_OT_TAG_DEFAULT_LANGUAGE; |
| 276 |
pair->script_index = j; |
| 277 |
pair->lang_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; |
| 278 |
g_hash_table_add (tags, pair); |
| 279 |
|
| 280 |
hb_ot_layout_script_get_language_tags (hb_face, tables[i], j, 0, &language_count, languages); |
| 281 |
for (k = 0; k < language_count; k++) |
| 282 |
{ |
| 283 |
pair = g_new (TagPair, 1); |
| 284 |
pair->script_tag = scripts[j]; |
| 285 |
pair->lang_tag = languages[k]; |
| 286 |
pair->script_index = j; |
| 287 |
pair->lang_index = k; |
| 288 |
g_hash_table_add (tags, pair); |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
if (cleanup_hb_face) |
| 294 |
hb_face_destroy (hb_face); |
| 295 |
} |
| 296 |
|
| 297 |
#ifdef FONT_FEATURES_USE_PANGOFT2 |
| 298 |
if (PANGO_IS_FC_FONT (pango_font)) |
| 299 |
pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font)); |
| 300 |
#endif |
| 301 |
|
| 302 |
g_object_unref (pango_font); |
| 303 |
|
| 304 |
g_hash_table_iter_init (&iter, tags); |
| 305 |
while (g_hash_table_iter_next (&iter, (gpointer *)&pair, NULL)) |
| 306 |
{ |
| 307 |
const char *scriptname; |
| 308 |
char scriptbuf[5]; |
| 309 |
const char *langname; |
| 310 |
char langbuf[5]; |
| 311 |
char *name; |
| 312 |
|
| 313 |
if (pair->script_tag == HB_OT_TAG_DEFAULT_SCRIPT) |
| 314 |
scriptname = "Default"; |
| 315 |
else if (pair->script_tag == HB_TAG ('m','a','t','h')) |
| 316 |
scriptname = "Math"; |
| 317 |
else |
| 318 |
{ |
| 319 |
hb_script_t script; |
| 320 |
|
| 321 |
hb_tag_to_string (pair->script_tag, scriptbuf); |
| 322 |
scriptbuf[4] = 0; |
| 323 |
scriptname = scriptbuf; |
| 324 |
|
| 325 |
script = hb_script_from_iso15924_tag (pair->script_tag); |
| 326 |
for (k = 0; k < G_N_ELEMENTS (script_names); k++) |
| 327 |
{ |
| 328 |
if (script == script_names[k].script) |
| 329 |
{ |
| 330 |
scriptname = script_names[k].name; |
| 331 |
break; |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
if (pair->lang_tag == HB_OT_TAG_DEFAULT_LANGUAGE) |
| 337 |
langname = "Default"; |
| 338 |
else |
| 339 |
{ |
| 340 |
hb_tag_to_string (pair->lang_tag, langbuf); |
| 341 |
langbuf[4] = 0; |
| 342 |
langname = langbuf; |
| 343 |
|
| 344 |
for (l = 0; l < G_N_ELEMENTS (language_names); l++) |
| 345 |
{ |
| 346 |
if (pair->lang_tag == language_names[l].tag) |
| 347 |
{ |
| 348 |
langname = language_names[l].name; |
| 349 |
break; |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
name = g_strdup_printf ("%s - %s", scriptname, langname); |
| 355 |
|
| 356 |
gtk_list_store_insert_with_values (store, NULL, -1, |
| 357 |
0, name, |
| 358 |
1, pair->script_index, |
| 359 |
2, pair->lang_index, |
| 360 |
3, pair->lang_tag, |
| 361 |
-1); |
| 362 |
|
| 363 |
g_free (name); |
| 364 |
} |
| 365 |
|
| 366 |
g_hash_table_destroy (tags); |
| 367 |
|
| 368 |
gtk_combo_box_set_model (GTK_COMBO_BOX (script_lang), GTK_TREE_MODEL (store)); |
| 369 |
gtk_combo_box_set_active (GTK_COMBO_BOX (script_lang), 0); |
| 370 |
} |
| 371 |
|
| 372 |
static void |
| 373 |
update_features (void) |
| 374 |
{ |
| 375 |
gint i, j, k; |
| 376 |
GtkTreeModel *model; |
| 377 |
GtkTreeIter iter; |
| 378 |
guint script_index, lang_index; |
| 379 |
PangoFont *pango_font; |
| 380 |
hb_font_t *hb_font = NULL; |
| 381 |
gboolean cleanup_hb_face = FALSE; |
| 382 |
|
| 383 |
#ifdef FONT_FEATURES_USE_PANGOFT2 |
| 384 |
FT_Face ft_face; |
| 385 |
#endif |
| 386 |
|
| 387 |
for (i = 0; i < num_features; i++) |
| 388 |
gtk_widget_set_opacity (icon[i], 0); |
| 389 |
|
| 390 |
/* set feature presence checks from the font features */ |
| 391 |
|
| 392 |
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (script_lang), &iter)) |
| 393 |
return; |
| 394 |
|
| 395 |
model = gtk_combo_box_get_model (GTK_COMBO_BOX (script_lang)); |
| 396 |
gtk_tree_model_get (model, &iter, |
| 397 |
1, &script_index, |
| 398 |
2, &lang_index, |
| 399 |
-1); |
| 400 |
|
| 401 |
pango_font = get_pango_font (); |
| 402 |
|
| 403 |
#ifdef FONT_FEATURES_USE_PANGOFT2 |
| 404 |
if (PANGO_IS_FC_FONT (pango_font)) |
| 405 |
{ |
| 406 |
ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)), |
| 407 |
hb_font = hb_ft_font_create (ft_face, NULL); |
| 408 |
cleanup_hb_face = TRUE; |
| 409 |
} |
| 410 |
#else |
| 411 |
hb_font = pango_font_get_hb_font (pango_font); |
| 412 |
#endif |
| 413 |
|
| 414 |
if (hb_font) |
| 415 |
{ |
| 416 |
hb_tag_t tables[2] = { HB_OT_TAG_GSUB, HB_OT_TAG_GPOS }; |
| 417 |
hb_face_t *hb_face; |
| 418 |
|
| 419 |
hb_face = hb_font_get_face (hb_font); |
| 420 |
|
| 421 |
for (i = 0; i < 2; i++) |
| 422 |
{ |
| 423 |
hb_tag_t features[80]; |
| 424 |
unsigned int count = G_N_ELEMENTS(features); |
| 425 |
|
| 426 |
hb_ot_layout_language_get_feature_tags (hb_face, |
| 427 |
tables[i], |
| 428 |
script_index, |
| 429 |
lang_index, |
| 430 |
0, |
| 431 |
&count, |
| 432 |
features); |
| 433 |
|
| 434 |
for (j = 0; j < count; j++) |
| 435 |
{ |
| 436 |
for (k = 0; k < num_features; k++) |
| 437 |
{ |
| 438 |
if (hb_tag_from_string (feature_names[k], -1) == features[j]) |
| 439 |
gtk_widget_set_opacity (icon[k], 0.5); |
| 440 |
} |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
if (cleanup_hb_face) |
| 445 |
hb_face_destroy (hb_face); |
| 446 |
} |
| 447 |
|
| 448 |
#ifdef FONT_FEATURES_USE_PANGOFT2 |
| 449 |
if (PANGO_IS_FC_FONT (pango_font)) |
| 450 |
pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font)); |
| 451 |
#endif |
| 452 |
|
| 453 |
g_object_unref (pango_font); |
| 454 |
} |
| 455 |
|
| 456 |
static void |
| 457 |
font_changed (void) |
| 458 |
{ |
| 459 |
update_script_combo (); |
| 460 |
} |
| 461 |
|
| 462 |
static void |
| 463 |
script_changed (void) |
| 464 |
{ |
| 465 |
update_features (); |
| 466 |
update_display (); |
| 467 |
} |
| 468 |
|
| 469 |
static void |
| 470 |
reset_features (void) |
| 471 |
{ |
| 472 |
int i; |
| 473 |
|
| 474 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (numcasedefault), TRUE); |
| 475 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (numspacedefault), TRUE); |
| 476 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fractiondefault), TRUE); |
| 477 |
for (i = 0; i < num_features; i++) |
| 478 |
{ |
| 479 |
if (!GTK_IS_RADIO_BUTTON (toggle[i])) |
| 480 |
{ |
| 481 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle[i]), FALSE); |
| 482 |
gtk_widget_set_sensitive (toggle[i], FALSE); |
| 483 |
} |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
static char *text; |
| 488 |
|
| 489 |
static void |
| 490 |
switch_to_entry (void) |
| 491 |
{ |
| 492 |
text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); |
| 493 |
gtk_stack_set_visible_child_name (GTK_STACK (stack), "entry"); |
| 494 |
} |
| 495 |
|
| 496 |
static void |
| 497 |
switch_to_label (void) |
| 498 |
{ |
| 499 |
g_free (text); |
| 500 |
text = NULL; |
| 501 |
gtk_stack_set_visible_child_name (GTK_STACK (stack), "label"); |
| 502 |
update_display (); |
| 503 |
} |
| 504 |
|
| 505 |
static gboolean |
| 506 |
entry_key_press (GtkEntry *entry, GdkEventKey *event) |
| 507 |
{ |
| 508 |
if (event->keyval == GDK_KEY_Escape) |
| 509 |
{ |
| 510 |
gtk_entry_set_text (GTK_ENTRY (entry), text); |
| 511 |
switch_to_label (); |
| 512 |
return GDK_EVENT_STOP; |
| 513 |
} |
| 514 |
|
| 515 |
return GDK_EVENT_PROPAGATE; |
| 516 |
} |
| 517 |
|
| 518 |
GtkWidget * |
| 519 |
do_font_features (GtkWidget *do_widget) |
| 520 |
{ |
| 521 |
static GtkWidget *window = NULL; |
| 522 |
|
| 523 |
if (!window) |
| 524 |
{ |
| 525 |
GtkBuilder *builder; |
| 526 |
int i; |
| 527 |
|
| 528 |
builder = gtk_builder_new_from_resource ("/font_features/font-features.ui"); |
| 529 |
|
| 530 |
gtk_builder_add_callback_symbol (builder, "update_display", update_display); |
| 531 |
gtk_builder_add_callback_symbol (builder, "font_changed", font_changed); |
| 532 |
gtk_builder_add_callback_symbol (builder, "script_changed", script_changed); |
| 533 |
gtk_builder_add_callback_symbol (builder, "reset", reset_features); |
| 534 |
gtk_builder_add_callback_symbol (builder, "switch_to_entry", switch_to_entry); |
| 535 |
gtk_builder_add_callback_symbol (builder, "switch_to_label", switch_to_label); |
| 536 |
gtk_builder_add_callback_symbol (builder, "entry_key_press", G_CALLBACK (entry_key_press)); |
| 537 |
gtk_builder_connect_signals (builder, NULL); |
| 538 |
|
| 539 |
window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); |
| 540 |
label = GTK_WIDGET (gtk_builder_get_object (builder, "label")); |
| 541 |
settings = GTK_WIDGET (gtk_builder_get_object (builder, "settings")); |
| 542 |
resetbutton = GTK_WIDGET (gtk_builder_get_object (builder, "reset")); |
| 543 |
font = GTK_WIDGET (gtk_builder_get_object (builder, "font")); |
| 544 |
script_lang = GTK_WIDGET (gtk_builder_get_object (builder, "script_lang")); |
| 545 |
numcasedefault = GTK_WIDGET (gtk_builder_get_object (builder, "numcasedefault")); |
| 546 |
numspacedefault = GTK_WIDGET (gtk_builder_get_object (builder, "numspacedefault")); |
| 547 |
fractiondefault = GTK_WIDGET (gtk_builder_get_object (builder, "fractiondefault")); |
| 548 |
stack = GTK_WIDGET (gtk_builder_get_object (builder, "stack")); |
| 549 |
entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry")); |
| 550 |
|
| 551 |
for (i = 0; i < num_features; i++) |
| 552 |
{ |
| 553 |
char *iname; |
| 554 |
|
| 555 |
toggle[i] = GTK_WIDGET (gtk_builder_get_object (builder, feature_names[i])); |
| 556 |
iname = g_strconcat (feature_names[i], "_pres", NULL); |
| 557 |
icon[i] = GTK_WIDGET (gtk_builder_get_object (builder, iname)); |
| 558 |
g_free (iname); |
| 559 |
} |
| 560 |
|
| 561 |
font_changed (); |
| 562 |
|
| 563 |
g_signal_connect (window, "destroy", |
| 564 |
G_CALLBACK (gtk_widget_destroyed), &window); |
| 565 |
|
| 566 |
g_object_unref (builder); |
| 567 |
} |
| 568 |
|
| 569 |
if (!gtk_widget_get_visible (window)) |
| 570 |
gtk_window_present (GTK_WINDOW (window)); |
| 571 |
else |
| 572 |
gtk_widget_destroy (window); |
| 573 |
|
| 574 |
return window; |
| 575 |
} |