| 1 | /*! |
| 2 | |
| 3 | This library implements |
| 4 | [Unicode Vertical_Orientation Property](https://www.unicode.org/reports/tr50/tr50-19.html) |
| 5 | (annex #50). |
| 6 | |
| 7 | ```rust |
| 8 | use unicode_vo::*; |
| 9 | |
| 10 | assert_eq!(char_orientation('A' ), Orientation::Rotated); |
| 11 | assert_eq!(char_orientation('本' ), Orientation::Upright); |
| 12 | ``` |
| 13 | |
| 14 | */ |
| 15 | |
| 16 | #![doc (html_root_url = "https://docs.rs/unicode-vo/0.1.0" )] |
| 17 | |
| 18 | #![forbid (unsafe_code)] |
| 19 | |
| 20 | /// Character orientation. |
| 21 | #[derive (Clone, Copy, PartialEq, Debug)] |
| 22 | pub enum Orientation { |
| 23 | /// Characters which are displayed upright, with the same orientation that appears in |
| 24 | /// the code charts. |
| 25 | /// |
| 26 | /// Original name: **U** |
| 27 | Upright, |
| 28 | |
| 29 | /// Characters which are displayed sideways, rotated 90 degrees clockwise compared to |
| 30 | /// the code charts. |
| 31 | /// |
| 32 | /// Original name: **R** |
| 33 | Rotated, |
| 34 | |
| 35 | /// Characters which are not just upright or sideways, but generally require |
| 36 | /// a different glyph than in the code charts when used in vertical texts. |
| 37 | /// In addition, as a fallback, the character can be displayed with |
| 38 | /// the code chart glyph upright. |
| 39 | /// |
| 40 | /// Original name: **Tu** |
| 41 | TransformedOrUpright, |
| 42 | |
| 43 | /// Same as Tu except that, as a fallback, the character can be displayed with |
| 44 | /// the code chart glyph rotated 90 degrees clockwise. |
| 45 | /// |
| 46 | /// Original name: **Tr** |
| 47 | TransformedOrRotated, |
| 48 | } |
| 49 | |
| 50 | /// Returns a vertical orientation of a character. |
| 51 | /// |
| 52 | /// Based on <https://www.unicode.org/Public/vertical/revision-17/VerticalOrientation-17.txt>. |
| 53 | pub fn char_orientation(c: char) -> Orientation { |
| 54 | match c as u32 { |
| 55 | 0x00A7 => Orientation::Upright, |
| 56 | 0x00A9 => Orientation::Upright, |
| 57 | 0x00AE => Orientation::Upright, |
| 58 | 0x00B1 => Orientation::Upright, |
| 59 | 0x00BC...0x00BE => Orientation::Upright, |
| 60 | 0x00D7 => Orientation::Upright, |
| 61 | 0x00F7 => Orientation::Upright, |
| 62 | 0x02EA...0x02EB => Orientation::Upright, |
| 63 | 0x1100...0x11FF => Orientation::Upright, |
| 64 | 0x1401...0x167F => Orientation::Upright, |
| 65 | 0x18B0...0x18FF => Orientation::Upright, |
| 66 | 0x2016 => Orientation::Upright, |
| 67 | 0x2020...0x2021 => Orientation::Upright, |
| 68 | 0x2030...0x2031 => Orientation::Upright, |
| 69 | 0x203B...0x203C => Orientation::Upright, |
| 70 | 0x2042 => Orientation::Upright, |
| 71 | 0x2047...0x2049 => Orientation::Upright, |
| 72 | 0x2051 => Orientation::Upright, |
| 73 | 0x2065 => Orientation::Upright, |
| 74 | 0x20DD...0x20E0 => Orientation::Upright, |
| 75 | 0x20E2...0x20E4 => Orientation::Upright, |
| 76 | 0x2100...0x2101 => Orientation::Upright, |
| 77 | 0x2103...0x2109 => Orientation::Upright, |
| 78 | 0x210F => Orientation::Upright, |
| 79 | 0x2113...0x2114 => Orientation::Upright, |
| 80 | 0x2116...0x2117 => Orientation::Upright, |
| 81 | 0x211E...0x2123 => Orientation::Upright, |
| 82 | 0x2125 => Orientation::Upright, |
| 83 | 0x2127 => Orientation::Upright, |
| 84 | 0x2129 => Orientation::Upright, |
| 85 | 0x212E => Orientation::Upright, |
| 86 | 0x2135...0x213F => Orientation::Upright, |
| 87 | 0x2145...0x214A => Orientation::Upright, |
| 88 | 0x214C...0x214D => Orientation::Upright, |
| 89 | 0x214F => Orientation::Upright, |
| 90 | 0x2150...0x2189 => Orientation::Upright, |
| 91 | 0x218C...0x218F => Orientation::Upright, |
| 92 | 0x221E => Orientation::Upright, |
| 93 | 0x2234...0x2235 => Orientation::Upright, |
| 94 | 0x2300...0x2307 => Orientation::Upright, |
| 95 | 0x230C...0x231F => Orientation::Upright, |
| 96 | 0x2324...0x2328 => Orientation::Upright, |
| 97 | 0x2329...0x232A => Orientation::TransformedOrRotated, |
| 98 | 0x232B => Orientation::Upright, |
| 99 | 0x237D...0x239A => Orientation::Upright, |
| 100 | 0x23BE...0x23CD => Orientation::Upright, |
| 101 | 0x23CF => Orientation::Upright, |
| 102 | 0x23D1...0x23DB => Orientation::Upright, |
| 103 | 0x23E2...0x23FF => Orientation::Upright, |
| 104 | 0x2400...0x2422 => Orientation::Upright, |
| 105 | 0x2424...0x243F => Orientation::Upright, |
| 106 | 0x2440...0x245F => Orientation::Upright, |
| 107 | 0x2460...0x24FF => Orientation::Upright, |
| 108 | 0x25A0...0x25FF => Orientation::Upright, |
| 109 | 0x2600...0x2619 => Orientation::Upright, |
| 110 | 0x2620...0x26FF => Orientation::Upright, |
| 111 | 0x2700...0x2767 => Orientation::Upright, |
| 112 | 0x2776...0x2793 => Orientation::Upright, |
| 113 | 0x2B12...0x2B2F => Orientation::Upright, |
| 114 | 0x2B50...0x2B59 => Orientation::Upright, |
| 115 | 0x2BB8...0x2BEB => Orientation::Upright, |
| 116 | 0x2BF0...0x2BFF => Orientation::Upright, |
| 117 | 0x2E80...0x2EFF => Orientation::Upright, |
| 118 | 0x2F00...0x2FDF => Orientation::Upright, |
| 119 | 0x2FE0...0x2FEF => Orientation::Upright, |
| 120 | 0x2FF0...0x2FFF => Orientation::Upright, |
| 121 | 0x3000 => Orientation::Upright, |
| 122 | 0x3001...0x3002 => Orientation::TransformedOrUpright, |
| 123 | 0x3003...0x3007 => Orientation::Upright, |
| 124 | 0x3008...0x3011 => Orientation::TransformedOrRotated, |
| 125 | 0x3012...0x3013 => Orientation::Upright, |
| 126 | 0x3014...0x301F => Orientation::TransformedOrRotated, |
| 127 | 0x3020...0x302F => Orientation::Upright, |
| 128 | 0x3030 => Orientation::TransformedOrRotated, |
| 129 | 0x3031...0x3040 => Orientation::Upright, |
| 130 | 0x3041 => Orientation::TransformedOrUpright, |
| 131 | 0x3042 => Orientation::Upright, |
| 132 | 0x3043 => Orientation::TransformedOrUpright, |
| 133 | 0x3044 => Orientation::Upright, |
| 134 | 0x3045 => Orientation::TransformedOrUpright, |
| 135 | 0x3046 => Orientation::Upright, |
| 136 | 0x3047 => Orientation::TransformedOrUpright, |
| 137 | 0x3048 => Orientation::Upright, |
| 138 | 0x3049 => Orientation::TransformedOrUpright, |
| 139 | 0x304A...0x3062 => Orientation::Upright, |
| 140 | 0x3063 => Orientation::TransformedOrUpright, |
| 141 | 0x3064...0x3082 => Orientation::Upright, |
| 142 | 0x3083 => Orientation::TransformedOrUpright, |
| 143 | 0x3084 => Orientation::Upright, |
| 144 | 0x3085 => Orientation::TransformedOrUpright, |
| 145 | 0x3086 => Orientation::Upright, |
| 146 | 0x3087 => Orientation::TransformedOrUpright, |
| 147 | 0x3088...0x308D => Orientation::Upright, |
| 148 | 0x308E => Orientation::TransformedOrUpright, |
| 149 | 0x308F...0x3094 => Orientation::Upright, |
| 150 | 0x3095...0x3096 => Orientation::TransformedOrUpright, |
| 151 | 0x3097...0x309A => Orientation::Upright, |
| 152 | 0x309B...0x309C => Orientation::TransformedOrUpright, |
| 153 | 0x309D...0x309F => Orientation::Upright, |
| 154 | 0x30A0 => Orientation::TransformedOrRotated, |
| 155 | 0x30A1 => Orientation::TransformedOrUpright, |
| 156 | 0x30A2 => Orientation::Upright, |
| 157 | 0x30A3 => Orientation::TransformedOrUpright, |
| 158 | 0x30A4 => Orientation::Upright, |
| 159 | 0x30A5 => Orientation::TransformedOrUpright, |
| 160 | 0x30A6 => Orientation::Upright, |
| 161 | 0x30A7 => Orientation::TransformedOrUpright, |
| 162 | 0x30A8 => Orientation::Upright, |
| 163 | 0x30A9 => Orientation::TransformedOrUpright, |
| 164 | 0x30AA...0x30C2 => Orientation::Upright, |
| 165 | 0x30C3 => Orientation::TransformedOrUpright, |
| 166 | 0x30C4...0x30E2 => Orientation::Upright, |
| 167 | 0x30E3 => Orientation::TransformedOrUpright, |
| 168 | 0x30E4 => Orientation::Upright, |
| 169 | 0x30E5 => Orientation::TransformedOrUpright, |
| 170 | 0x30E6 => Orientation::Upright, |
| 171 | 0x30E7 => Orientation::TransformedOrUpright, |
| 172 | 0x30E8...0x30ED => Orientation::Upright, |
| 173 | 0x30EE => Orientation::TransformedOrUpright, |
| 174 | 0x30EF...0x30F4 => Orientation::Upright, |
| 175 | 0x30F5...0x30F6 => Orientation::TransformedOrUpright, |
| 176 | 0x30F7...0x30FB => Orientation::Upright, |
| 177 | 0x30FC => Orientation::TransformedOrRotated, |
| 178 | 0x30FD...0x30FF => Orientation::Upright, |
| 179 | 0x3100...0x3126 => Orientation::Upright, |
| 180 | 0x3127 => Orientation::TransformedOrUpright, |
| 181 | 0x3128...0x312F => Orientation::Upright, |
| 182 | 0x3130...0x318F => Orientation::Upright, |
| 183 | 0x3190...0x319F => Orientation::Upright, |
| 184 | 0x31A0...0x31BF => Orientation::Upright, |
| 185 | 0x31C0...0x31EF => Orientation::Upright, |
| 186 | 0x31F0...0x31FF => Orientation::TransformedOrUpright, |
| 187 | 0x3200...0x321E => Orientation::Upright, |
| 188 | 0x321F...0x32FF => Orientation::Upright, |
| 189 | 0x3300...0x3357 => Orientation::TransformedOrUpright, |
| 190 | 0x3358...0x337A => Orientation::Upright, |
| 191 | 0x337B...0x337F => Orientation::TransformedOrUpright, |
| 192 | 0x3380...0x33FF => Orientation::Upright, |
| 193 | 0x3400...0x4DBF => Orientation::Upright, |
| 194 | 0x4DC0...0x4DFF => Orientation::Upright, |
| 195 | 0x4E00...0x9FFF => Orientation::Upright, |
| 196 | 0xA000...0xA48F => Orientation::Upright, |
| 197 | 0xA490...0xA4CF => Orientation::Upright, |
| 198 | 0xA960...0xA97F => Orientation::Upright, |
| 199 | 0xAC00...0xD7AF => Orientation::Upright, |
| 200 | 0xD7B0...0xD7FF => Orientation::Upright, |
| 201 | 0xE000...0xF8FF => Orientation::Upright, |
| 202 | 0xF900...0xFAFF => Orientation::Upright, |
| 203 | 0xFE10...0xFE19 => Orientation::Upright, |
| 204 | 0xFE1A...0xFE1F => Orientation::Upright, |
| 205 | 0xFE30...0xFE48 => Orientation::Upright, |
| 206 | 0xFE50...0xFE52 => Orientation::TransformedOrUpright, |
| 207 | 0xFE53...0xFE57 => Orientation::Upright, |
| 208 | 0xFE59...0xFE5E => Orientation::TransformedOrRotated, |
| 209 | 0xFE5F...0xFE62 => Orientation::Upright, |
| 210 | 0xFE67...0xFE6B => Orientation::Upright, |
| 211 | 0xFE6C...0xFE6F => Orientation::Upright, |
| 212 | 0xFF01 => Orientation::TransformedOrUpright, |
| 213 | 0xFF02...0xFF07 => Orientation::Upright, |
| 214 | 0xFF08...0xFF09 => Orientation::TransformedOrRotated, |
| 215 | 0xFF0A...0xFF0B => Orientation::Upright, |
| 216 | 0xFF0C => Orientation::TransformedOrUpright, |
| 217 | 0xFF0E => Orientation::TransformedOrUpright, |
| 218 | 0xFF0F...0xFF19 => Orientation::Upright, |
| 219 | 0xFF1A...0xFF1B => Orientation::TransformedOrRotated, |
| 220 | 0xFF1F => Orientation::TransformedOrUpright, |
| 221 | 0xFF20 => Orientation::Upright, |
| 222 | 0xFF21...0xFF3A => Orientation::Upright, |
| 223 | 0xFF3B => Orientation::TransformedOrRotated, |
| 224 | 0xFF3C => Orientation::Upright, |
| 225 | 0xFF3D => Orientation::TransformedOrRotated, |
| 226 | 0xFF3E => Orientation::Upright, |
| 227 | 0xFF3F => Orientation::TransformedOrRotated, |
| 228 | 0xFF40 => Orientation::Upright, |
| 229 | 0xFF41...0xFF5A => Orientation::Upright, |
| 230 | 0xFF5B...0xFF60 => Orientation::TransformedOrRotated, |
| 231 | 0xFFE0...0xFFE2 => Orientation::Upright, |
| 232 | 0xFFE3 => Orientation::TransformedOrRotated, |
| 233 | 0xFFE4...0xFFE7 => Orientation::Upright, |
| 234 | 0xFFF0...0xFFF8 => Orientation::Upright, |
| 235 | 0xFFFC...0xFFFD => Orientation::Upright, |
| 236 | 0x10980...0x1099F => Orientation::Upright, |
| 237 | 0x11580...0x115FF => Orientation::Upright, |
| 238 | 0x13000...0x1342F => Orientation::Upright, |
| 239 | 0x14400...0x1467F => Orientation::Upright, |
| 240 | 0x16FE0...0x16FFF => Orientation::Upright, |
| 241 | 0x17000...0x187FF => Orientation::Upright, |
| 242 | 0x18800...0x18AFF => Orientation::Upright, |
| 243 | 0x1B000...0x1B0FF => Orientation::Upright, |
| 244 | 0x1D000...0x1D0FF => Orientation::Upright, |
| 245 | 0x1D100...0x1D1FF => Orientation::Upright, |
| 246 | 0x1D300...0x1D35F => Orientation::Upright, |
| 247 | 0x1D360...0x1D37F => Orientation::Upright, |
| 248 | 0x1D800...0x1DAAF => Orientation::Upright, |
| 249 | 0x1F000...0x1F02F => Orientation::Upright, |
| 250 | 0x1F030...0x1F09F => Orientation::Upright, |
| 251 | 0x1F0A0...0x1F0FF => Orientation::Upright, |
| 252 | 0x1F100...0x1F1FF => Orientation::Upright, |
| 253 | 0x1F200...0x1F201 => Orientation::TransformedOrUpright, |
| 254 | 0x1F202...0x1F2FF => Orientation::Upright, |
| 255 | 0x1F300...0x1F5FF => Orientation::Upright, |
| 256 | 0x1F600...0x1F64F => Orientation::Upright, |
| 257 | 0x1F650...0x1F67F => Orientation::Upright, |
| 258 | 0x1F680...0x1F6FF => Orientation::Upright, |
| 259 | 0x1F700...0x1F77F => Orientation::Upright, |
| 260 | 0x1F780...0x1F7FF => Orientation::Upright, |
| 261 | 0x1F900...0x1F9FF => Orientation::Upright, |
| 262 | 0x20000...0x2A6DF => Orientation::Upright, |
| 263 | 0x2A6E0...0x2A6FF => Orientation::Upright, |
| 264 | 0x2A700...0x2B73F => Orientation::Upright, |
| 265 | 0x2B740...0x2B81F => Orientation::Upright, |
| 266 | 0x2B820...0x2CEAF => Orientation::Upright, |
| 267 | 0x2CEB0...0x2F7FF => Orientation::Upright, |
| 268 | 0x2F800...0x2FA1F => Orientation::Upright, |
| 269 | 0x2FA20...0x2FFFD => Orientation::Upright, |
| 270 | 0x30000...0x3FFFD => Orientation::Upright, |
| 271 | 0xF0000...0xFFFFD => Orientation::Upright, |
| 272 | 0x100000...0x10FFFD => Orientation::Upright, |
| 273 | _ => Orientation::Rotated, |
| 274 | } |
| 275 | } |
| 276 | |