The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

DefaultCharactersSet.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Fix translation heads/master
1 /* 2 Copyright (C) 2013, 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 /** Default character sets for several languages. */ 18 public class DefaultCharacterSet { 19 20 public static DefaultLanguages languages; 21 22 public static void create_default_character_sets () { 23 languages = new DefaultLanguages (); 24 25 add_language (t_("Default Language"), "", ""); 26 add_language (t_("Private Use Area"), "PRIVATE_USE", ""); 27 28 add_language (t_("Czech"), "cs", "A Á B C Č D Ď E É Ě F G H Ch I Í J K L M N Ň O Ó P Q R Ř S Š T Ť U Ú Ů V W X Y Ý Z Ž a á b c č d ď e é ě f g h ch i í j k l m n ň o ó p q r ř s š t ť u ú ů v w x y ý z ž"); 29 add_language (t_("Chinese"), "zh", ""); 30 add_language (t_("English"), "en", "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z"); 31 add_language (t_("Greek"), "el", "Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ ς τ υ φ χ ψ ω"); 32 add_language (t_("Japanese"), "ja", ""); 33 add_language (t_("Javanese"), "jv", "ꦀ ꦁ ꦂ ꦃ ꦄ ꦅ ꦆ ꦇ ꦈ ꦉ ꦊ ꦋ ꦌ ꦍ ꦎ ꦏ ꦐ ꦑ ꦒ ꦓ ꦔ ꦕ ꦖ ꦗ ꦘ ꦙ ꦚ ꦛ ꦜ ꦝ ꦞ ꦟ ꦠ ꦡ ꦢ ꦣ ꦤ ꦥ ꦦ ꦧ ꦨ ꦩ ꦪ ꦫ ꦬ ꦭ ꦮ ꦯ ꦰ ꦱ ꦲ ꦳ ꦴ ꦵ ꦶ ꦷ ꦸ ꦹ ꦺ ꦻ ꦼ ꦽ ꦾ ꦿ ꧀ ꧁ ꧂ ꧃ ꧄ ꧅ ꧆ ꧇ ꧈ ꧉ ꧊ ꧋ ꧌ ꧍ ꧏ ꧐ ꧑ ꧒ ꧓ ꧔ ꧕ ꧖ ꧗ ꧘ ꧙ ꧞ ꧟ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z"); 34 add_language (t_("Latin"), "la", ""); 35 add_language (t_("Russian"), "ro", "А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я"); 36 add_language (t_("Swedish"), "sv", "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Å Ä Ö a b c d e f g h i j k l m n o p q r s t u v w x y z å ä ö"); 37 add_language (t_("Thai"), "th", "ก-ฺ ฿-๛"); 38 } 39 40 /** Add a new language to the menu for default character set. 41 * @param language A localized string for the name of the language. 42 * @param language_code ISO code 43 * @param characters all characters (including characters with diacritical marks). 44 * For languages with too many glyphs should this string be left empty. 45 * See the functions for chinese and japanese. 46 */ 47 public static void add_language (string language, string language_code, string characters) { 48 DefaultLanguages.names.add (language); 49 DefaultLanguages.codes.add (language_code); 50 DefaultLanguages.characters.add (characters); 51 } 52 53 /** Add all glyphs for the current locale settings to this glyph range. */ 54 public static void use_default_range (GlyphRange gr) { 55 string language = get_prefered_language_code (); 56 57 if (language == "PRIVATE_USE") { 58 use_private_area (gr); 59 } else if (language.has_prefix ("ja")) { 60 use_default_range_japanese (gr); 61 } else if (language.has_prefix ("la")) { 62 use_default_range_latin (gr); 63 } else if (language.has_prefix ("zh")) { // TODO: not just simplified chinese 64 use_default_range_chinese (gr); 65 } else { 66 use_default_range_alphabetic (gr); 67 } 68 69 gr.name = "Default"; 70 } 71 72 private static string get_prefered_language_code () { 73 string prefered_language; 74 string[] languages = Intl.get_language_names (); 75 76 prefered_language = Preferences.get ("language"); 77 78 if (prefered_language != "") { 79 return prefered_language; 80 } 81 82 if (languages.length == 0) { 83 return ""; 84 } 85 86 return languages[0]; 87 } 88 89 public static string get_characters_for_prefered_language () { 90 string lang = get_prefered_language_code (); 91 int i = 0; 92 string characters = ""; 93 94 foreach (string code in DefaultLanguages.codes) { 95 if (lang.has_prefix (code)) { 96 characters = DefaultLanguages.characters.get (i); 97 } 98 i++; 99 } 100 101 return characters; 102 } 103 104 private static void use_private_area (GlyphRange gr) { 105 gr.add_range (0xe000, 0xf8ff); 106 } 107 108 private static void use_default_range_alphabetic (GlyphRange gr) { 109 string lower_case, upper_case; 110 string all_characters; 111 112 all_characters = get_characters_for_prefered_language (); 113 114 try { 115 if (all_characters != "") { 116 gr.parse_ranges (all_characters); 117 } else { 118 /// All lower case letters in alphabetic order separated by space. Letters with diacritical marks should be included. 119 lower_case = t_("a b c d e f g h i j k l m n o p q r s t u v w x y z"); 120 121 /// All upper case letters in alphabetic order separated by space. Letters with diacritical marks should be included. 122 upper_case = t_("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"); 123 124 gr.parse_ranges (lower_case); 125 gr.parse_ranges (upper_case); 126 } 127 } catch (GLib.Error e) { 128 warning (e.message); 129 } 130 131 gr.add_range ('0', '9'); 132 133 gr.add_single (' '); // TODO: add all spaces here. 134 135 gr.add_single ('.'); 136 gr.add_single ('?'); 137 138 gr.add_single (','); 139 140 gr.add_single ('’'); 141 142 gr.add_range ('“', '”'); 143 144 gr.add_single ('&'); 145 146 gr.add_range (':', ';'); 147 148 gr.add_single ('/'); 149 150 gr.add_range ('!', '/'); 151 152 gr.add_single ('-'); 153 gr.add_range ('‐', '—'); 154 gr.add_range ('<', '@'); 155 gr.add_range ('(', ')'); 156 } 157 158 public static void use_default_range_japanese (GlyphRange gr) { 159 // hiragana 160 gr.add_range ('ぁ', 'ゖ'); 161 gr.add_range ('゙', 'ゟ'); 162 163 // halfwidth and fullwidth forms 164 gr.add_range ('!', 'ᄒ'); 165 gr.add_range ('ᅡ', 'ᅦ'); 166 gr.add_range ('ᅧ', 'ᅬ'); 167 gr.add_range ('ᅭ', 'ᅲ'); 168 gr.add_range ('ᅳ', 'ᅵ'); 169 gr.add_range ('¢', '₩'); 170 gr.add_range ('│', '○'); 171 172 // katakana phonetic extensions 173 gr.add_range ('ㇰ', 'ㇿ'); 174 175 // kana supplement 176 gr.add_single ('𛀀'); 177 gr.add_single ('𛀁'); 178 179 // kanbun 180 gr.add_range ('㆐', '㆟'); 181 } 182 183 public static void use_default_range_chinese (GlyphRange gr) { 184 string pinyin_tones; 185 186 // pinyin 187 pinyin_tones = "ˇ ˉ ˊ ˋ ˙ ā á ǎ à ō ó ǒ ò ē é ě è ī í ǐ ì ū ú ǔ ù ǖ ǘ ǚ ǜ ü Ā Á Ǎ À Ō Ó Ǒ Ò Ē É Ě È"; 188 gr.add_range ('a', 'z'); 189 190 foreach (string c in pinyin_tones.split (" ")) { 191 gr.add_single (c.get_char ()); 192 } 193 194 // CJK punctuations and symbols 195 gr.add_range (' ', '々'); 196 gr.add_range ('〇', '】'); 197 gr.add_range ('〓', '〟'); 198 gr.add_range ('︐', '︙'); 199 200 // CJK numbers and months 201 gr.add_range ('0', '9'); 202 gr.add_range ('㈠', '㈩'); 203 gr.add_range ('㋀', '㋋'); 204 gr.add_range ('㉑', '㉟'); 205 gr.add_range ('㊱', '㊿'); 206 gr.add_range ('㊀', '㊉'); 207 208 // CJK fullwidth letters and symbols 209 gr.add_range ('!', '・'); 210 gr.add_range ('¢', '₩'); 211 gr.add_single ('│'); 212 213 // CJK special characters 214 gr.add_range ('㍘', '㏿'); 215 gr.add_range ('㋌', '㋏'); 216 217 // CJK strokes 218 gr.add_range ('㇀', '㇢'); 219 220 // CJK supplements 221 gr.add_range ('⺀', '⺙'); 222 gr.add_range ('⺛', '⻳'); 223 224 // GB2312 (punctuations) 225 gr.add_single ('―'); 226 gr.add_single ('¤'); 227 gr.add_single ('§'); 228 gr.add_single ('¨'); 229 gr.add_single ('°'); 230 gr.add_single ('±'); 231 gr.add_single ('×'); 232 gr.add_single ('÷'); 233 234 // GB2312 (greek letters) 235 gr.add_range ('Α', 'Ω'); 236 gr.add_range ('α', 'ω'); 237 238 // GB2312 (cyrillic letters) 239 gr.add_range ('А', 'я'); 240 gr.add_single ('ё'); 241 gr.add_single ('Ё'); 242 243 // GB2312 (U+4e00 to U+fa20) 244 gr.add_range ('一', '龥'); 245 gr.add_single ('郎'); 246 gr.add_single ('凉'); 247 gr.add_single ('秊'); 248 gr.add_single ('裏'); 249 gr.add_single ('隣'); 250 251 gr.add_range ('兀', '﨏'); 252 gr.add_single ('﨑'); 253 gr.add_single ('﨓'); 254 gr.add_single ('﨔'); 255 gr.add_single ('礼'); 256 gr.add_single ('﨟'); 257 gr.add_single ('蘒'); 258 gr.add_single ('﨡'); 259 gr.add_single ('﨣'); 260 gr.add_single ('﨤'); 261 gr.add_single ('﨧'); 262 gr.add_single ('﨨'); 263 gr.add_single ('﨩'); 264 } 265 266 public static void use_default_range_latin (GlyphRange gr) { 267 gr.add_range ('!', '~'); 268 gr.add_range ('¡', 'ʯ'); 269 } 270 271 public static void use_full_unicode_range (GlyphRange gr) { 272 CharDatabase.get_full_unicode (gr); 273 274 if (gr.get_length () == 0) { 275 try { 276 gr.parse_ranges ("null-ͷ ͺ-; ΄-Ί Ό Ύ-Ρ Σ-ԧ Ա-Ֆ ՙ-՟ ա-և ։-֊ ֏ ֑-ׇ א-ת װ-״ ؀-؄ ؆-؛ ؞-܍ ܏-݊ ݍ-ޱ ߀-ߺ ࠀ-࠭ ࠰-࠾ ࡀ-࡛ ࡞ ࢠ ࢢ-ࢬ ࣤ-ࣾ ऀ-ॷ ॹ-ॿ ঁ-ঃ অ-ঌ এ-ঐ ও-ন প-র ল শ-হ ়-ৄ ে-ৈ ো-ৎ ৗ ড়-ঢ় য়-৻ ਁ-ਃ ਅ-ਊ ਏ-ਐ ਓ-ਨ ਪ-ਰ ਲ-ਲ਼ ਵ-ਸ਼ ਸ-ਹ ਼ ਾ-ੂ ੇ-ੈ ੋ-੍ ੑ ਖ਼-ੜ ਫ਼ ੤-ੵ ઁ-ઃ અ-ઍ એ-ઑ ઓ-ન પ-ર લ-ળ વ-હ ઼-ૅ ે-ૉ ો-્ ૐ ૠ-૱ ଁ-ଃ ଅ-ଌ ଏ-ଐ ଓ-ନ ପ-ର ଲ-ଳ ଵ-ହ ଼-ୄ େ-ୈ ୋ-୍ ୖ-ୗ ଡ଼-ଢ଼ ୟ-୷ ஂ-ஃ அ-ஊ எ-ஐ ஒ-க ங-ச ஜ ஞ-ட ண-த ந-ப ம-ஹ ா-ூ ெ-ை ொ-் ௐ ௗ ௤-௺ ఁ-ః అ-ఌ ఎ-ఐ ఒ-న ప-ళ వ-హ ఽ-ౄ ె-ై ొ-్ ౕ-ౖ ౘ-ౙ ౠ-౯ ౸-౿ ಂ-ಃ ಅ-ಌ ಎ-ಐ ಒ-ನ ಪ-ಳ ವ-ಹ ಼-ೄ ೆ-ೈ ೊ-್ ೕ-ೖ ೞ ೠ-೯ ೱ-ೲ ം-ഃ അ-ഌ എ-ഐ ഒ-ഺ ഽ-ൄ െ-ൈ ൊ-ൎ ൗ ൠ-൵ ൹-ൿ ං-ඃ අ-ඖ ක-න ඳ-ර ල ව-ෆ ් ා-ු ූ ෘ-ෟ ෲ-෴ ก-ฺ ฿-๛ ກ-ຂ ຄ ງ-ຈ ຊ ຍ ດ-ທ ນ-ຟ ມ-ຣ ລ ວ ສ-ຫ ອ-ູ ົ-ຽ ເ-ໄ ໆ ່-ໍ ໐-໙ ໜ-ໟ ༀ-ཇ ཉ-ཬ ཱ-ྗ ྙ-ྼ ྾-࿌ ࿎-࿚ က-Ⴥ Ⴧ Ⴭ ა-ቈ ቊ-ቍ ቐ-ቖ ቘ ቚ-ቝ በ-ኈ ኊ-ኍ ነ-ኰ ኲ-ኵ ኸ-ኾ ዀ ዂ-ዅ ወ-ዖ ዘ-ጐ ጒ-ጕ ጘ-ፚ ፝-፼ ᎀ-᎙ Ꭰ-Ᏼ ᐀-᚜ ᚠ-ᛰ ᜀ-ᜌ ᜎ-᜔ ᜠ-᜶ ᝀ-ᝓ ᝠ-ᝬ ᝮ-ᝰ ᝲ-ᝳ ក-៝ ០-៩ ៰-៹ ᠀-᠎ ᠐-᠙ ᠠ-ᡷ ᢀ-ᢪ ᢰ-ᣵ ᤀ-ᤜ ᤠ-ᤫ ᤰ-᤻ ᥀ ᥄-ᥭ ᥰ-ᥴ ᦀ-ᦫ ᦰ-ᧉ ᧐-᧚ ᧞-ᨛ ᨞-ᩞ ᩠-᩼ ᩿-᪉ ᪐-᪙ ᪠-᪭ ᬀ-ᭋ ᭐-᭼ ᮀ-᯳ ᯼-᰷ ᰻-᱉ ᱍ-᱿ ᳀-᳇ ᳐-ᳶ ᴀ-ᷦ ᷼-ἕ Ἐ-Ἕ ἠ-ὅ Ὀ-Ὅ ὐ-ὗ Ὑ Ὓ Ὕ Ὗ-ώ ᾀ-ᾴ ᾶ-ῄ ῆ-ΐ ῖ-Ί ῝-` ῲ-ῴ ῶ-῾  -⁤ -₎ ₐ-ₜ ₠-₹ ⃐-⃰ ℀-↉ ←-⏳ ␀-␦ ⑀-⑊ ①-⛿ ✁-⭌ ⭐-⭙ Ⰰ-Ⱞ ⰰ-ⱞ Ⱡ-ⳳ ⳹-ⴥ ⴧ ⴭ ⴰ-ⵧ ⵯ-⵰ ⵿-ⶖ ⶠ-ⶦ ⶨ-ⶮ ⶰ-ⶶ ⶸ-ⶾ ⷀ-ⷆ ⷈ-ⷎ ⷐ-ⷖ ⷘ-ⷞ ⷠ-⸻ ⺀-⺙ ⺛-⻳ ⼀-⿕ ⿰-⿻  -〿 ぁ-ゖ ゙-ヿ ㄅ-ㄭ ㄱ-ㆎ ㆐-ㆺ ㇀-㇣ ㇰ-㈞ ㈠-㋾ ㌀-㏿ ䷀-䷿ ꀀ-ꒌ ꒐-꓆ ꓐ-ꘫ Ꙁ-ꚗ ꚟ-꛷ ꜀-ꞎ Ꞑ-ꞓ Ꞡ-Ɦ ꟸ-꠫ ꠰-꠹ ꡀ-꡷ ꢀ-꣄ ꣎-꣙ ꣠-ꣻ ꤀-꥓ ꥟-ꥼ ꦀ-꧍ ꧏ-꧙ ꧞-꧟ ꨀ-ꨶ ꩀ-ꩍ ꩐-꩙ ꩜-ꩻ ꪀ-ꫂ ꫛ-꫶ ꬁ-ꬆ ꬉ-ꬎ ꬑ-ꬖ ꬠ-ꬦ ꬨ-ꬮ ꯀ-꯭ ꯰-꯹ ힰ-ퟆ ퟋ-ퟻ 豈-舘 並-龎 ff-st ﬓ-ﬗ יִ-זּ טּ-לּ מּ נּ-סּ ףּ-פּ צּ-﯁ ﯓ-﴿ ﵐ-ﶏ ﶒ-ﷇ ﷰ-﷽ ︀-︙ ︠-︦ ︰-﹒ ﹔-﹦ ﹨-﹫ ﹰ-ﹴ ﹶ-ﻼ !-ᄒ ᅡ-ᅦ ᅧ-ᅬ ᅭ-ᅲ ᅳ-ᅵ ¢-₩ │-○ -� 𐀀-𐀋 𐀍-𐀦 𐀨-𐀺 𐀼-𐀽 𐀿-𐁍 𐁐-𐁝 𐂀-𐃺 𐄀-𐄂 𐄇-𐄳 𐄷-𐆊 𐆐-𐆛 𐇐-𐇽 𐊀-𐊜 𐊠-𐋐 𐌀-𐌞 𐌠-𐌣 𐌰-𐍊 𐎀-𐎝 𐎟-𐏃 𐏈-𐏕 𐐀-𐒝 𐒠-𐒩 𐠀-𐠅 𐠈 𐠊-𐠵 𐠷-𐠸 𐠼 𐠿-𐡕 𐡗-𐡟 𐤀-𐤛 𐤟-𐤹 𐤿 𐦀-𐦷 𐦾-𐦿 𐨀-𐨃 𐨅-𐨆 𐨌-𐨓 𐨕-𐨗 𐨙-𐨳 𐨸-𐨺 𐨿-𐩇 𐩐-𐩘 𐩠-𐩿 𐬀-𐬵 𐬹-𐭕 𐭘-𐭲 𐭸-𐭿 𐰀-𐱈 𐹠-𐹾 𑀀-𑁍 𑁒-𑁯 𑂀-𑃁 𑃐-𑃨 𑃰-𑃹 𑄀-𑄴 𑄶-𑅃 𑆀-𑇈 𑇐-𑇙 𑚀-𑚷 𑛀-𑛉 𒀀-𒍮 𒐀-𒑢 𒑰-𒑳 𓀀-𓐮 𖠀-𖨸 𖼀-𖽄 𖽐-𖽾 𖾏-𖾟 𛀀-𛀁 𝀀-𝃵 𝄀-𝄦 𝄩-𝇝 𝈀-𝉅 𝌀-𝍖 𝍠-𝍱 𝐀-𝚥 𝚨-𝟋 𝟎-𝟿 𞸀-𞸃 𞸅-𞸟 𞸡-𞸢 𞸤 𞸧 𞸩-𞸲 𞸴-𞸷 𞸹 𞸻 𞹂 𞹇 𞹉 𞹋 𞹍-𞹏 𞹑-𞹒 𞹔 𞹗 𞹙 𞹛 𞹝 𞹟 𞹡-𞹢 𞹤 𞹧-𞹪 𞹬-𞹲 𞹴-𞹷 𞹹-𞹼 𞹾 𞺀-𞺉 𞺋-𞺛 𞺡-𞺣 𞺥-𞺩 𞺫-𞺻 𞻰-𞻱 🀀-🀫 🀰-🂓 🂠-🂮 🂱-🂾 🃁-🃏 🃑-🃟 🄀-🄊 🄐-🄮 🄰-🅫 🅰-🆚 🇦-🈂 🈐-🈺 🉀-🉈 🉐-🉑 🌀-🌠 🌰-🌵 🌷-🍼 🎀-🎓 🎠-🏄 🏆-🏊 🏠-🏰 🐀-🐾 👀 👂-📷 📹-📼 🔀-🔽 🕀-🕃 🕐-🕧 🗻-🙀 🙅-🙏 🚀-🛅 🜀-🝳 丽-𪘀 󠀁 󠀠-󠁿 󠄀-󠇯"); 277 } catch (MarkupError e) { 278 warning (e.message); 279 gr.add_range ('\0', (unichar) 0xFFF8); 280 } 281 } 282 283 gr.name = "Unicode"; 284 } 285 286 public static DefaultLanguages get_default_languages () { 287 return languages; 288 } 289 } 290 291 public class DefaultLanguages { 292 public static Gee.ArrayList<string> names; 293 public static Gee.ArrayList<string> codes; 294 public static Gee.ArrayList<string> characters; 295 296 public DefaultLanguages () { 297 names = new Gee.ArrayList<string> (); 298 codes = new Gee.ArrayList<string> (); 299 characters = new Gee.ArrayList<string> (); 300 } 301 302 public string? get_name (int index) { 303 if (0 <= index < names.size) { 304 return names.get (index); 305 } 306 307 return null; 308 } 309 310 public string? get_code (int index) { 311 if (0 <= index < codes.size) { 312 return codes.get (index); 313 } 314 315 return null; 316 } 317 } 318 319 } 320