From 74d99766e4094f249bd9fc32071d85e6e0624169 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Oct 2020 09:56:04 -0400 Subject: [PATCH] gtk-demo: Fix up the Characters demo Move the Unicode names to a separate source file, and only build the demo if we have harfbuzz (since we use script names, and those are only available with harfbuzz). Also, fix a forgotten type name. --- demos/gtk-demo/listview_ucd.c | 149 +--------------------------- demos/gtk-demo/meson.build | 5 +- demos/gtk-demo/unicode-names.c | 174 +++++++++++++++++++++++++++++++++ demos/gtk-demo/unicode-names.h | 7 ++ 4 files changed, 187 insertions(+), 148 deletions(-) create mode 100644 demos/gtk-demo/unicode-names.c create mode 100644 demos/gtk-demo/unicode-names.h diff --git a/demos/gtk-demo/listview_ucd.c b/demos/gtk-demo/listview_ucd.c index 8a6d642f5e..ecaa37d9ac 100644 --- a/demos/gtk-demo/listview_ucd.c +++ b/demos/gtk-demo/listview_ucd.c @@ -6,6 +6,7 @@ #include #include "script-names.h" +#include "unicode-names.h" #define UCD_TYPE_ITEM (ucd_item_get_type ()) @@ -171,43 +172,12 @@ bind_type (GtkSignalListItemFactory *factory, GtkWidget *label; GObject *item; gunichar codepoint; - const char *types[] = { - "Other, Control", - "Other, Format", - "Other, Not Assigned", - "Other, Private Use", - "Letter, Lowercase", - "Letter, Modifier", - "Letter, Other", - "Letter, Titlecase", - "Letter, Uppercase", - "Mark, Spacing", - "Mark, Enclosing", - "Mark, Nonspacing", - "Number, Decimal Digit", - "Number, Letter", - "Number, Other", - "Punctuation, Connector", - "Punctuation, Dash", - "Punctuation, Close", - "Punctuation, Final quote", - "Punctuation, Initial quote", - "Punctuation, Other", - "Punctuation, Open", - "Symbol, Currency", - "Symbol, Modifier", - "Symbol, Math", - "Symbol, Other", - "Separator, Line", - "Separator, Paragraph", - "Separator, Space", - }; label = gtk_list_item_get_child (GTK_LIST_ITEM (listitem)); item = gtk_list_item_get_item (GTK_LIST_ITEM (listitem)); codepoint = ucd_item_get_codepoint (UCD_ITEM (item)); - gtk_label_set_label (GTK_LABEL (label), types[g_unichar_type (codepoint)]); + gtk_label_set_label (GTK_LABEL (label), get_unicode_type_name (g_unichar_type (codepoint))); } static void @@ -217,57 +187,12 @@ bind_break_type (GtkSignalListItemFactory *factory, GtkWidget *label; GObject *item; gunichar codepoint; - const char *break_types[] = { - "Mandatory Break", - "Carriage Return", - "Line Feed", - "Attached Characters and Combining Marks", - "Surrogates", - "Zero Width Space", - "Inseparable", - "Non-breaking (\"Glue\")", - "Contingent Break Opportunity", - "Space", - "Break Opportunity After", - "Break Opportunity Before", - "Break Opportunity Before and After", - "Hyphen", - "Nonstarter", - "Opening Punctuation", - "Closing Punctuation", - "Ambiguous Quotation", - "Exclamation/Interrogation", - "Ideographic", - "Numeric", - "Infix Separator (Numeric)", - "Symbols Allowing Break After", - "Ordinary Alphabetic and Symbol Characters", - "Prefix (Numeric)", - "Postfix (Numeric)", - "Complex Content Dependent (South East Asian)", - "Ambiguous (Alphabetic or Ideographic)", - "Unknown", - "Next Line", - "Word Joiner", - "Hangul L Jamo", - "Hangul V Jamo", - "Hangul T Jamo", - "Hangul LV Syllable", - "Hangul LVT Syllable", - "Closing Parenthesis", - "Conditional Japanese Starter", - "Hebrew Letter", - "Regional Indicator", - "Emoji Base", - "Emoji Modifier", - "Zero Width Joiner", - }; label = gtk_list_item_get_child (GTK_LIST_ITEM (listitem)); item = gtk_list_item_get_item (GTK_LIST_ITEM (listitem)); codepoint = ucd_item_get_codepoint (UCD_ITEM (item)); - gtk_label_set_label (GTK_LABEL (label), break_types[g_unichar_break_type (codepoint)]); + gtk_label_set_label (GTK_LABEL (label), get_break_type_name (g_unichar_break_type (codepoint))); } static void @@ -277,78 +202,12 @@ bind_combining_class (GtkSignalListItemFactory *factory, GtkWidget *label; GObject *item; gunichar codepoint; - const char *classes[255] = { 0, }; - - classes[0] = "Not Reordered"; - classes[1] = "Overlay"; - classes[7] = "Nukta"; - classes[8] = "Kana Voicing"; - classes[9] = "Virama"; - classes[10] = "CCC10 (Hebrew)"; - classes[11] = "CCC11 (Hebrew)"; - classes[12] = "CCC12 (Hebrew)"; - classes[13] = "CCC13 (Hebrew)"; - classes[14] = "CCC14 (Hebrew)"; - classes[15] = "CCC15 (Hebrew)"; - classes[16] = "CCC16 (Hebrew)"; - classes[17] = "CCC17 (Hebrew)"; - classes[18] = "CCC18 (Hebrew)"; - classes[19] = "CCC19 (Hebrew)"; - classes[20] = "CCC20 (Hebrew)"; - classes[21] = "CCC21 (Hebrew)"; - classes[22] = "CCC22 (Hebrew)"; - classes[23] = "CCC23 (Hebrew)"; - classes[24] = "CCC24 (Hebrew)"; - classes[25] = "CCC25 (Hebrew)"; - classes[26] = "CCC26 (Hebrew)"; - - classes[27] = "CCC27 (Arabic)"; - classes[28] = "CCC28 (Arabic)"; - classes[29] = "CCC29 (Arabic)"; - classes[30] = "CCC30 (Arabic)"; - classes[31] = "CCC31 (Arabic)"; - classes[32] = "CCC32 (Arabic)"; - classes[33] = "CCC33 (Arabic)"; - classes[34] = "CCC34 (Arabic)"; - classes[35] = "CCC35 (Arabic)"; - - classes[36] = "CCC36 (Syriac)"; - - classes[84] = "CCC84 (Telugu)"; - classes[85] = "CCC85 (Telugu)"; - - classes[103] = "CCC103 (Thai)"; - classes[107] = "CCC107 (Thai)"; - - classes[118] = "CCC118 (Lao)"; - classes[122] = "CCC122 (Lao)"; - - classes[129] = "CCC129 (Tibetan)"; - classes[130] = "CCC130 (Tibetan)"; - classes[133] = "CCC133 (Tibetan)"; - - classes[200] = "Attached Below Left"; - classes[202] = "Attached Below"; - classes[214] = "Attached Above"; - classes[216] = "Attached Above Right"; - classes[218] = "Below Left"; - classes[220] = "Below"; - classes[222] = "Below Right"; - classes[224] = "Left"; - classes[226] = "Right"; - classes[228] = "Above Left"; - classes[230] = "Above"; - classes[232] = "Above Right"; - classes[233] = "Double Below"; - classes[234] = "Double Above"; - classes[240] = "Iota Subscript"; - classes[255] = "Invalid"; label = gtk_list_item_get_child (GTK_LIST_ITEM (listitem)); item = gtk_list_item_get_item (GTK_LIST_ITEM (listitem)); codepoint = ucd_item_get_codepoint (UCD_ITEM (item)); - gtk_label_set_label (GTK_LABEL (label), classes[g_unichar_combining_class (codepoint)]); + gtk_label_set_label (GTK_LABEL (label), get_combining_class_name (g_unichar_combining_class (codepoint))); } static void diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build index 5fb736adef..095a64ed63 100644 --- a/demos/gtk-demo/meson.build +++ b/demos/gtk-demo/meson.build @@ -54,7 +54,6 @@ demos = files([ 'listview_filebrowser.c', 'listview_minesweeper.c', 'listview_settings.c', - 'listview_ucd.c', 'listview_weather.c', 'listview_words.c', 'markup.c', @@ -122,8 +121,8 @@ extra_demo_sources = files(['main.c', 'demo3widget.c']) if harfbuzz_dep.found() and pangoft_dep.found() - demos += files('font_features.c') - extra_demo_sources += files(['script-names.c', 'language-names.c']) + demos += files(['font_features.c', 'listview_ucd.c']) + extra_demo_sources += files(['script-names.c', 'language-names.c', 'unicode-names.c']) gtkdemo_deps += [ harfbuzz_dep, epoxy_dep ] endif diff --git a/demos/gtk-demo/unicode-names.c b/demos/gtk-demo/unicode-names.c new file mode 100644 index 0000000000..6c4f21924a --- /dev/null +++ b/demos/gtk-demo/unicode-names.c @@ -0,0 +1,174 @@ +#include "unicode-names.h" + +const char * +get_unicode_type_name (GUnicodeType type) +{ + const char *names[] = { + "Other, Control", + "Other, Format", + "Other, Not Assigned", + "Other, Private Use", + "Other, Surrogate", + "Letter, Lowercase", + "Letter, Modifier", + "Letter, Other", + "Letter, Titlecase", + "Letter, Uppercase", + "Mark, Spacing", + "Mark, Enclosing", + "Mark, Nonspacing", + "Number, Decimal Digit", + "Number, Letter", + "Number, Other", + "Punctuation, Connector", + "Punctuation, Dash", + "Punctuation, Close", + "Punctuation, Final quote", + "Punctuation, Initial quote", + "Punctuation, Other", + "Punctuation, Open", + "Symbol, Currency", + "Symbol, Modifier", + "Symbol, Math", + "Symbol, Other", + "Separator, Line", + "Separator, Paragraph", + "Separator, Space", + }; + + if (type < G_N_ELEMENTS (names)) + return names[type]; + + return "Unknown"; +} + +const char * +get_break_type_name (GUnicodeBreakType type) +{ + const char *names[] = { + "Mandatory Break", + "Carriage Return", + "Line Feed", + "Attached Characters and Combining Marks", + "Surrogates", + "Zero Width Space", + "Inseparable", + "Non-breaking (\"Glue\")", + "Contingent Break Opportunity", + "Space", + "Break Opportunity After", + "Break Opportunity Before", + "Break Opportunity Before and After", + "Hyphen", + "Nonstarter", + "Opening Punctuation", + "Closing Punctuation", + "Ambiguous Quotation", + "Exclamation/Interrogation", + "Ideographic", + "Numeric", + "Infix Separator (Numeric)", + "Symbols Allowing Break After", + "Ordinary Alphabetic and Symbol Characters", + "Prefix (Numeric)", + "Postfix (Numeric)", + "Complex Content Dependent (South East Asian)", + "Ambiguous (Alphabetic or Ideographic)", + "Unknown", + "Next Line", + "Word Joiner", + "Hangul L Jamo", + "Hangul V Jamo", + "Hangul T Jamo", + "Hangul LV Syllable", + "Hangul LVT Syllable", + "Closing Parenthesis", + "Conditional Japanese Starter", + "Hebrew Letter", + "Regional Indicator", + "Emoji Base", + "Emoji Modifier", + "Zero Width Joiner", + }; + + if (type < G_N_ELEMENTS (names)) + return names[type]; + + return "Unknown"; +} + +const char * +get_combining_class_name (int cclass) +{ + const char *classes[255] = { 0, }; + + classes[0] = "Not Reordered"; + classes[1] = "Overlay"; + classes[7] = "Nukta"; + classes[8] = "Kana Voicing"; + classes[9] = "Virama"; + classes[10] = "CCC10 (Hebrew)"; + classes[11] = "CCC11 (Hebrew)"; + classes[12] = "CCC12 (Hebrew)"; + classes[13] = "CCC13 (Hebrew)"; + classes[14] = "CCC14 (Hebrew)"; + classes[15] = "CCC15 (Hebrew)"; + classes[16] = "CCC16 (Hebrew)"; + classes[17] = "CCC17 (Hebrew)"; + classes[18] = "CCC18 (Hebrew)"; + classes[19] = "CCC19 (Hebrew)"; + classes[20] = "CCC20 (Hebrew)"; + classes[21] = "CCC21 (Hebrew)"; + classes[22] = "CCC22 (Hebrew)"; + classes[23] = "CCC23 (Hebrew)"; + classes[24] = "CCC24 (Hebrew)"; + classes[25] = "CCC25 (Hebrew)"; + classes[26] = "CCC26 (Hebrew)"; + + classes[27] = "CCC27 (Arabic)"; + classes[28] = "CCC28 (Arabic)"; + classes[29] = "CCC29 (Arabic)"; + classes[30] = "CCC30 (Arabic)"; + classes[31] = "CCC31 (Arabic)"; + classes[32] = "CCC32 (Arabic)"; + classes[33] = "CCC33 (Arabic)"; + classes[34] = "CCC34 (Arabic)"; + classes[35] = "CCC35 (Arabic)"; + + classes[36] = "CCC36 (Syriac)"; + + classes[84] = "CCC84 (Telugu)"; + classes[85] = "CCC85 (Telugu)"; + + classes[103] = "CCC103 (Thai)"; + classes[107] = "CCC107 (Thai)"; + + classes[118] = "CCC118 (Lao)"; + classes[122] = "CCC122 (Lao)"; + + classes[129] = "CCC129 (Tibetan)"; + classes[130] = "CCC130 (Tibetan)"; + classes[133] = "CCC133 (Tibetan)"; + + classes[200] = "Attached Below Left"; + classes[202] = "Attached Below"; + classes[214] = "Attached Above"; + classes[216] = "Attached Above Right"; + classes[218] = "Below Left"; + classes[220] = "Below"; + classes[222] = "Below Right"; + classes[224] = "Left"; + classes[226] = "Right"; + classes[228] = "Above Left"; + classes[230] = "Above"; + classes[232] = "Above Right"; + classes[233] = "Double Below"; + classes[234] = "Double Above"; + classes[240] = "Iota Subscript"; + classes[255] = "Invalid"; + + if (cclass < 256 && classes[cclass] != NULL) + return classes[cclass]; + + return "Unknown"; +} diff --git a/demos/gtk-demo/unicode-names.h b/demos/gtk-demo/unicode-names.h new file mode 100644 index 0000000000..4442cad21b --- /dev/null +++ b/demos/gtk-demo/unicode-names.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +const char * get_unicode_type_name (GUnicodeType type); +const char * get_break_type_name (GUnicodeBreakType type); +const char * get_combining_class_name (int cclass);