1 | /* FriBidi |
2 | * fribidi-char-sets-cp1255.c - CP1255 character set conversion routines |
3 | * |
4 | * Authors: |
5 | * Behdad Esfahbod, 2001, 2002, 2004 |
6 | * Dov Grobgeld, 1999, 2000 |
7 | * |
8 | * Copyright (C) 2004 Sharif FarsiWeb, Inc |
9 | * Copyright (C) 2001,2002 Behdad Esfahbod |
10 | * Copyright (C) 1999,2000 Dov Grobgeld |
11 | * |
12 | * This library is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU Lesser General Public |
14 | * License as published by the Free Software Foundation; either |
15 | * version 2.1 of the License, or (at your option) any later version. |
16 | * |
17 | * This library is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | * Lesser General Public License for more details. |
21 | * |
22 | * You should have received a copy of the GNU Lesser General Public License |
23 | * along with this library, in a file named COPYING; if not, write to the |
24 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 | * Boston, MA 02110-1301, USA |
26 | * |
27 | * For licensing issues, contact <fribidi.license@gmail.com>. |
28 | */ |
29 | |
30 | #include <common.h> |
31 | |
32 | #include <fribidi-char-sets-cp1255.h> |
33 | |
34 | #define ISO_ALEF 0xE0 |
35 | #define ISO_TAV 0xFA |
36 | #define CP1255_SHEVA 0xC0 |
37 | #define CP1255_SOF_PASUQ 0xD3 |
38 | #define CP1255_DOUBLE_VAV 0xD4 |
39 | #define CP1255_GERSHAYIM 0xD8 |
40 | #define CP1255_LRM 0xFD |
41 | #define CP1255_RLM 0xFE |
42 | |
43 | #define UNI_ALEF 0x05D0 |
44 | #define UNI_TAV 0x05EA |
45 | #define UNI_SHEVA 0x05B0 |
46 | #define UNI_SOF_PASUQ 0x05C3 |
47 | #define UNI_DOUBLE_VAV 0x05F0 |
48 | #define UNI_GERSHAYIM 0x05F4 |
49 | #define UNI_LRM 0x200E |
50 | #define UNI_RLM 0x200F |
51 | |
52 | static FriBidiChar fribidi_cp1255_to_unicode_tab[] = { /* 0x80-0xBF */ |
53 | 0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, |
54 | 0x02C6, 0x2030, 0x008a, 0x2039, 0x008c, 0x008d, 0x008e, 0x008f, |
55 | 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, |
56 | 0x02DC, 0x2122, 0x009a, 0x203A, 0x009c, 0x009d, 0x009e, 0x009f, |
57 | 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7, |
58 | 0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, |
59 | 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, |
60 | 0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF |
61 | }; |
62 | |
63 | FriBidiChar |
64 | fribidi_cp1255_to_unicode_c ( |
65 | /* input */ |
66 | char sch |
67 | ) |
68 | { |
69 | register unsigned char ch = (unsigned char) sch; |
70 | if (ch >= ISO_ALEF && ch <= ISO_TAV) |
71 | return ch - ISO_ALEF + UNI_ALEF; |
72 | else if (ch >= CP1255_SHEVA && ch <= CP1255_SOF_PASUQ) |
73 | return ch - CP1255_SHEVA + UNI_SHEVA; |
74 | else if (ch >= CP1255_DOUBLE_VAV && ch <= CP1255_GERSHAYIM) |
75 | return ch - CP1255_DOUBLE_VAV + UNI_DOUBLE_VAV; |
76 | /* cp1256 specific chars */ |
77 | else if (ch >= 0x80 && ch <= 0xbf) |
78 | return fribidi_cp1255_to_unicode_tab[ch - 0x80]; |
79 | else if (ch == CP1255_LRM || ch == CP1255_RLM) |
80 | return ch - CP1255_LRM + UNI_LRM; |
81 | /* treat LRM/LRM charrectes correctly */ |
82 | else |
83 | return ch; |
84 | } |
85 | |
86 | char |
87 | fribidi_unicode_to_cp1255_c ( |
88 | /* input */ |
89 | FriBidiChar uch |
90 | ) |
91 | { |
92 | if (uch >= UNI_ALEF && uch <= UNI_TAV) |
93 | return (char) (uch - UNI_ALEF + ISO_ALEF); |
94 | if (uch >= UNI_SHEVA && uch <= UNI_SOF_PASUQ) |
95 | return (char) (uch - UNI_SHEVA + CP1255_SHEVA); |
96 | if (uch >= UNI_DOUBLE_VAV && uch <= UNI_GERSHAYIM) |
97 | return (char) (uch - UNI_DOUBLE_VAV + CP1255_DOUBLE_VAV); |
98 | /* TODO: handle pre-composed and presentation chars */ |
99 | if (uch == UNI_LRM || uch==UNI_RLM) |
100 | return (char) (uch - UNI_LRM + CP1255_LRM); |
101 | /* Treat LRM/RLM charrecters correctly */ |
102 | else if (uch < 256) |
103 | return (char) uch; |
104 | else |
105 | return '?'; |
106 | } |
107 | |
108 | /* Editor directions: |
109 | * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent |
110 | */ |
111 | |