| File: | fontenc.c |
| Location: | line 937, column 11 |
| Description: | Result of 'calloc' is converted to a pointer of type 'unsigned int *', which is incompatible with sizeof operand type 'int *' |
| 1 | /* |
| 2 | Copyright (c) 1998-2001 by Juliusz Chroboczek |
| 3 | |
| 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | of this software and associated documentation files (the "Software"), to deal |
| 6 | in the Software without restriction, including without limitation the rights |
| 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | copies of the Software, and to permit persons to whom the Software is |
| 9 | furnished to do so, subject to the following conditions: |
| 10 | |
| 11 | The above copyright notice and this permission notice shall be included in |
| 12 | all copies or substantial portions of the Software. |
| 13 | |
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | /* Backend-independent encoding code */ |
| 24 | |
| 25 | #include <string.h> |
| 26 | #include <strings.h> |
| 27 | #include <stdlib.h> |
| 28 | |
| 29 | #define FALSE0 0 |
| 30 | #define TRUE1 1 |
| 31 | #define MAXFONTNAMELEN1024 1024 |
| 32 | #define MAXFONTFILENAMELEN1024 1024 |
| 33 | |
| 34 | #include <X11/fonts/fontenc.h> |
| 35 | #include "fontencI.h" |
| 36 | |
| 37 | /* Functions local to this file */ |
| 38 | |
| 39 | static FontEncPtr FontEncLoad(const char *, const char *); |
| 40 | |
| 41 | /* Early versions of this code only knew about hardwired encodings, |
| 42 | hence the following data. Now that the code knows how to load an |
| 43 | encoding from a file, most of these tables could go away. */ |
| 44 | |
| 45 | /* At any rate, no new hardcoded encodings will be added. */ |
| 46 | |
| 47 | static FontMapRec iso10646[] = { |
| 48 | {FONT_ENCODING_UNICODE1, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 49 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 50 | }; |
| 51 | |
| 52 | /* Notice that the Apple encodings do not have all the characters in |
| 53 | the corresponding ISO 8859, and therefore the table has some holes. |
| 54 | There's not much more we can do with fonts without a Unicode cmap |
| 55 | unless we are willing to combine cmaps (which we are not). */ |
| 56 | |
| 57 | static const unsigned short |
| 58 | iso8859_1_apple_roman[] = { |
| 59 | 0xCA, 0xC1, 0xA2, 0xA3, 0xDB, 0xB4, 0x00, 0xA4, |
| 60 | 0xAC, 0xA9, 0xBB, 0xC7, 0xC2, 0x00, 0xA8, 0xF8, |
| 61 | 0xA1, 0xB1, 0x00, 0x00, 0xAB, 0xB5, 0xA6, 0xE1, |
| 62 | 0xFC, 0x00, 0xBC, 0xC8, 0x00, 0x00, 0x00, 0xC0, |
| 63 | 0xCB, 0xE7, 0xE5, 0xCC, 0x80, 0x81, 0xAE, 0x82, |
| 64 | 0xE9, 0x83, 0xE6, 0xE8, 0xED, 0xEA, 0xEB, 0xEC, |
| 65 | 0x00, 0x84, 0xF1, 0xEE, 0xEF, 0xCD, 0x85, 0x00, |
| 66 | 0xAF, 0xF4, 0xF2, 0xF3, 0x86, 0x00, 0x00, 0xA7, |
| 67 | 0x88, 0x87, 0x89, 0x8B, 0x8A, 0x8C, 0xBE, 0x8D, |
| 68 | 0x8F, 0x8E, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, |
| 69 | 0x00, 0x96, 0x98, 0x97, 0x99, 0x9B, 0x9A, 0xD6, |
| 70 | 0xBF, 0x9D, 0x9C, 0x9E, 0x9F, 0x00, 0x00, 0xD8 |
| 71 | }; |
| 72 | |
| 73 | /* Cannot use simple_recode because need to eliminate 0x80<=code<0xA0 */ |
| 74 | static unsigned |
| 75 | iso8859_1_to_apple_roman(unsigned isocode, void *client_data) |
| 76 | { |
| 77 | if (isocode <= 0x80) |
| 78 | return isocode; |
| 79 | else if (isocode >= 0xA0) |
| 80 | return iso8859_1_apple_roman[isocode - 0xA0]; |
| 81 | else |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static FontMapRec iso8859_1[] = { |
| 86 | {FONT_ENCODING_TRUETYPE2, 2, 2, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, /* ISO 8859-1 */ |
| 87 | {FONT_ENCODING_UNICODE1, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, /* ISO 8859-1 coincides with Unicode */ |
| 88 | {FONT_ENCODING_TRUETYPE2, 1, 0, iso8859_1_to_apple_roman, NULL((void *)0), NULL((void *)0), NULL((void *)0), |
| 89 | NULL((void *)0)}, |
| 90 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 91 | }; |
| 92 | |
| 93 | static const unsigned short iso8859_2_tophalf[] = { |
| 94 | 0x00A0, 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, |
| 95 | 0x00A8, 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, |
| 96 | 0x00B0, 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, |
| 97 | 0x00B8, 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, |
| 98 | 0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, |
| 99 | 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, |
| 100 | 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, |
| 101 | 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, |
| 102 | 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, |
| 103 | 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, |
| 104 | 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, |
| 105 | 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9 |
| 106 | }; |
| 107 | |
| 108 | static FontEncSimpleMapRec iso8859_2_to_unicode_map = |
| 109 | { 0x60, 0, 0xA0, iso8859_2_tophalf }; |
| 110 | |
| 111 | static const unsigned short iso8859_2_apple_centeuro[] = { |
| 112 | 0xCA, 0x84, 0x00, 0xFC, 0x00, 0xBB, 0xE5, 0xA4, |
| 113 | 0xAC, 0xE1, 0x00, 0xE8, 0x8F, 0x00, 0xEB, 0xFB, |
| 114 | 0xA1, 0x88, 0x00, 0xB8, 0x00, 0xBC, 0xE6, 0xFF, |
| 115 | 0x00, 0xE4, 0x00, 0xE9, 0x90, 0x00, 0xEC, 0xFD, |
| 116 | 0xD9, 0xE7, 0x00, 0x00, 0x80, 0xBD, 0x8C, 0x00, |
| 117 | 0x89, 0x83, 0xA2, 0x00, 0x9D, 0xEA, 0x00, 0x91, |
| 118 | 0x00, 0xC1, 0xC5, 0xEE, 0xEF, 0xCC, 0x85, 0x00, |
| 119 | 0xDB, 0xF1, 0xF2, 0xF4, 0x86, 0xF8, 0x00, 0xA7, |
| 120 | 0xDA, 0x87, 0x00, 0x00, 0x8A, 0xBE, 0x8D, 0x00, |
| 121 | 0x8B, 0x8E, 0xAB, 0x00, 0x9E, 0x92, 0x00, 0x93, |
| 122 | 0x00, 0xC4, 0xCB, 0x97, 0x99, 0xCE, 0x9A, 0xD6, |
| 123 | 0xDE, 0xF3, 0x9C, 0xF5, 0x9F, 0xF9, 0x00, 0x00 |
| 124 | }; |
| 125 | |
| 126 | static unsigned |
| 127 | iso8859_2_to_apple_centeuro(unsigned isocode, void *client_data) |
| 128 | { |
| 129 | if (isocode <= 0x80) |
| 130 | return isocode; |
| 131 | else if (isocode >= 0xA0) |
| 132 | return iso8859_2_apple_centeuro[isocode - 0xA0]; |
| 133 | else |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static FontMapRec iso8859_2[] = { |
| 138 | {FONT_ENCODING_UNICODE1, 0, 0, |
| 139 | FontEncSimpleRecode, NULL((void *)0), &iso8859_2_to_unicode_map, NULL((void *)0), NULL((void *)0)}, |
| 140 | {FONT_ENCODING_TRUETYPE2, 1, 29, iso8859_2_to_apple_centeuro, NULL((void *)0), NULL((void *)0), |
| 141 | NULL((void *)0), NULL((void *)0)}, |
| 142 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 143 | }; |
| 144 | |
| 145 | static const unsigned short iso8859_3_tophalf[] = { |
| 146 | 0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0x0000, 0x0124, 0x00A7, |
| 147 | 0x00A8, 0x0130, 0x015E, 0x011E, 0x0134, 0x00AD, 0x0000, 0x017B, |
| 148 | 0x00B0, 0x0127, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x0125, 0x00B7, |
| 149 | 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135, 0x00BD, 0x0000, 0x017C, |
| 150 | 0x00C0, 0x00C1, 0x00C2, 0x0000, 0x00C4, 0x010A, 0x0108, 0x00C7, |
| 151 | 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, |
| 152 | 0x0000, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7, |
| 153 | 0x011C, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF, |
| 154 | 0x00E0, 0x00E1, 0x00E2, 0x0000, 0x00E4, 0x010B, 0x0109, 0x00E7, |
| 155 | 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, |
| 156 | 0x0000, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7, |
| 157 | 0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9 |
| 158 | }; |
| 159 | |
| 160 | static FontEncSimpleMapRec iso8859_3_to_unicode_map = |
| 161 | { 0x60, 0, 0xA0, iso8859_3_tophalf }; |
| 162 | |
| 163 | static FontMapRec iso8859_3[] = { |
| 164 | {FONT_ENCODING_UNICODE1, 0, 0, |
| 165 | FontEncSimpleRecode, NULL((void *)0), &iso8859_3_to_unicode_map, NULL((void *)0), NULL((void *)0)}, |
| 166 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 167 | }; |
| 168 | |
| 169 | static const unsigned short iso8859_4_tophalf[] = { |
| 170 | 0x00A0, 0x0104, 0x0138, 0x0156, 0x00A4, 0x0128, 0x013B, 0x00A7, |
| 171 | 0x00A8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00AD, 0x017D, 0x00AF, |
| 172 | 0x00B0, 0x0105, 0x02DB, 0x0157, 0x00B4, 0x0129, 0x013C, 0x02C7, |
| 173 | 0x00B8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014A, 0x017E, 0x014B, |
| 174 | 0x0100, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x012E, |
| 175 | 0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116, 0x00CD, 0x00CE, 0x012A, |
| 176 | 0x0110, 0x0145, 0x014C, 0x0136, 0x00D4, 0x00D5, 0x00D6, 0x00D7, |
| 177 | 0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x0168, 0x016A, 0x00DF, |
| 178 | 0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F, |
| 179 | 0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x012B, |
| 180 | 0x0111, 0x0146, 0x014D, 0x0137, 0x00F4, 0x00F5, 0x00F6, 0x00F7, |
| 181 | 0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x0169, 0x016B, 0x02D9, |
| 182 | }; |
| 183 | |
| 184 | static FontEncSimpleMapRec iso8859_4_to_unicode_map = |
| 185 | { 0x60, 0, 0xA0, iso8859_4_tophalf }; |
| 186 | |
| 187 | static FontMapRec iso8859_4[] = { |
| 188 | {FONT_ENCODING_UNICODE1, 0, 0, FontEncSimpleRecode, NULL((void *)0), |
| 189 | &iso8859_4_to_unicode_map, NULL((void *)0), NULL((void *)0)}, |
| 190 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 191 | }; |
| 192 | |
| 193 | static const unsigned short iso8859_5_tophalf[] = { |
| 194 | 0x00A0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, |
| 195 | 0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x00AD, 0x040E, 0x040F, |
| 196 | 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, |
| 197 | 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, |
| 198 | 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, |
| 199 | 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, |
| 200 | 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, |
| 201 | 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, |
| 202 | 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, |
| 203 | 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, |
| 204 | 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, |
| 205 | 0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F |
| 206 | }; |
| 207 | |
| 208 | static FontEncSimpleMapRec iso8859_5_to_unicode_map = |
| 209 | { 0x60, 0, 0xA0, iso8859_5_tophalf }; |
| 210 | |
| 211 | static const unsigned short iso8859_5_apple_cyrillic[] = { |
| 212 | 0xCA, 0xDD, 0xAB, 0xAE, 0xB8, 0xC1, 0xA7, 0xBA, |
| 213 | 0xB7, 0xBC, 0xBE, 0xCB, 0xCD, 0x00, 0xD8, 0xDA, |
| 214 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 215 | 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, |
| 216 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 217 | 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, |
| 218 | 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, |
| 219 | 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, |
| 220 | 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, |
| 221 | 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF, |
| 222 | 0xDC, 0xDE, 0xAC, 0xAF, 0xB9, 0xCF, 0xB4, 0xBB, |
| 223 | 0xC0, 0xBD, 0xBF, 0xCC, 0xCE, 0xA4, 0xD9, 0xDB |
| 224 | }; |
| 225 | |
| 226 | static unsigned |
| 227 | iso8859_5_to_apple_cyrillic(unsigned isocode, void *client_data) |
| 228 | { |
| 229 | if (isocode <= 0x80) |
| 230 | return isocode; |
| 231 | else if (isocode >= 0xA0) |
| 232 | return iso8859_5_apple_cyrillic[isocode - 0x80]; |
| 233 | else |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static FontMapRec iso8859_5[] = { |
| 238 | {FONT_ENCODING_UNICODE1, 0, 0, FontEncSimpleRecode, NULL((void *)0), |
| 239 | &iso8859_5_to_unicode_map, NULL((void *)0), NULL((void *)0)}, |
| 240 | {FONT_ENCODING_TRUETYPE2, 1, 7, iso8859_5_to_apple_cyrillic, NULL((void *)0), NULL((void *)0), |
| 241 | NULL((void *)0), NULL((void *)0)}, |
| 242 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 243 | }; |
| 244 | |
| 245 | /* ISO 8859-6 seems useless for serving fonts (not enough presentation |
| 246 | * forms). What do Arabic-speakers use? */ |
| 247 | |
| 248 | static unsigned |
| 249 | iso8859_6_to_unicode(unsigned isocode, void *client_data) |
| 250 | { |
| 251 | if (isocode <= 0xA0 || isocode == 0xA4 || isocode == 0xAD) |
| 252 | return isocode; |
| 253 | else if (isocode == 0xAC || isocode == 0xBB || |
| 254 | isocode == 0xBF || |
| 255 | (isocode >= 0xC1 && isocode <= 0xDA) || |
| 256 | (isocode >= 0xE0 && isocode <= 0xEF) || |
| 257 | (isocode >= 0xF0 && isocode <= 0xF2)) |
| 258 | return isocode - 0xA0 + 0x0600; |
| 259 | else |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static FontMapRec iso8859_6[] = { |
| 264 | {FONT_ENCODING_UNICODE1, 0, 0, iso8859_6_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 265 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 266 | }; |
| 267 | |
| 268 | static unsigned |
| 269 | iso8859_7_to_unicode(unsigned isocode, void *client_data) |
| 270 | { |
| 271 | if (isocode <= 0xA0 || |
| 272 | (isocode >= 0xA3 && isocode <= 0xAD) || |
| 273 | (isocode >= 0xB0 && isocode <= 0xB3) || |
| 274 | isocode == 0xB7 || isocode == 0xBB || isocode == 0xBD) |
| 275 | return isocode; |
| 276 | else if (isocode == 0xA1) |
| 277 | return 0x02BD; |
| 278 | else if (isocode == 0xA2) |
| 279 | return 0x02BC; |
| 280 | else if (isocode == 0xAF) |
| 281 | return 0x2015; |
| 282 | else if (isocode == 0xD2) /* unassigned */ |
| 283 | return 0; |
| 284 | else if (isocode >= 0xB4) |
| 285 | return isocode - 0xA0 + 0x0370; |
| 286 | else |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static FontMapRec iso8859_7[] = { |
| 291 | {FONT_ENCODING_UNICODE1, 0, 0, iso8859_7_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 292 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 293 | }; |
| 294 | |
| 295 | static unsigned |
| 296 | iso8859_8_to_unicode(unsigned isocode, void *client_data) |
| 297 | { |
| 298 | if (isocode == 0xA1) |
| 299 | return 0; |
| 300 | else if (isocode < 0xBF) |
| 301 | return isocode; |
| 302 | else if (isocode == 0xDF) |
| 303 | return 0x2017; |
| 304 | else if (isocode >= 0xE0 && isocode <= 0xFA) |
| 305 | return isocode + 0x04F0; |
| 306 | else |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static FontMapRec iso8859_8[] = { |
| 311 | {FONT_ENCODING_UNICODE1, 0, 0, iso8859_8_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 312 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 313 | }; |
| 314 | |
| 315 | static unsigned |
| 316 | iso8859_9_to_unicode(unsigned isocode, void *client_data) |
| 317 | { |
| 318 | switch (isocode) { |
| 319 | case 0xD0: |
| 320 | return 0x011E; |
| 321 | case 0xDD: |
| 322 | return 0x0130; |
| 323 | case 0xDE: |
| 324 | return 0x015E; |
| 325 | case 0xF0: |
| 326 | return 0x011F; |
| 327 | case 0xFD: |
| 328 | return 0x0131; |
| 329 | case 0xFE: |
| 330 | return 0x015F; |
| 331 | default: |
| 332 | return isocode; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | static FontMapRec iso8859_9[] = { |
| 337 | {FONT_ENCODING_UNICODE1, 0, 0, iso8859_9_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 338 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 339 | }; |
| 340 | |
| 341 | static const unsigned short iso8859_10_tophalf[] = { |
| 342 | 0x00A0, 0x0104, 0x0112, 0x0122, 0x012A, 0x0128, 0x0136, 0x00A7, |
| 343 | 0x013B, 0x0110, 0x0160, 0x0166, 0x017D, 0x00AD, 0x016A, 0x014A, |
| 344 | 0x00B0, 0x0105, 0x0113, 0x0123, 0x012B, 0x0129, 0x0137, 0x00B7, |
| 345 | 0x013C, 0x0111, 0x0161, 0x0167, 0x017E, 0x2014, 0x016B, 0x014B, |
| 346 | 0x0100, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x012E, |
| 347 | 0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116, 0x00CD, 0x00CE, 0x00CF, |
| 348 | 0x00D0, 0x0145, 0x014C, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x0168, |
| 349 | 0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, |
| 350 | 0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F, |
| 351 | 0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x00EF, |
| 352 | 0x00F0, 0x0146, 0x014D, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x0169, |
| 353 | 0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x0138 |
| 354 | }; |
| 355 | |
| 356 | static FontEncSimpleMapRec iso8859_10_to_unicode_map = |
| 357 | { 0x60, 0, 0xA0, iso8859_10_tophalf }; |
| 358 | |
| 359 | static FontMapRec iso8859_10[] = { |
| 360 | {FONT_ENCODING_UNICODE1, 0, 0, FontEncSimpleRecode, NULL((void *)0), |
| 361 | &iso8859_10_to_unicode_map, NULL((void *)0), NULL((void *)0)}, |
| 362 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 363 | }; |
| 364 | |
| 365 | static unsigned |
| 366 | iso8859_15_to_unicode(unsigned isocode, void *client_data) |
| 367 | { |
| 368 | switch (isocode) { |
| 369 | case 0xA4: |
| 370 | return 0x20AC; |
| 371 | case 0xA6: |
| 372 | return 0x0160; |
| 373 | case 0xA8: |
| 374 | return 0x0161; |
| 375 | case 0xB4: |
| 376 | return 0x017D; |
| 377 | case 0xB8: |
| 378 | return 0x017E; |
| 379 | case 0xBC: |
| 380 | return 0x0152; |
| 381 | case 0xBD: |
| 382 | return 0x0153; |
| 383 | case 0xBE: |
| 384 | return 0x0178; |
| 385 | default: |
| 386 | return isocode; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | static FontMapRec iso8859_15[] = { |
| 391 | {FONT_ENCODING_UNICODE1, 0, 0, iso8859_15_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), |
| 392 | NULL((void *)0)}, |
| 393 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 394 | }; |
| 395 | |
| 396 | static const unsigned short koi8_r_tophalf[] = { |
| 397 | 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, |
| 398 | 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, |
| 399 | 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2022, 0x221A, 0x2248, |
| 400 | 0x2264, 0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7, |
| 401 | 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, |
| 402 | 0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x255C, 0x255D, 0x255E, |
| 403 | 0x255F, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, |
| 404 | 0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x256B, 0x256C, 0x00A9, |
| 405 | 0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, |
| 406 | 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, |
| 407 | 0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, |
| 408 | 0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A, |
| 409 | 0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, |
| 410 | 0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, |
| 411 | 0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, |
| 412 | 0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A |
| 413 | }; |
| 414 | |
| 415 | static FontEncSimpleMapRec koi8_r_to_unicode_map = |
| 416 | { 0x80, 0, 0x80, koi8_r_tophalf }; |
| 417 | |
| 418 | static FontMapRec koi8_r[] = { |
| 419 | {FONT_ENCODING_UNICODE1, 0, 0, FontEncSimpleRecode, NULL((void *)0), |
| 420 | &koi8_r_to_unicode_map, NULL((void *)0), NULL((void *)0)}, |
| 421 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 422 | }; |
| 423 | |
| 424 | static unsigned |
| 425 | koi8_ru_to_unicode(unsigned koicode, void *client_data) |
| 426 | { |
| 427 | switch (koicode) { |
| 428 | case 0x93: |
| 429 | return 0x201C; |
| 430 | case 0x96: |
| 431 | return 0x201D; |
| 432 | case 0x97: |
| 433 | return 0x2014; |
| 434 | case 0x98: |
| 435 | return 0x2116; |
| 436 | case 0x99: |
| 437 | return 0x2122; |
| 438 | case 0x9B: |
| 439 | return 0x00BB; |
| 440 | case 0x9C: |
| 441 | return 0x00AE; |
| 442 | case 0x9D: |
| 443 | return 0x00AB; |
| 444 | case 0x9F: |
| 445 | return 0x00A4; |
| 446 | case 0xA4: |
| 447 | return 0x0454; |
| 448 | case 0xA6: |
| 449 | return 0x0456; |
| 450 | case 0xA7: |
| 451 | return 0x0457; |
| 452 | case 0xAD: |
| 453 | return 0x0491; |
| 454 | case 0xAE: |
| 455 | return 0x045E; |
| 456 | case 0xB4: |
| 457 | return 0x0404; |
| 458 | case 0xB6: |
| 459 | return 0x0406; |
| 460 | case 0xB7: |
| 461 | return 0x0407; |
| 462 | case 0xBD: |
| 463 | return 0x0490; |
| 464 | case 0xBE: |
| 465 | return 0x040E; |
| 466 | default: |
| 467 | return FontEncSimpleRecode(koicode, &koi8_r_to_unicode_map); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | static FontMapRec koi8_ru[] = { |
| 472 | {FONT_ENCODING_UNICODE1, 0, 0, koi8_ru_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 473 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 474 | }; |
| 475 | |
| 476 | /* koi8-e, ISO-IR-111 or ECMA-Cyrillic */ |
| 477 | |
| 478 | static const unsigned short koi8_e_A0_BF[] = { |
| 479 | 0x00A0, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, |
| 480 | 0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x00AD, 0x045E, 0x045F, |
| 481 | 0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, |
| 482 | 0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x00A4, 0x040E, 0x040F |
| 483 | }; |
| 484 | |
| 485 | static unsigned |
| 486 | koi8_e_to_unicode(unsigned koicode, void *client_data) |
| 487 | { |
| 488 | if (koicode < 0xA0) |
| 489 | return koicode; |
| 490 | else if (koicode < 0xC0) |
| 491 | return koi8_e_A0_BF[koicode - 0xA0]; |
| 492 | else |
| 493 | return FontEncSimpleRecode(koicode, &koi8_r_to_unicode_map); |
| 494 | } |
| 495 | |
| 496 | static FontMapRec koi8_e[] = { |
| 497 | {FONT_ENCODING_UNICODE1, 0, 0, koi8_e_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 498 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 499 | }; |
| 500 | |
| 501 | /* Koi8 unified */ |
| 502 | |
| 503 | static const unsigned short koi8_uni_80_BF[] = { |
| 504 | 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, |
| 505 | 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, |
| 506 | 0x2591, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, |
| 507 | 0x00A9, 0x2122, 0x00A0, 0x00BB, 0x00AE, 0x00AB, 0x00B7, 0x00A4, |
| 508 | 0x00A0, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, |
| 509 | 0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x0491, 0x045E, 0x045F, |
| 510 | 0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, |
| 511 | 0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x0490, 0x040E, 0x040F |
| 512 | }; |
| 513 | |
| 514 | static unsigned |
| 515 | koi8_uni_to_unicode(unsigned koicode, void *client_data) |
| 516 | { |
| 517 | if (koicode < 0x80) |
| 518 | return koicode; |
| 519 | else if (koicode < 0xC0) |
| 520 | return koi8_uni_80_BF[koicode - 0x80]; |
| 521 | else |
| 522 | return FontEncSimpleRecode(koicode, &koi8_r_to_unicode_map); |
| 523 | } |
| 524 | |
| 525 | static FontMapRec koi8_uni[] = { |
| 526 | {FONT_ENCODING_UNICODE1, 0, 0, koi8_uni_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 527 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 528 | }; |
| 529 | |
| 530 | /* Ukrainian variant of Koi8-R; see RFC 2319 */ |
| 531 | |
| 532 | static unsigned |
| 533 | koi8_u_to_unicode(unsigned koicode, void *client_data) |
| 534 | { |
| 535 | switch (koicode) { |
| 536 | case 0xA4: |
| 537 | return 0x0454; |
| 538 | case 0xA6: |
| 539 | return 0x0456; |
| 540 | case 0xA7: |
| 541 | return 0x0457; |
| 542 | case 0xAD: |
| 543 | return 0x0491; |
| 544 | case 0xB4: |
| 545 | return 0x0404; |
| 546 | case 0xB6: |
| 547 | return 0x0406; |
| 548 | case 0xB7: |
| 549 | return 0x0407; |
| 550 | case 0xBD: |
| 551 | return 0x0490; |
| 552 | default: |
| 553 | return FontEncSimpleRecode(koicode, &koi8_r_to_unicode_map); |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | static FontMapRec koi8_u[] = { |
| 558 | {FONT_ENCODING_UNICODE1, 0, 0, koi8_u_to_unicode, NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 559 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 560 | }; |
| 561 | |
| 562 | /* Microsoft Symbol, which is only meaningful for TrueType fonts, is |
| 563 | treated specially in ftenc.c, where we add usFirstCharIndex-0x20 to |
| 564 | the glyph index before applying the cmap. Lovely design. */ |
| 565 | |
| 566 | static FontMapRec microsoft_symbol[] = { |
| 567 | {FONT_ENCODING_TRUETYPE2, 3, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 568 | /* You never know */ |
| 569 | {FONT_ENCODING_TRUETYPE2, 3, 1, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 570 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 571 | }; |
| 572 | |
| 573 | static FontMapRec apple_roman[] = { |
| 574 | {FONT_ENCODING_TRUETYPE2, 1, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)}, |
| 575 | {0, 0, 0, NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0)} |
| 576 | }; |
| 577 | |
| 578 | /* The data for recodings */ |
| 579 | |
| 580 | /* For compatibility with X11R6.4. Losers. */ |
| 581 | static char *iso8859_15_aliases[2] = { "fcd8859-15", NULL((void *)0) }; |
| 582 | |
| 583 | static FontEncRec initial_encodings[] = { |
| 584 | {"iso10646-1", NULL((void *)0), 256 * 256, 0, iso10646, NULL((void *)0), 0, 0}, /* Unicode */ |
| 585 | {"iso8859-1", NULL((void *)0), 256, 0, iso8859_1, NULL((void *)0), 0, 0}, /* Latin 1 (West European) */ |
| 586 | {"iso8859-2", NULL((void *)0), 256, 0, iso8859_2, NULL((void *)0), 0, 0}, /* Latin 2 (East European) */ |
| 587 | {"iso8859-3", NULL((void *)0), 256, 0, iso8859_3, NULL((void *)0), 0, 0}, /* Latin 3 (South European) */ |
| 588 | {"iso8859-4", NULL((void *)0), 256, 0, iso8859_4, NULL((void *)0), 0, 0}, /* Latin 4 (North European) */ |
| 589 | {"iso8859-5", NULL((void *)0), 256, 0, iso8859_5, NULL((void *)0), 0, 0}, /* Cyrillic */ |
| 590 | {"iso8859-6", NULL((void *)0), 256, 0, iso8859_6, NULL((void *)0), 0, 0}, /* Arabic */ |
| 591 | {"iso8859-7", NULL((void *)0), 256, 0, iso8859_7, NULL((void *)0), 0, 0}, /* Greek */ |
| 592 | {"iso8859-8", NULL((void *)0), 256, 0, iso8859_8, NULL((void *)0), 0, 0}, /* Hebrew */ |
| 593 | {"iso8859-9", NULL((void *)0), 256, 0, iso8859_9, NULL((void *)0), 0, 0}, /* Latin 5 (Turkish) */ |
| 594 | {"iso8859-10", NULL((void *)0), 256, 0, iso8859_10, NULL((void *)0), 0, 0}, /* Latin 6 (Nordic) */ |
| 595 | {"iso8859-15", iso8859_15_aliases, 256, 0, iso8859_15, NULL((void *)0), 0, 0}, /* Latin 9 */ |
| 596 | {"koi8-r", NULL((void *)0), 256, 0, koi8_r, NULL((void *)0), 0, 0}, /* Russian */ |
| 597 | {"koi8-ru", NULL((void *)0), 256, 0, koi8_ru, NULL((void *)0), 0, 0}, /* Ukrainian */ |
| 598 | {"koi8-uni", NULL((void *)0), 256, 0, koi8_uni, NULL((void *)0), 0, 0}, /* Russian/Ukrainian/Bielorussian */ |
| 599 | {"koi8-e", NULL((void *)0), 256, 0, koi8_e, NULL((void *)0), 0, 0}, /* ``European'' */ |
| 600 | {"koi8-u", NULL((void *)0), 256, 0, koi8_u, NULL((void *)0), 0, 0}, /* Ukrainian too */ |
| 601 | {"microsoft-symbol", NULL((void *)0), 256, 0, microsoft_symbol, NULL((void *)0), 0, 0}, |
| 602 | {"apple-roman", NULL((void *)0), 256, 0, apple_roman, NULL((void *)0), 0, 0}, |
| 603 | {NULL((void *)0), NULL((void *)0), 0, 0, NULL((void *)0), NULL((void *)0), 0, 0} |
| 604 | }; |
| 605 | |
| 606 | static FontEncPtr font_encodings = NULL((void *)0); |
| 607 | |
| 608 | static void |
| 609 | define_initial_encoding_info(void) |
| 610 | { |
| 611 | FontEncPtr encoding; |
| 612 | FontMapPtr mapping; |
| 613 | |
| 614 | font_encodings = initial_encodings; |
| 615 | for (encoding = font_encodings; ; encoding++) { |
| 616 | encoding->next = encoding + 1; |
| 617 | for (mapping = encoding->mappings; ; mapping++) { |
| 618 | mapping->next = mapping + 1; |
| 619 | mapping->encoding = encoding; |
| 620 | if (mapping->next->type == 0) { |
| 621 | mapping->next = NULL((void *)0); |
| 622 | break; |
| 623 | } |
| 624 | } |
| 625 | if (!encoding->next->name) { |
| 626 | encoding->next = NULL((void *)0); |
| 627 | break; |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | char * |
| 633 | FontEncFromXLFD(const char *name, int length) |
| 634 | { |
| 635 | const char *p; |
| 636 | char *q; |
| 637 | static char charset[MAXFONTNAMELEN1024]; |
| 638 | int len; |
| 639 | |
| 640 | if (length > MAXFONTNAMELEN1024 - 1) |
| 641 | return NULL((void *)0); |
| 642 | |
| 643 | if (name == NULL((void *)0)) |
| 644 | p = NULL((void *)0); |
| 645 | else { |
| 646 | p = name + length - 1; |
| 647 | while (p > name && *p != '-') |
| 648 | p--; |
| 649 | p--; |
| 650 | while (p >= name && *p != '-') |
| 651 | p--; |
| 652 | if (p <= name) |
| 653 | p = NULL((void *)0); |
| 654 | } |
| 655 | |
| 656 | /* now p either is null or points at the '-' before the charset registry */ |
| 657 | |
| 658 | if (p == NULL((void *)0)) |
| 659 | return NULL((void *)0); |
| 660 | |
| 661 | len = length - (p - name) - 1; |
| 662 | memcpy(charset, p + 1, len)__builtin___memcpy_chk (charset, p + 1, len, __builtin_object_size (charset, 0)); |
| 663 | charset[len] = 0; |
| 664 | |
| 665 | /* check for a subset specification */ |
| 666 | if ((q = strchr(charset, (int) '['))) |
| 667 | *q = 0; |
| 668 | |
| 669 | return charset; |
| 670 | } |
| 671 | |
| 672 | unsigned |
| 673 | FontEncRecode(unsigned code, FontMapPtr mapping) |
| 674 | { |
| 675 | FontEncPtr encoding = mapping->encoding; |
| 676 | |
| 677 | if (encoding && mapping->recode) { |
| 678 | if (encoding->row_size == 0) { |
| 679 | /* linear encoding */ |
| 680 | if (code < encoding->first || code >= encoding->size) |
| 681 | return 0; |
| 682 | } |
| 683 | else { |
| 684 | /* matrix encoding */ |
| 685 | int row = code / 0x100, col = code & 0xFF; |
| 686 | |
| 687 | if (row < encoding->first || row >= encoding->size || |
| 688 | col < encoding->first_col || col >= encoding->row_size) |
| 689 | return 0; |
| 690 | } |
| 691 | return (*mapping->recode) (code, mapping->client_data); |
| 692 | } |
| 693 | else |
| 694 | return code; |
| 695 | } |
| 696 | |
| 697 | char * |
| 698 | FontEncName(unsigned code, FontMapPtr mapping) |
| 699 | { |
| 700 | FontEncPtr encoding = mapping->encoding; |
| 701 | |
| 702 | if (encoding && mapping->name) { |
| 703 | if ((encoding->row_size == 0 && code >= encoding->size) || |
| 704 | (encoding->row_size != 0 && |
| 705 | (code / 0x100 >= encoding->size || |
| 706 | (code & 0xFF) >= encoding->row_size))) |
| 707 | return NULL((void *)0); |
| 708 | return (*mapping->name) (code, mapping->client_data); |
| 709 | } |
| 710 | else |
| 711 | return NULL((void *)0); |
| 712 | } |
| 713 | |
| 714 | FontEncPtr |
| 715 | FontEncFind(const char *encoding_name, const char *filename) |
| 716 | { |
| 717 | FontEncPtr encoding; |
| 718 | char **alias; |
| 719 | |
| 720 | if (font_encodings == NULL((void *)0)) |
| 721 | define_initial_encoding_info(); |
| 722 | |
| 723 | for (encoding = font_encodings; encoding; encoding = encoding->next) { |
| 724 | if (!strcasecmp(encoding->name, encoding_name)) |
| 725 | return encoding; |
| 726 | if (encoding->aliases) |
| 727 | for (alias = encoding->aliases; *alias; alias++) |
| 728 | if (!strcasecmp(*alias, encoding_name)) |
| 729 | return encoding; |
| 730 | } |
| 731 | |
| 732 | /* Unknown charset, try to load a definition file */ |
| 733 | return FontEncLoad(encoding_name, filename); |
| 734 | } |
| 735 | |
| 736 | FontMapPtr |
| 737 | FontMapFind(FontEncPtr encoding, int type, int pid, int eid) |
| 738 | { |
| 739 | FontMapPtr mapping; |
| 740 | |
| 741 | if (encoding == NULL((void *)0)) |
| 742 | return NULL((void *)0); |
| 743 | |
| 744 | for (mapping = encoding->mappings; mapping; mapping = mapping->next) { |
| 745 | if (mapping->type != type) |
| 746 | continue; |
| 747 | if (pid > 0 && mapping->pid != pid) |
| 748 | continue; |
| 749 | if (eid > 0 && mapping->eid != eid) |
| 750 | continue; |
| 751 | return mapping; |
| 752 | } |
| 753 | return NULL((void *)0); |
| 754 | } |
| 755 | |
| 756 | FontMapPtr |
| 757 | FontEncMapFind(const char *encoding_name, int type, int pid, int eid, |
| 758 | const char *filename) |
| 759 | { |
| 760 | FontEncPtr encoding; |
| 761 | FontMapPtr mapping; |
| 762 | |
| 763 | encoding = FontEncFind(encoding_name, filename); |
| 764 | if (encoding == NULL((void *)0)) |
| 765 | return NULL((void *)0); |
| 766 | mapping = FontMapFind(encoding, type, pid, eid); |
| 767 | return mapping; |
| 768 | } |
| 769 | |
| 770 | static FontEncPtr |
| 771 | FontEncLoad(const char *encoding_name, const char *filename) |
| 772 | { |
| 773 | FontEncPtr encoding; |
| 774 | |
| 775 | encoding = FontEncReallyLoad(encoding_name, filename); |
| 776 | if (encoding == NULL((void *)0)) { |
| 777 | return NULL((void *)0); |
| 778 | } |
| 779 | else { |
| 780 | char **alias; |
| 781 | int found = 0; |
| 782 | |
| 783 | /* Check whether the name is already known for this encoding */ |
| 784 | if (strcasecmp(encoding->name, encoding_name) == 0) { |
| 785 | found = 1; |
| 786 | } |
| 787 | else { |
| 788 | if (encoding->aliases) { |
| 789 | for (alias = encoding->aliases; *alias; alias++) |
| 790 | if (!strcasecmp(*alias, encoding_name)) { |
| 791 | found = 1; |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | if (!found) { |
| 798 | /* Add a new alias. This works because we know that this |
| 799 | particular encoding has been allocated dynamically */ |
| 800 | char **new_aliases; |
| 801 | char *new_name; |
| 802 | int numaliases = 0; |
| 803 | |
| 804 | new_name = strdup(encoding_name); |
| 805 | if (new_name == NULL((void *)0)) |
| 806 | return NULL((void *)0); |
| 807 | if (encoding->aliases) { |
| 808 | for (alias = encoding->aliases; *alias; alias++) |
| 809 | numaliases++; |
| 810 | } |
| 811 | new_aliases = malloc((numaliases + 2) * sizeof(char *)); |
| 812 | if (new_aliases == NULL((void *)0)) { |
| 813 | free(new_name); |
| 814 | return NULL((void *)0); |
| 815 | } |
| 816 | if (encoding->aliases) { |
| 817 | memcpy(new_aliases, encoding->aliases,__builtin___memcpy_chk (new_aliases, encoding->aliases, numaliases * sizeof(char *), __builtin_object_size (new_aliases, 0)) |
| 818 | numaliases * sizeof(char *))__builtin___memcpy_chk (new_aliases, encoding->aliases, numaliases * sizeof(char *), __builtin_object_size (new_aliases, 0)); |
| 819 | free(encoding->aliases); |
| 820 | } |
| 821 | new_aliases[numaliases] = new_name; |
| 822 | new_aliases[numaliases + 1] = NULL((void *)0); |
| 823 | encoding->aliases = new_aliases; |
| 824 | } |
| 825 | |
| 826 | /* register the new encoding */ |
| 827 | encoding->next = font_encodings; |
| 828 | font_encodings = encoding; |
| 829 | |
| 830 | return encoding; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | unsigned |
| 835 | FontEncSimpleRecode(unsigned code, void *client_data) |
| 836 | { |
| 837 | FontEncSimpleMapPtr map; |
| 838 | unsigned index; |
| 839 | |
| 840 | map = client_data; |
| 841 | |
| 842 | if (code > 0xFFFF || (map->row_size && (code & 0xFF) >= map->row_size)) |
| 843 | return 0; |
| 844 | |
| 845 | if (map->row_size) |
| 846 | index = (code & 0xFF) + (code >> 8) * map->row_size; |
| 847 | else |
| 848 | index = code; |
| 849 | |
| 850 | if (map->map && index >= map->first && index < map->first + map->len) |
| 851 | return map->map[index - map->first]; |
| 852 | else |
| 853 | return code; |
| 854 | } |
| 855 | |
| 856 | char * |
| 857 | FontEncSimpleName(unsigned code, void *client_data) |
| 858 | { |
| 859 | FontEncSimpleNamePtr map; |
| 860 | |
| 861 | map = client_data; |
| 862 | if (map && code >= map->first && code < map->first + map->len) |
| 863 | return map->map[code - map->first]; |
| 864 | else |
| 865 | return NULL((void *)0); |
| 866 | } |
| 867 | |
| 868 | unsigned |
| 869 | FontEncUndefinedRecode(unsigned code, void *client_data) |
| 870 | { |
| 871 | return code; |
| 872 | } |
| 873 | |
| 874 | char * |
| 875 | FontEncUndefinedName(unsigned code, void *client_data) |
| 876 | { |
| 877 | return NULL((void *)0); |
| 878 | } |
| 879 | |
| 880 | #define FONTENC_SEGMENT_SIZE256 256 |
| 881 | #define FONTENC_SEGMENTS256 256 |
| 882 | #define FONTENC_INVERSE_CODES(256 * 256) (FONTENC_SEGMENT_SIZE256 * FONTENC_SEGMENTS256) |
| 883 | |
| 884 | static unsigned int |
| 885 | reverse_reverse(unsigned i, void *data) |
| 886 | { |
| 887 | int s, j; |
| 888 | unsigned **map = (unsigned **) data; |
| 889 | |
| 890 | if (i >= FONTENC_INVERSE_CODES(256 * 256)) |
| 891 | return 0; |
| 892 | |
| 893 | if (map == NULL((void *)0)) |
| 894 | return 0; |
| 895 | |
| 896 | s = i / FONTENC_SEGMENT_SIZE256; |
| 897 | j = i % FONTENC_SEGMENT_SIZE256; |
| 898 | |
| 899 | if (map[s] == NULL((void *)0)) |
| 900 | return 0; |
| 901 | else |
| 902 | return map[s][j]; |
| 903 | } |
| 904 | |
| 905 | static int |
| 906 | tree_set(unsigned int **map, unsigned int i, unsigned int j) |
| 907 | { |
| 908 | int s, c; |
| 909 | |
| 910 | if (i >= FONTENC_INVERSE_CODES(256 * 256)) |
| 911 | return FALSE0; |
| 912 | |
| 913 | s = i / FONTENC_SEGMENT_SIZE256; |
| 914 | c = i % FONTENC_SEGMENT_SIZE256; |
| 915 | |
| 916 | if (map[s] == NULL((void *)0)) { |
| 917 | map[s] = calloc(FONTENC_SEGMENT_SIZE256, sizeof(int)); |
| 918 | if (map[s] == NULL((void *)0)) |
| 919 | return FALSE0; |
| 920 | } |
| 921 | |
| 922 | map[s][c] = j; |
| 923 | return TRUE1; |
| 924 | } |
| 925 | |
| 926 | FontMapReversePtr |
| 927 | FontMapReverse(FontMapPtr mapping) |
| 928 | { |
| 929 | FontEncPtr encoding = mapping->encoding; |
| 930 | FontMapReversePtr reverse = NULL((void *)0); |
| 931 | unsigned int **map = NULL((void *)0); |
| 932 | int i, j, k; |
| 933 | |
| 934 | if (encoding == NULL((void *)0)) |
| 935 | goto bail; |
| 936 | |
| 937 | map = calloc(FONTENC_SEGMENTS256, sizeof(int *)); |
Result of 'calloc' is converted to a pointer of type 'unsigned int *', which is incompatible with sizeof operand type 'int *' | |
| 938 | if (map == NULL((void *)0)) |
| 939 | goto bail; |
| 940 | |
| 941 | if (encoding->row_size == 0) { |
| 942 | for (i = encoding->first; i < encoding->size; i++) { |
| 943 | k = FontEncRecode(i, mapping); |
| 944 | if (k != 0) |
| 945 | if (!tree_set(map, k, i)) |
| 946 | goto bail; |
| 947 | } |
| 948 | } |
| 949 | else { |
| 950 | for (i = encoding->first; i < encoding->size; i++) { |
| 951 | for (j = encoding->first_col; j < encoding->row_size; j++) { |
| 952 | k = FontEncRecode(i * 256 + j, mapping); |
| 953 | if (k != 0) |
| 954 | if (!tree_set(map, k, i * 256 + j)) |
| 955 | goto bail; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | reverse = malloc(sizeof(FontMapReverseRec)); |
| 961 | if (!reverse) |
| 962 | goto bail; |
| 963 | |
| 964 | reverse->reverse = reverse_reverse; |
| 965 | reverse->data = map; |
| 966 | return reverse; |
| 967 | |
| 968 | bail: |
| 969 | free(map); |
| 970 | free(reverse); |
| 971 | return NULL((void *)0); |
| 972 | } |
| 973 | |
| 974 | void |
| 975 | FontMapReverseFree(FontMapReversePtr delendum) |
| 976 | { |
| 977 | unsigned int **map = (unsigned int **) delendum; |
| 978 | int i; |
| 979 | |
| 980 | if (map == NULL((void *)0)) |
| 981 | return; |
| 982 | |
| 983 | for (i = 0; i < FONTENC_SEGMENTS256; i++) |
| 984 | free(map[i]); |
| 985 | |
| 986 | free(map); |
| 987 | return; |
| 988 | } |