Q-3-1. Why is char_code in dtCharDoOutput a 4-byte unsigned integer? What is the code for character 'A'?
char_code is a 4-byte unsigned integer (DT_ID_ULONG) referencing a Unicode character. The 4-byte encoding scheme offers additional flexibility and simplifies programming with international character sets. Code for character 'A' is still 65 (as defined by Unicode), but the Unicode representation makes it possible to display all character sets in the world simultaneously. Since ASCII is a subset of Unicode, any ASCII character can be represented as a Unicode character code by casting its value to the DT_ID_ULONG type.
Q-3-2. When using marlet.ttf, wingdings.ttf or webdings.ttf fonts, I do not see any output. I tried to render all of the standard ASCII characters but nothing shows up.
Marlet.ttf, wingdings.ttf and webdings.ttf are symbol fonts. According to the TrueType specification, the term "symbol" is used for "undefined character sets or indexing schemes". This means that applications must know how the characters are encoded within the font in order for the font to be useful.
A Symbol font does not have any characters in the ASCII range 0x00-0xFF (or 0-255 decimal). All of its characters (also called "symbol" characters) are located at private Unicode locations 0xF000-0xF0FF (or 61440-61695 decimal). However, when encountering a Symbol font, Microsoft Windows operating system applies a special rule: it maps all character codes in its private Unicode range 0xF000-0xF0FF to the standard ASCII range 0x00-0xFF. This is most likely done in order to make these characters accessible to Unicode-unaware applications.
Although this behavior is in violation of the Unicode standard, fonts utilizing this so-called encoding sometimes appear. Examples do not only include known symbol fonts such as wingdings.ttf, webdings.ttf and marlet.ttf but also some freeware Roman fonts created using popular font editing tools (e.g. Fontographer). Unaware of what the term "symbol" really means, some font authors choose to save their fonts as Microsoft Symbol Fonts.
Microsoft has recently added the following note about the symbol fonts: "Symbol character sets have a special meaning. If the symbol bit (31) is set, and the font file contains a 'cmap' subtable for platform of 3 and encoding ID of 1, then all of the characters in the Unicode range 0xF000 - 0xF0FF (inclusive) will be used to enumerate the symbol character set. If the bit is not set, any characters present in that range will not be enumerated as a symbol character set."
In order to display symbol characters in the same way Windows operating system does, you have two options:
Option A: perform the conversion yourself
Call the dtFontGetNumericValue function and pass it DV_NVAL_PLATFORM_TYPE to check if the font in question is a symbol font.
If dtFontGetNumericValue returns 200, the font in question is a symbol font. In this case add 0xF000 (or 61440 decimal) to every ASCII character code in your text string before rendering.
For example, to render the character 'A' (Unicode 65), instead of calling dtCharDoOutput(engine, 65, X, Y, 0, &bmp) you will need to call dtCharDoOutput(engine, 65+61440, X, Y, 0, &bmp).
Option B: Let D-Type Font Engine perform the conversion
Alternatively, you can instruct D-Type Font Engine to perform the above conversion for you automatically. To do so, specify font_format_id = 81 (for TrueType or OpenType fonts with TrueType outlines) or font_format_id = 82 (for OpenType fonts with Type 2/CFF outlines) when adding the font to the Font Catalog using one of the dtFontAdd... functions. In order for this automatic conversion to work, you must initialize D-Type Font Engine via the dtype.inf file and the file called ot-win-symbol.ccv must be in the location specified by dtype.inf (typically this is system/ccv/ot-win-symbol.ccv).
Q-3-3. Is it possible to detect if a font does not contain the glyph for a certain Unicode character?
Using D-Type Font Engine, yes. See dtFontGetGlyphIndex for details.
Q-3-4. Can D-Type support character codes beyond the codepoint U+FFFF?
Yes. To enable D-Type's 32-bit Unicode support, which means support beyond the codepoint U+FFFF, three things are required:
1. It is necessary to use D-Type Font Engine 5.0.1.3 (released in August 2014) or more recent.
2. It is necessary to activate Unicode support beyond codepoint U+FFFF (or 65535 using the standard decimal notation) for those font formats whose charmaps can support it: TrueType (.ttf) and OpenType (.otf). This is done by modifying Section A (CHARACTER TRANSLATION FOR WINDOWS UNICODE ENCODING) of the ot-win-unicode.ccv file which can be found in your D-Type's system/ccv/ folder. Specifically, open the ot-win-unicode.ccv file in a text editor and locate the last line of this section. It should look as shown below:
160,-65535,160
This line needs to be changed to:
160,-1114111,160
This will enable support for Unicode codepoints up to U+10FFFF (or 1114111 using the standard decimal notation), which is the highest possible/allowed Unicode codepoint. The entire Section A of the ot-win-unicode.ccv file set up like this is shown below.
# A) CHARACTER TRANSLATION FOR WINDOWS UNICODE ENCODING { 1,-127,1 128,8364 129,0 130,8218 131,402 132,8222 133,8230 134,8224 135,8225 136,710 137,8240 138,352 139,8249 140,338 141,0 142,0 143,0 144,0 145,8216 146,8217 147,8220 148,8221 149,8226 150,8211 151,8212 152,732 153,8482 154,353 155,8250 156,339 157,0 158,0 159,376 160,-1114111,160 -1 }
This step does not apply to D-Type (.dtf) fonts because 32-bit Unicode charmaps are the only charmaps D-Type fonts support.
3. Finally, when loading fonts (i.e. adding them to D-Type's Font Catalog), it is necessary to set the cmap_id parameter to 14. This means: prefer 32-bit Unicode charmaps over legacy Windows Unicode charmaps (which don't provide support beyond codepoint U+FFFF). By default this parameter is set to -1, which is the legacy behavior.
For example, if you are loading the font via D-Type's Initial Font List (dtype.fls), your font should be added to this file as shown below:
3,F0010_HIERO__NS0,0,14,128,1,1,0,../../fonts/Noto Sans Egyptian Hieroglyphs Regular.ttf,DV_NULL
Note that the 4th parameter is set to 14. This is the cmap_id parameter.
That should be it. Once D-Type Font Engine is configured like this, support for 32-bit Unicode codepoints becomes available.