Drawings SDK requires access to font files in order to calculate text extents and to vectorize text. Drawings SDK supports both SHX fonts and Truetype fonts. However, the target system must have the correct font files installed for the Drawings to vectorize and find the extents of text that uses a particular font. One of the most common causes for incorrect text vectorization/extents is a missing font file. In such cases, the Drawings will substitute a new font for the missing font, but normally this will cause vectorization and extents differences as the dimensions of the characters in the substituted font will be different from those in the missing font.
Drawings SDK contains platform neutral code to read and process SHX font files. Truetype fonts are handled in a platform-specific manner. For Windows, the Drawings SDK uses Windows calls to stroke out TTF characters. For other platforms, the Drawings SDK uses the Freetype font library (TD_XXXX_Freetype.*).
SHX fonts (both regular SHX fonts and bigfonts) are represented by a file name, for example, txt.shx. Truetype fonts can be represented be a file name, for example arial.ttf, or a typeface name such as "Times New Roman".
Drawings SDK performs the following steps when attempting to access a font file:
Note: The MTEXT rendering engine uses the OdDbHostAppServices::getSubstituteFontByChar() method if the current font (TTF or SHX) doesn’t contain a necessary character. The method returns the type face for the substituted current font.
Drawings SDK contains two built-in default SHX fonts, a simple font similar to txt.shx, and a gdt font. These fonts are used during vectorization and extents calculations when all of the above methods fail to yield a valid font or font file. The tables below represent sets of characters with corresponding hex-codes for each of the default fonts.
Set of characters for default gdt font:
Set of characters for default simple font:
Operation platforms (macOS, Unix, Windows) can have different encoding types. In this case, convert a string from one codepage to another. It is much better to use the OdCharMapper class. For example, to get a correct string from UTF8 to Unicode, use the OdCharMapper::utf8ToUnicode() method:
OdArray buf;
OdCharMapper::utf8ToUnicode(DWG.szDWGFilePath, 512, buf);
OdString sFilePath(buf.getPtr());
Starting with the file format version AC21, a drawing stores text in Unicode. Before this version, strings are stored in the drawing with MBCS (multi-byte character set) coding. There are early versions of drawings that don't have code page information. So in the case of a .dwg file version AC18 and later, Big Font code page is used for converting multi-byte to Unicode. In the case of DXF file loading, system code (system locale) page is used. This is the same behavior as with Autodesk AutoCAD.
Drawings SDK supports the following code page identifications declared by the OdAsianCpIndex enumeration:
Id | Number | Language | Enumeration |
0 | undefined | undefined | |
1 | 932 | Japanese (Shift-JIS) | JAPANESE_CP_INDEX |
2 | 950 | Traditional Chinese (Big 5) | TRADITIONAL_CHINESE_CP_INDEX |
3 | 949 | Wansung (KS C-5601-1987) | KOREAN_WANSUNG_CP_INDEX |
4 | 1361 | Johab (KS C-5601-1992) | KOREAN_JOHAB_CP_INDEX |
5 | 936 | Simplified Chinese (GB 2312-80) | SIMPLIFIED_CHINESE_CP_INDEX |
A font mapping file is a text file where each line specifies a font substitution. A font substitution is of the form:
<original font>;<font to substitute>
The original font can be either a typeface name or a file name. However, the substitute font should be a file name. For example:
romb;ROMAB___.TTF
romi;ROMAI___.TTF
Asian Language Big Fonts included in the Drawings SDK map by default:
Font File Name | Description | Index |
@extfont2.shx | Japanese vertical font | 1 |
bigfont.shx | Japanese font, subset of characters | 1 |
chineset.shx | Traditional Chinese font | 2 |
extfont.shx | Japanese extended font, level 1 | 1 |
extfont2.shx | Japanese extended font, level 2 | 1 |
gbcbig.shx | Simplified Chinese font | 5 |
whgdtxt.shx | Korean font | 3 |
whgtxt.shx | Korean font | 3 |
whgtxt.shx | Korean font | 3 |
whtmtxt.shx | Korean font | 3 |
A different big font must be added to the map for correct conversion from Unicode to MBCS. The next two methods can be used to populate the map with the font — code page pairs:
void OdCharMapper::addBigFontWithIndex (const OdString& bigFont, OdInt32 cpIndex);
void OdCharMapper::addBigFontWithCodepage (const OdString& bigFont, OdCodePageId acad_cp);
Get the index and code page using the next methods:
OdCodePageId OdCharMapper::getCpByBigFont(const OdString& bigFont);
OdInt32 OdCharMapper::getCpIndexByBigFont(const OdString& bigFont);
A list of big fonts may be added with the next method:
OdResult OdCharMapper::addBigFonts(OdStreamBuf* io);
Format "io" stream is:
<BIGFONTFILENAME.SHX> ; <CODE PAGE INDEX>
where CODE PAGE INDEX can be a value as in "enum OdAsianCpIndex".
For custom big fonts, use a "bigfont.ini" file, which specifies code pages for custom double-byte SHX big fonts.
Big fonts are used as an additional font only together with a main font. A big font cannot be used as a single font and also it cannot be used with Truetype fonts. The text style record object has the fileName() method that returns the main font and the bigFontFileName() method that returns the big font.
Unicode characters are converted to MBCB using the big font codepage when they are rendered. Therefore, the big font must be added in the big font mapping using the OdCharMapper class. The big font is used for rendering of characters when it exists.
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|