| 1 | <html> |
| 2 | <title>Creating a Character-Mapping File</title> |
| 3 | |
| 4 | <style type="text/css"><!-- |
| 5 | |
| 6 | table.maps { |
| 7 | margin-left: 2em; |
| 8 | background: #f0f0f0; |
| 9 | } |
| 10 | |
| 11 | table.maps tr.odd { |
| 12 | background: #e0e0e0; |
| 13 | } |
| 14 | |
| 15 | --></style> |
| 16 | |
| 17 | <body> |
| 18 | |
| 19 | <h1>Creating a Character-Mapping File</h1> |
| 20 | |
| 21 | <p>Because TADS 3 uses Unicode internally, TADS programs can work on |
| 22 | practically any computer, in any national language, using any |
| 23 | character set. Unicode is a "universal" character set that encodes |
| 24 | almost every character from almost every written language in the |
| 25 | world. |
| 26 | |
| 27 | <p>Sadly, most computers today do not use Unicode as their native |
| 28 | character sets. In order for TADS to work on non-Unicode computers, |
| 29 | TADS must translate characters between Unicode and native encodings. |
| 30 | To accomplish this without tying itself to any one type of computer, |
| 31 | TADS uses character mapping files. A character mapping file describes |
| 32 | the translation between a computer's native character set and Unicode. |
| 33 | |
| 34 | <p>The Unicode consortium, which is the organization that defines the |
| 35 | Unicode standard, publishes files that describe the correspondence |
| 36 | between Unicode and most native character sets that are in use today. |
| 37 | TADS uses these files as a starting point. |
| 38 | |
| 39 | <p>To create a new character mapping for use with TADS, follow these |
| 40 | steps. |
| 41 | |
| 42 | <p><b>Identify the character set you're using.</b> This is a function |
| 43 | of the type of computer you're using and your computer's localization. |
| 44 | For example, Microsoft Windows systems localized for Eastern or |
| 45 | Central Europe use Windows Code Page 1250. |
| 46 | |
| 47 | <p><b>Obtain a Unicode mapping file.</b> For most character sets in |
| 48 | widespread use, there's a mapping available from the Unicode web site, |
| 49 | <a href="http://www.unicode.org">www.unicode.org</a>. See below for a |
| 50 | list of common mappings and where to find them on the Unicode site. |
| 51 | The character mapping files as provided on the Unicode ftp site are |
| 52 | <i>almost</i> in a format that you can directly feed into the TADS |
| 53 | character map compiler, but you must make one small addition first. |
| 54 | At the end of the file, add a line that looks like this: |
| 55 | |
| 56 | <code> |
| 57 | default_display 0x81 |
| 58 | </code> |
| 59 | |
| 60 | <p>For the "0x81", however, you should substitute the character that |
| 61 | you want to use as the default display character. This defines the |
| 62 | character that TADS will display when a Unicode character has no |
| 63 | mapping in your native character set. Most native character sets |
| 64 | include an "invalid" character for just this purpose; this character |
| 65 | looks like an empty rectangle in many fonts, but each character set |
| 66 | varies. You should find an appropriate character in your native |
| 67 | character set, and define it for the "default_display" character. |
| 68 | |
| 69 | <p><b>Compile the mapping file.</b> Use the mkchrtab ("make character |
| 70 | table") utility, included with the TADS distribution, to compile the |
| 71 | mapping file into the format that TADS uses: |
| 72 | |
| 73 | <cmdline> |
| 74 | mkchrtab cp1250.txt cp1250.tcm |
| 75 | </cmdline> |
| 76 | |
| 77 | <p>The first argument is the source file that you downloaded from the |
| 78 | Unicode site. The second argument is the name of the "tcm" file (TADS |
| 79 | Character Map) that TADS will use. |
| 80 | |
| 81 | <h2>Download Locations for Common Mappings</h2> |
| 82 | |
| 83 | <table class=maps> |
| 84 | |
| 85 | <tr class=odd><td>ISO 8859 (ISO Latin-n) code pages |
| 86 | <td><a href='ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/'> |
| 87 | ftp://ftp.unicode.org/Public/MAPPINGS/ISO8859/</a> |
| 88 | |
| 89 | <tr><td>MS-DOS code pages |
| 90 | <td><a href='ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/'> |
| 91 | ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/</a> |
| 92 | |
| 93 | <tr class=odd><td>Microsoft Windows code pages |
| 94 | <td><a href='ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/'> |
| 95 | ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/</a> |
| 96 | |
| 97 | <tr><td>Apple Macintosh character sets |
| 98 | <td><a href='ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/APPLE/'> |
| 99 | ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/APPLE/</a> |
| 100 | |
| 101 | <tr class=odd><td>NeXT character sets |
| 102 | <td><a href='ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/NEXT/'> |
| 103 | ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/NEXT/</a> |
| 104 | |
| 105 | </table> |
| 106 | |
| 107 | <h2>Approximation Mappings</h2> |
| 108 | |
| 109 | <p>Since the Unicode character set includes character assignments for |
| 110 | nearly every character used in a written language anywhere in the |
| 111 | world, and most local character sets on existing operating systems and |
| 112 | terminals include character assignments for only a few languages, most |
| 113 | of the characters in the Unicode character set will not be displayable |
| 114 | on most computers. |
| 115 | |
| 116 | <p>As described earlier, the default_display setting in the character |
| 117 | mapping file allows you to specify the glyph to display when a |
| 118 | character cannot be mapped to the local character set. So, if you're |
| 119 | running a game that uses kanji characters on a machine localized for |
| 120 | the United States, the kanji characters will be unmappable and so will |
| 121 | be displayed using the default_display setting. |
| 122 | |
| 123 | <p>In many cases, however, you might want to provide an "approximate" |
| 124 | mapping for some characters. An approximate mapping lets you specify a |
| 125 | local character that is similar enough to a particular Unicode |
| 126 | character that you'd rather display that local character as an |
| 127 | approximation than display the default_display glyph. For example, if |
| 128 | your computer can display only plain ASCII characters (so it doesn't |
| 129 | have any accented letters in its character set), you might want to use |
| 130 | a regular "a" as an approximation for the various accented "a" |
| 131 | characters ("á", "à", "â", and so on). While displaying a |
| 132 | regular "a" for an accented "a" loses some information, it might give |
| 133 | the reader a better chance of understanding the original text than |
| 134 | displaying the default_display character, which doesn't tell the |
| 135 | reader anything other than that the original character can't be |
| 136 | displayed on this system. |
| 137 | |
| 138 | <p>In addition, some glyphs can be approximated visually by combining |
| 139 | two or more glyphs from a more limited character set. For example, |
| 140 | left and right arrows can be approximated by {{<-}} and {{->}}. |
| 141 | |
| 142 | <p>The TADS 3 character mapping system provides an optional mechanism |
| 143 | for making these types of approximations. If you wish to provide |
| 144 | approximations, you must place them after the local-to-Unicode |
| 145 | mappings described earlier (the local-to-Unicode mappings are usually |
| 146 | the ones you obtain from mapping files found on the Unicode web site). |
| 147 | After all of the local-to-Unicode mappings, add this line to your |
| 148 | mapping source file: |
| 149 | |
| 150 | <code> |
| 151 | display_mappings |
| 152 | </code> |
| 153 | |
| 154 | <p>After this line, provide your approximation mappings. These |
| 155 | mappings can take two forms, as shown in these examples: |
| 156 | |
| 157 | <code> |
| 158 | &mdash '--' |
| 159 | 0x0141 'L' |
| 160 | </code> |
| 161 | |
| 162 | <p>In the first form, you can specify an HTML entity name, written |
| 163 | with a leading ampersand ({{&}}) as it is in HTML source code. In the |
| 164 | second form, you use a number (the "0x" prefix indicates that the |
| 165 | number is in hexadecimal; you can specify a decimal number by omitting |
| 166 | the "0x" prefix, but the Unicode listings specify everything in hex so |
| 167 | you would probably want to use hex most of the time). |
| 168 | |
| 169 | <p>In both forms, the first item on the line specifies the Unicode |
| 170 | character to be mapped to a local approximation, and the rest of the |
| 171 | line specifies a string of Unicode characters to substitute for the |
| 172 | original Unicode character. The simplest way to specify the |
| 173 | substitution string is to enclose a string in single quote marks; this |
| 174 | works if all of the substituted characters are plain ASCII characters |
| 175 | (in the Unicode range 0 to 255). If you want to substitute any Unicode |
| 176 | characters outside of the plain ASCII range, use numbers to specify |
| 177 | the Unicode code points of the substitution: |
| 178 | |
| 179 | <code> |
| 180 | &mdash 0x2d 0x2d |
| 181 | </code> |
| 182 | |
| 183 | <p>The numeric form eliminates any character set translation issues |
| 184 | with respect to the character mapping source file itself (the last |
| 185 | thing we need to worry about at this point is how mapping files are |
| 186 | mapped!). |
| 187 | |
| 188 | <p>Important: the substitution string is a set of Unicode characters, |
| 189 | not local characters. These Unicode characters are themselves further |
| 190 | translated into local characters. Note that the Unicode characters in |
| 191 | the substitution string must appear in the local-to-Unicode mapping |
| 192 | section; you cannot substitute a character with no mapping, and you |
| 193 | cannot substitute a character that itself has an approximation |
| 194 | mapping. The character mapper automatically translates the |
| 195 | substitution string to the local character set for display. |
| 196 | |
| 197 | <p>The reason that the substitution string is specified with Unicode |
| 198 | characters rather than local characters is that this allows programs |
| 199 | to perform the approximation substitutions entirely in the Unicode |
| 200 | domain, and then know for certain that each Unicode character in the |
| 201 | substituted string will translate to exactly one local character. This |
| 202 | is important because it allows programs using the character mappings |
| 203 | to process the results of any multiple-character substitutions in the |
| 204 | Unicode domain; for example, the TADS Interpreter's output formatter |
| 205 | uses this information to perform word wrapping on the text that |
| 206 | results from substituting the approximation mappings, which must be |
| 207 | done in the Unicode domain. |
| 208 | |
| 209 | <p>You might wonder why the character mapping file has two separate |
| 210 | sections - one for mappings from local to Unicode, and the other for |
| 211 | approximation mappings. The reason for this dichotomy is that the |
| 212 | character mapper treats the local-to-Unicode mappings as reversible - |
| 213 | each mapping establishes that the local character will be translated |
| 214 | on input to the given Unicode character, and also that the Unicode |
| 215 | character will be translated to the local character on output; in |
| 216 | order to be reversible, the local-to-Unicode entries must be unique, |
| 217 | one-to-one mappings. The Unicode-to-local section, on the other hand, |
| 218 | does not need to provide a unique mapping for each character, because |
| 219 | the character mapper does not assume that these mappings are |
| 220 | reversible - this is a one-way mapping. This is all designed as a |
| 221 | time-saver for people creating character mappings - if one or the |
| 222 | other of these sections weren't reversible, you'd always have to |
| 223 | specify a full set for both directions, because neither set could be |
| 224 | reversed to infer the other; the logical choice for the reversible |
| 225 | mappings is the local-to-Unicode set, because the local character set |
| 226 | will almost always be a small subset of the Unicode set, and hence it |
| 227 | is frequently desirable to map several Unicode characters to a single |
| 228 | local character, but not vice versa. |
| 229 | |
| 230 | <p>For some approximation mapping examples, refer to the default 7-bit |
| 231 | ASCII mapping file "us-ascii.txt" (in the "charmap" subdirectory of |
| 232 | the TADS 3 distribution). |
| 233 | |
| 234 | </body> |
| 235 | </html> |
| 236 |