OBD:Text encoding

From OniGalore
Revision as of 16:08, 29 December 2021 by Iritscen (talk | contribs) (general copy-edit and wiki touch-up)
Jump to navigation Jump to search

Beyond the US English release of the game, Oni's text is known to have been translated into French, Italian, Spanish, German, Japanese and Chinese by various localization companies. Depending on the language version, vanilla Oni uses one of the following five encodings to render text:

  • The original US version uses a trimmed-down Mac OS Roman code page that is effectively limited to US-ASCII (96 code points).
  • European localizations (UK English, French, Italian, Spanish, German) use a custom version of Mac OS Roman (192 code points).
  • The Russian localization uses a full implementation of the Windows-1251 (Cyrillic) code page (224 code points).
  • The Chinese localization uses the EUC-CN implementation of GB 2312 (8,836 code points).
  • The Japanese localization uses 1,357 code points mostly conforming to the Shift JIS implementation of JIS X 0208.

Properties of the fonts that are eventually used to render the text (via the encoding) are briefly described throughout the page.

A more thorough overview of the glyphs can be found HERE.

Encodings

US English

Below is the code page implemented by TSFFTahoma in the US English version of Oni. It is based on Mac OS Roman ("MacRoman"), but with two differences:

  • Of the 223 printable glyphs provided by MacRoman, 42 were not created in TSFFTahoma (shown as grey-on-black).
  • Control point 0x7F (a typically non-printable "delete" character) is visible as a box glyph (◻).
  ...0 ...1 ...2 ...3 ...4 ...5 ...6 ...7 ...8 ...9 ...A ...B ...C ...D ...E ...F
0x2... SP ! " # $ % & ' ( ) * + , - . /
0x3... 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
0x4... @ A B C D E F G H I J K L M N O
0x5... P Q R S T U V W X Y Z [ \ ] ^ _
0x6... ` a b c d e f g h i j k l m n o
0x7... p q r s t u v w x y z { | } ~
0x8... Ä Å Ç É Ñ Ö Ü á à â ä ã å ç é è
0x9... ê ë í ì î ï ñ ó ò ô ö õ ú ù û ü
0xA... ° £ § ß ® © ´ ¨ Æ Ø
0xB... ± Ұ µ π ª º Ω æ ø
0xC... ¿ ¡ ¬ ƒ « » NBSP À Ã Õ Œ œ
0xD... ÷ ÿ Ÿ ¤
0xE... · Â Ê Á Ë È Í Î Ï Ì Ó Ô
0xF... Platform-Mac.png Ò Ú Û Ù ı ˆ ˜ ¯ ̆ ̇ ̊ ̧ ̋ ̨ ̌
Minor notes
  • The layout was apparently "borrowed" before Mac OS 8.5 came out in 1998. How can we say that? Because 8.5 replaced MacRoman's glyph at 0xDB, which was the international currency sign or scarab (¤), with the euro symbol (€), but TSFFTahoma still has the scarab.
  • The Yen/Yuan symbol only has a single horizontal stroke, presumably due to lack of available detail at small font sizes.
Major notes
  • Some of the removed glyphs (most importantly ß, Ê, ù and û, but also Ú and ú) occur in common European languages. This made the US TSFFTahoma unsuitable for EFIGS localizations, requiring the creation of a new version (see below).
  • The US engine cannot interpret any code points beyond the US-ASCII range (first 6 rows, white background), such as "…" (see "Ellipsis issue" below). This is because of a provision for Asian encoding systems (EUC-CN and Shift JIS), which use two-byte sequences starting with a high-bit byte.

European

The code page used by the five Western European versions (UK English, French, German, Spanish and Italian) is slightly different from the trimmed-down Mac OS Roman.

  • It tends to the needs of European localizations by adding back the following characters:
German ß; French Ê and û; French/Italian ù; Spanish/Italian Ú and ú (relatively rare).
N.B. The characters Æ and ÿ are not reinstated, despite their (very rare) occurrence in French script.
  • Awkwardly enough, the six characters are not restored in their original positions (grey-on-black), but take the place of math symbols. Four more "math" positions are inexplicably filled with three duplicate characters (œ, ¡ and ª) and the truly enigmatic character ʖ̇ (which doesn't seem to be a character in any known language and is not in Unicode).
N.B. The broken italic font variants do not fully implement the 10 new glyphs and use a regular question mark instead of the ʖ̇.
  ...0 ...1 ...2 ...3 ...4 ...5 ...6 ...7 ...8 ...9 ...A ...B ...C ...D ...E ...F
0x2... SP ! " # $ % & ' ( ) * + , - . /
0x3... 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
0x4... @ A B C D E F G H I J K L M N O
0x5... P Q R S T U V W X Y Z [ \ ] ^ _
0x6... ` a b c d e f g h i j k l m n o
0x7... p q r s t u v w x y z { | } ~
0x8... Ä Ç É Ñ Ö Ü á à â ä ã å ç é è
0x9... ê ë í ì î ï ñ ó ò ô ö ú ù û ü
0xA... £ § ß ® © ´ ¨ Ø
0xB... ± Ұ µ Ê Ú ù ú û ª ß œ æ ø
0xC... ¿ ¡ ¬ ¡ ƒ ʖ̇ ª « » À Õ Œ œ
0xD... ÷ Ÿ ¤
0xE... Â Ê Á Ë È Í Î Ï Ì Ó Ô
0xF... Ò Ú Û Ù ˆ ˜ ¯

Coincidentally, with the 10 new glyphs, the European code page has exactly 96 glyphs in the US-ASCII half and 96 in the extension half (blue).

N.B. Unlike the US version, all five Western European versions (including UK English) are able to render the full extended ASCII set.

Cyrillic

In the Russian version of Oni, TSFFTahoma fully implements the Windows-1251 (Cyrillic) code page.

  • All the Windows-1251 characters are present, although only 66 (purple) are used by Russian script.
  • The character 0x98 is normally non-printable, but in this font is visible as a box glyph (☐), like 0x7F.
  • Apart from 0x20, there are two whitespace characters: the non-breaking space and the soft hyphen.
  ...0 ...1 ...2 ...3 ...4 ...5 ...6 ...7 ...8 ...9 ...A ...B ...C ...D ...E ...F
0x2... SP ! " # $ % & ' ( ) * + , - . /
0x3... 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
0x4... @ A B C D E F G H I J K L M N O
0x5... P Q R S T U V W X Y Z [ \ ] ^ _
0x6... ` a b c d e f g h i j k l m n o
0x7... p q r s t u v w x y z { | } ~
0x8... Ђ Ѓ ѓ Љ Њ Ќ Ћ Џ
0x9... ђ љ њ ќ ћ џ
0xA... NBSP Ў ў Ј ¤ Ґ ¦ § Ё © Є « ¬ SHY ® Ї
0xB... ° ± І і ґ µ · ё є » ј Ѕ ѕ ї
0xC... А Б В Г Д Е Ж З И Й К Л М Н О П
0xD... Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я
0xE... а б в г д е ж з и й к л м н о п
0xF... р с т у ф х ц ч ш щ ъ ы ь э ю я

Chinese

The Chinese version of Oni has the same TSFFTahoma as the original US version (trimmed-down Mac OS Roman), but the engine cannot interpret the extended ASCII range, and in fact does not use TSFFTahoma at all. Instead the user launches a wrapper mini-app called oni.exe which in turn executes the code in Oni.dat (the game binary itself – in fact, the original Oni.exe from the US version), injecting a custom text engine found in xfhsm_oni.dll and the font data in xf_font.dat. Text strings that Oni intends to display are then intercepted by xfhsm_oni.dll and the resulting pixel data from xf_font.dat is injected into Oni's OpenGL context.

Unlike other versions of Oni, the Chinese font doesn't have a table listing the valid code points along with their "glyph descriptors" (i.e., instructions on how to extract a glyph from the raw pixel data). Instead all the glyphs have a standard size of 16x16 pixels and there are exactly 94x94=8,836 glyphs, filling up a standard GB 2312 plane (qūwèi), indexed through a compact numbering scheme known as EUC-CN: each of the 94x94 code points is indexed by a pair of bytes that are both in the 0xA1-0xFE range. Code points that are not assigned under GB 2312 (e.g. rows 10-15 and 90-94) simply have blank pixel data in the corresponding regions of xf_font.dat.

The pixel packing used by xf_font.dat is 1-bit black-and-white (i.e., without antialiasing), which is much more space-efficient than the 8-bit grayscale storage used in Oni's TSFT. Another gain comes from not having any glyph descriptors (TSGAs). Both a regular and a bold typeface are available (but in one size only, fixed-width 16x16).

At the time of writing, the pixel data in xf_font.dat has not been thoroughly analyzed and compared with GB 2312, so we do not know for sure if all the GB 2312 glyphs are implemented or if there are some additional blanks. The encoding may also be one of several extensions of EUC-CN, although it should be kept in mind that control bytes need to remain inside the 0xA1-0xFE range for the raw 94x94 layout to work.

In theory, EUC-CN allows for single-byte control codes, which would be interpreted as US-ASCII and rendered using Oni's own TSFFTahoma. In practice, all of the strings in the Chinese game data use only two-byte control sequences.


Japanese

Japanese Oni uses a custom two-byte encoding that is mostly consistent with Shift JIS but with some of the control sequences rearranged in seemingly non-standard ways. Like Chinese Oni, the glyph data is stored in new, external files; in this case they are .fnt files stored in GameDataFolder. Three font sizes are available, with pixel sizes 11x11 (JPN_SMALL.fnt), 12x12 (JPN_MIDDLE.fnt) and 14x14 (JPN_BIG.fnt). The 14x14 font has a bold-face variant (JPN_BOLD.fnt). All four fonts are fixed-width, i.e. all glyphs have a square bounding box.

Unlike the Chinese version, the TSFFTahoma contained in the Japanese game data is not limited to the ASCII code page. There are a total of 154 double-byte code points (Romaji, punctuation, kana and kanji) across 19 code pages (TSGA) each corresponding to a different "lead byte" (0x81, 0x82, 0x83, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x95, 0x96, 0x97 and 0x98).

As for the first code page of the Japanese TSFFTahoma, it implements only the 0x20-0x7F range of characters, i.e., is limited to US-ASCII. This is consistent with the simplified logic used by the Japanese engine, where any high-bit byte (in the 0x80-0xFF range) is treated as the start of a two-byte sequence (in actual Shift JIS some high-bit bytes are interpreted as half-width kana).

It must be noted that, as compared to the separate .fnt files, TSFFTahoma provides a very rudimentary implementation of JIS X 0208 (only coding for 154 double-byte glyphs, whereas the .fnt files implement 1,357) and is essentially useless/unusable.

  • The Japanese engine requires all four .fnt files to be present (bails out if any of them are missing) and uses them for all of the vanilla text strings, which only contain double-byte control codes. Thus, under normal conditions, TSFFTahoma remains completely unused in the Japanese version.
  • If the US engine is used on the Japanese game data, then the .fnt files are ignored (obviously), and the incomplete TSFFTahoma is used to render the Japanese text strings as well as the few English strings supplied by the EXE. Due to the limited character set, many strings end up broken.

Possibly the incomplete Shift JIS code pages present in the Japanese TSFFTahoma represent an early attempt to implement all the glyphs within Oni's existing text system. As the number of kanji increased, supposedly, the TSFT grew prohibitively large due to the use of 8-bit grayscale storage for the pixel data, and the size taken up by the sparsely populated TSGA also increased out of proportion with the rest of the game data. Once the switch to separate .fnt files was made, no one bothered to clean up TSFFTahoma.

At the time of writing, the code points and pixel data in the Japanese .fnt files have not been thoroughly analyzed and compared with JIS X 0208. We know that 1,357 glyphs are implemented, across 27 "lead bytes" (roughly 50 kuten rows). This is much smaller than the full kuten plane, and makes sense in terms of space efficiency. We also know that some code points are non-standard (rearranged) as compared to regular Shift JIS, although we do not yet know if this rearrangement is consistent with any common variation of Shift JIS. As long as Japanese game data contains text strings that match the game's encoding, non-standard code points are not a problem (but should be kept in mind).

Text anomalies

Ellipsis issue

Unlike other Western versions (UK English, French, German, Italian, Spanish, Russian), the US engine treats high-bit characters as part of a two-byte control sequence (a provision for Asian encodings), and therefore fails to render any character from the extended ASCII range. This happens twice in English Oni, because the ellipsis (…), encoded at 0xC9, was accidentally used in these two text consoles in place of three consecutive dots (probably an auto-substitution by a text editor). The result is that the two lines using a "…" are cut off at the offending character.

(A1,A0) issue

Unlike the Japanese version, where non-standard Shift JIS sequences are explicitly allowed in the .fnt files, the Chinese version does not have a code table and relies on a standard EUC-CN encoding, with exactly 8,836 code points (94x94). A proper EUC-CN control sequence consists of two bytes that are both in the range 0xA1-0xFE (single US-ASCII characters are also allowed in theory).

The text strings in the the Chinese version mostly conform to the EUC-CN scheme, except for the rare occurrence of the (A1,A0) sequence. This is not a valid control sequence under any common extension of EUC-CN, and in any case it does not correspond to any pixel data within xf_font.dat, which only covers the standard 94x94 qūwèi plane, corresponding to a strict 0xA1-0xFE range for the two encoding bytes.

Over-tall text

Although not strictly speaking a font issue, some of Oni's text fails to render because it doesn't fit vertically into a fixed-size frame (such as a text console). This is known to happen for these two consoles in the English version, and possibly for other screens in other language versions.

Over-long text

Chinese glyphs have a fixed size of 16x16 pixels and do not fit horizontally into the drop-down lists, causing a disruptive line wrap to take place (this is visible in the Options screen's Resolution and Difficulty menus).