The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

UnicodeRangeBits.vala in libbirdfont/OpenFontFormat

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

Revisions

View the latest version of libbirdfont/OpenFontFormat/UnicodeRangeBits.vala.
Language fix heads/multimaster
1 /* 2 Copyright (C) 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 public class UnicodeRangeBits : GLib.Object { 18 19 Gee.ArrayList<RangeBit> bits = new Gee.ArrayList<RangeBit> (); 20 21 public UnicodeRangeBits () { 22 add_ranges (); 23 } 24 25 public void get_ranges (Font font, out uint32 r0, out uint32 r1, out uint32 r2, out uint32 r3) { 26 uint32 index; 27 GlyphCollection? gl; 28 GlyphCollection g; 29 int bit; 30 31 r0 = 0; 32 r1 = 0; 33 r2 = 0; 34 r3 = 0; 35 36 for (index = 0; (gl = font.get_glyph_collection_index (index)) != null; index++) { 37 g = (!) gl; 38 if (!g.is_unassigned ()) { 39 bit = get_bit (g.get_unicode_character ()); 40 if (likely (bit >= 0)) { 41 set_bit (bit, ref r0, ref r1, ref r2, ref r3); 42 } else { 43 warning (@"Can't find range for character $(g.get_name ())."); 44 } 45 } 46 } 47 } 48 49 void set_bit (int bit, ref uint32 r0, ref uint32 r1, ref uint32 r2, ref uint32 r3) { 50 const int length = 32; 51 52 if (0 <= bit <= length) { 53 r0 |= 1 << bit; 54 } else if (length <= bit <= 2 * length) { 55 r1 |= 1 << (bit - length); 56 } else if (2 * length <= bit <= 3 * length) { 57 r2 |= 1 << (bit - 2 * length); 58 } else if (3 * length <= bit <= 122) { 59 r3 |= 1 << (bit - 3 * length); 60 } else if (unlikely (bit > 122)) { 61 warning ("Reserved bit"); 62 } 63 } 64 65 int get_bit (unichar c) { 66 foreach (RangeBit b in bits) { 67 if (b.range.has_character (c)) { 68 return b.bit; 69 } 70 } 71 72 return -1; 73 } 74 75 void add_range (int bit, unichar start, unichar stop) { 76 bits.add (new RangeBit (bit, start, stop)); 77 } 78 79 void add_ranges () { 80 add_range (0, 0x0000, 0x007F); // Basic Latin 81 add_range (1, 0x0080, 0x00FF); // Latin-1 Supplement 82 add_range (2, 0x0100, 0x017F); // Latin Extended-A 83 add_range (3, 0x0180, 0x024F); // Latin Extended-B 84 add_range (4, 0x0250, 0x02AF); // IPA Extensions 85 add_range (4, 0x1D00, 0x1D7F); // Phonetic Extensions 86 add_range (4, 0x1D80, 0x1DBF); // Phonetic Extensions Supplement 87 add_range (4, 0x02B0, 0x02FF); // Spacing Modifier Letters 88 add_range (4, 0xA700, 0xA71F); // Modifier Tone Letters 89 add_range (4, 0x0300, 0x036F); // Combining Diacritical Marks 90 add_range (4, 0x1DC0, 0x1DFF); // Combining Diacritical Marks Supplement 91 add_range (7, 0x0370, 0x03FF); // Greek and Coptic 92 add_range (8, 0x2C80, 0x2CFF); // Coptic 93 add_range (9, 0x0400, 0x04FF); // Cyrillic 94 add_range (9, 0x0500, 0x052F); // Cyrillic Supplement 95 add_range (9, 0x2DE0, 0x2DFF); // Cyrillic Extended-A 96 add_range (9, 0xA640, 0xA69F); // Cyrillic Extended-B 97 add_range (10, 0x0530, 0x058F); // Armenian 98 add_range (11, 0x0590, 0x05FF); // Hebrew 99 add_range (12, 0xA500, 0xA63F); // Vai 100 add_range (13, 0x0600, 0x06FF); // Arabic 101 add_range (13, 0x0750, 0x077F); // Arabic Supplement 102 add_range (14, 0x07C0, 0x07FF); // NKo 103 add_range (15, 0x0900, 0x097F); // Devanagari 104 add_range (16, 0x0980, 0x09FF); // Bengali 105 add_range (17, 0x0A00, 0x0A7F); // Gurmukhi 106 add_range (18, 0x0A80, 0x0AFF); // Gujarati 107 add_range (19, 0x0B00, 0x0B7F); // Oriya 108 add_range (20, 0x0B80, 0x0BFF); // Tamil 109 add_range (21, 0x0C00, 0x0C7F); // Telugu 110 add_range (22, 0x0C80, 0x0CFF); // Kannada 111 add_range (23, 0x0D00, 0x0D7F); // Malayalam 112 add_range (24, 0x0E00, 0x0E7F); // Thai 113 add_range (25, 0x0E80, 0x0EFF); // Lao 114 add_range (26, 0x10A0, 0x10FF); // Georgian 115 add_range (26, 0x2D00, 0x2D2F); // Georgian Supplement 116 add_range (27, 0x1B00, 0x1B7F); // Balinese 117 add_range (28, 0x1100, 0x11FF); // Hangul Jamo 118 add_range (29, 0x1E00, 0x1EFF); // Latin Extended Additional 119 add_range (29, 0x2C60, 0x2C7F); // Latin Extended-C 120 add_range (29, 0xA720, 0xA7FF); // Latin Extended-D 121 add_range (30, 0x1F00, 0x1FFF); // Greek Extended 122 add_range (31, 0x2000, 0x206F); // General Punctuation 123 add_range (31, 0x2E00, 0x2E7F); // Supplemental Punctuation 124 add_range (32, 0x2070, 0x209F); // Superscripts And Subscripts 125 add_range (33, 0x20A0, 0x20CF); // Currency Symbols 126 add_range (34, 0x20D0, 0x20FF); // Combining Diacritical Marks For Symbols 127 add_range (35, 0x2100, 0x214F); // Letterlike Symbols 128 add_range (36, 0x2150, 0x218F); // Number Forms 129 add_range (37, 0x2190, 0x21FF); // Arrows 130 add_range (37, 0x27F0, 0x27FF); // Supplemental Arrows-A 131 add_range (37, 0x2900, 0x297F); // Supplemental Arrows-B 132 add_range (37, 0x2B00, 0x2BFF); // Miscellaneous Symbols and Arrows 133 add_range (37, 0x2200, 0x22FF); // Mathematical Operators 134 add_range (37, 0x2A00, 0x2AFF); // Supplemental Mathematical Operators 135 add_range (37, 0x27C0, 0x27EF); // Miscellaneous Mathematical Symbols-A 136 add_range (37, 0x2980, 0x29FF); // Miscellaneous Mathematical Symbols-B 137 add_range (39, 0x2300, 0x23FF); // Miscellaneous Technical 138 add_range (40, 0x2400, 0x243F); // Control Pictures 139 add_range (41, 0x2440, 0x245F); // Optical Character Recognition 140 add_range (42, 0x2460, 0x24FF); // Enclosed Alphanumerics 141 add_range (43, 0x2500, 0x257F); // Box Drawing 142 add_range (44, 0x2580, 0x259F); // Block Elements 143 add_range (45, 0x25A0, 0x25FF); // Geometric Shapes 144 add_range (46, 0x2600, 0x26FF); // Miscellaneous Symbols 145 add_range (47, 0x2700, 0x27BF); // Dingbats 146 add_range (48, 0x3000, 0x303F); // CJK Symbols And Punctuation 147 add_range (49, 0x3040, 0x309F); // Hiragana 148 add_range (50, 0x30A0, 0x30FF); // Katakana 149 add_range (50, 0x31F0, 0x31FF); // Katakana Phonetic Extensions 150 add_range (50, 0x3100, 0x312F); // Bopomofo 151 add_range (50, 0x31A0, 0x31BF); // Bopomofo Extended 152 add_range (52, 0x3130, 0x318F); // Hangul Compatibility Jamo 153 add_range (53, 0xA840, 0xA87F); // Phags-pa 154 add_range (54, 0x3200, 0x32FF); // Enclosed CJK Letters And Months 155 add_range (55, 0x3300, 0x33FF); // CJK Compatibility 156 add_range (56, 0xAC00, 0xD7AF); // Hangul Syllables 157 add_range (57, 0xD800, 0xDFFF); // Non-Plane 0 * 158 add_range (58, 0x10900, 0x1091F); // Phoenician 159 add_range (59, 0x4E00, 0x9FFF); // CJK Unified Ideographs 160 add_range (59, 0x2E80, 0x2EFF); // CJK Radicals Supplement 161 add_range (59, 0x2F00, 0x2FDF); // Kangxi Radicals 162 add_range (59, 0x2FF0, 0x2FFF); // Ideographic Description Characters 163 add_range (59, 0x3400, 0x4DBF); // CJK Unified Ideographs Extension A 164 add_range (59, 0x20000, 0x2A6DF); // CJK Unified Ideographs Extension B 165 add_range (59, 0x3190, 0x319F); // Kanbun 166 add_range (60, 0xE000, 0xF8FF); // Private Use Area (plane 0) 167 add_range (61, 0x31C0, 0x31EF); // CJK Strokes 168 add_range (61, 0xF900, 0xFAFF); // CJK Compatibility Ideographs 169 add_range (61, 0x2F800, 0x2Fa1F); // CJK Compatibility Ideographs Supplement 170 add_range (61, 0xFB00, 0xFB4F); // Alphabetic Presentation Forms 171 add_range (63, 0xFB50, 0xFDFF); // Arabic Presentation Forms-A 172 add_range (64, 0xFE20, 0xFE2F); // Combining Half Marks 173 add_range (65, 0xFE10, 0xFE1F); // Vertical Forms 174 add_range (65, 0xFE30, 0xFE4F); // CJK Compatibility Forms 175 add_range (66, 0xFE50, 0xFE6F); // Small Form Variants 176 add_range (67, 0xFE70, 0xFEFF); // Arabic Presentation Forms-B 177 add_range (68, 0xFF00, 0xFFEF); // Halfwidth And Fullwidth Forms 178 add_range (69, 0xFFF0, 0xFFFF); // Specials 179 add_range (70, 0x0F00, 0x0FFF); // Tibetan 180 add_range (71, 0x0700, 0x074F); // Syriac 181 add_range (72, 0x0780, 0x07BF); // Thaana 182 add_range (73, 0x0D80, 0x0DFF); // Sinhala 183 add_range (74, 0x1000, 0x109F); // Myanmar 184 add_range (75, 0x1200, 0x137F); // Ethiopic 185 add_range (75, 0x1380, 0x139F); // Ethiopic Supplement 186 add_range (75, 0x2D80, 0x2DDF); // Ethiopic Extended 187 add_range (76, 0x13A0, 0x13FF); // Cherokee 188 add_range (77, 0x1400, 0x167F); // Unified Canadian Aboriginal Syllabics 189 add_range (78, 0x1680, 0x169F); // Ogham 190 add_range (79, 0x16A0, 0x16FF); // Runic 191 add_range (80, 0x1780, 0x17FF); // Khmer 192 add_range (80, 0x19E0, 0x19FF); // Khmer Symbols 193 add_range (81, 0x1800, 0x18AF); // Mongolian 194 add_range (82, 0x2800, 0x28FF); // Braille Patterns 195 add_range (83, 0xA000, 0xA48F); // Yi Syllables 196 add_range (83, 0xA490, 0xA4CF); // Yi Radicals 197 add_range (83, 0x1700, 0x171F); // Tagalog 198 add_range (83, 0x1720, 0x173F); // Hanunoo 199 add_range (83, 0x1740, 0x175F); // Buhid 200 add_range (83, 0x1760, 0x177F); // Tagbanwa 201 add_range (85, 0x10300, 0x1032F); // Old Italic 202 add_range (86, 0x10330, 0x1034F); // Gothic 203 add_range (87, 0x10400, 0x1044F); // Deseret 204 add_range (88, 0x1D000, 0x1D0FF); // Byzantine Musical Symbols 205 add_range (88, 0x1D100, 0x1D1FF); // Musical Symbols 206 add_range (88, 0x1D200, 0x1D24F); // Ancient Greek Musical Notation 207 add_range (89, 0x1D400, 0x1D7FF); // Mathematical Alphanumeric Symbols 208 add_range (90, 0xFF000, 0xFFFFD); // Private Use (plane 15) 209 add_range (90, 0x100000, 0x10FFFD); // Private Use (plane 16) 210 add_range (90, 0xFE00, 0xFE0F); // Variation Selectors 211 add_range (90, 0xE0100, 0xE01EF); // Variation Selectors Supplement 212 add_range (92, 0xE0000, 0xE007F); // Tags 213 add_range (93, 0x1900, 0x194F); // Limbu 214 add_range (94, 0x1950, 0x197F); // Tai Le 215 add_range (95, 0x1980, 0x19DF); // New Tai Lue 216 add_range (96, 0x1A00, 0x1A1F); // Buginese 217 add_range (97, 0x2C00, 0x2C5F); // Glagolitic 218 add_range (98, 0x2D30, 0x2D7F); // Tifinagh 219 add_range (99, 0x4DC0, 0x4DFF); // Yijing Hexagram Symbols 220 add_range (100, 0xA800, 0xA82F); // Syloti Nagri 221 add_range (101, 0x10000, 0x1007F); // Linear B Syllabary 222 add_range (101, 0x10080, 0x100FF); // Linear B Ideograms 223 add_range (101, 0x10100, 0x1013F); // Aegean Numbers 224 add_range (102, 0x10140, 0x1018F); // Ancient Greek Numbers 225 add_range (103, 0x10380, 0x1039F); // Ugaritic 226 add_range (104, 0x103A0, 0x103DF); // Old Persian 227 add_range (105, 0x10450, 0x1047F); // Shavian 228 add_range (106, 0x10480, 0x104AF); // Osmanya 229 add_range (107, 0x10800, 0x1083F); // Cypriot Syllabary 230 add_range (108, 0x10A00, 0x10A5F); // Kharoshthi 231 add_range (109, 0x1D300, 0x1D35F); // Tai Xuan Jing Symbols 232 add_range (110, 0x12000, 0x123FF); // Cuneiform 233 add_range (110, 0x12400, 0x1247F); // Cuneiform Numbers and Punctuation 234 add_range (111, 0x1D360, 0x1D37F); // Counting Rod Numerals 235 add_range (112, 0x1B80, 0x1BBF); // Sundanese 236 add_range (113, 0x1C00, 0x1C4F); // Lepcha 237 add_range (114, 0x1C50, 0x1C7F); // Ol Chiki 238 add_range (115, 0xA880, 0xA8DF); // Saurashtra 239 add_range (116, 0xA900, 0xA92F); // Kayah Li 240 add_range (117, 0xA930, 0xA95F); // Rejang 241 add_range (118, 0xAA00, 0xAA5F); // Cham 242 add_range (119, 0x10190, 0x101CF); // Ancient Symbols 243 add_range (120, 0x101D0, 0x101FF); // Phaistos Disc 244 add_range (121, 0x102A0, 0x102DF); // Carian 245 add_range (121, 0x10280, 0x1029F); // Lycian 246 add_range (121, 0x10920, 0x1093F); // Lydian 247 add_range (122, 0x1F030, 0x1F09F); // Domino Tiles 248 add_range (122, 0x1F000, 0x1F02F); // Mahjong Tiles 249 } 250 251 private class RangeBit: GLib.Object { 252 public int32 bit = 0; 253 public UniRange range; 254 255 public RangeBit (int bit, unichar start, unichar stop) { 256 this.range = new UniRange (start, stop); 257 } 258 } 259 } 260 261 } 262 263