Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Working with Database Containers > Working with Predefined Tables of Named Records > Working with Specific Predefined Tables of Named Records > Text Styles Table > Fonts of Text Styles
Fonts of Text Styles

A font defines the appearance and visual parameters of text. A text style can use either Microsoft® Windows® font or an Autodesk® AutoCAD® font for representing text entities and shapes associated with them. Windows fonts are located in the "...\Windows\Fonts" folder and have a .ttf file extension. Information about Windows fonts is stored in the system registry. Each Windows font uses the registered font name for its own identification. AutoCAD fonts are located in the "...\Program Files\Autodesk\AutoCAD\Fonts" folder and have a .shx file extension. A program must load an .shx file before using an AutoCAD font.

In the examples below, the pTextStyle variable stores a pointer to the text style record object.

Windows fonts

To work with Windows fonts, the text style requires a registered font name, character set, pitch and family identifier, and bold and italic attributes. The font name is a non-empty String value that corresponds to the name of a Windows font. The character set is an Integer value that corresponds to the number of the character set accessed for this font. The bold and italic attributes are Boolean values that influence the style of characters. When the attribute is set to True, a text is bold (or italic). When the attribute is set to False, a text is not bold (or not italic). These parameters are used for plotting text using Windows fonts.

When a text style uses a Windows font, use the font() method for getting information about the font. The font() method requires five arguments which simultaneously are the returned values — the reference to the variable in which the method must save the registered font name as an OdString value, the reference to the variable in which the method must save the bold font attribute as a Boolean value, the reference to the variable in which the method must save the italic font attribute as a Boolean value, the reference to the variable in which the method must save the character set number as an Integer value, and the reference to the variable in which the method must save pitch and the family identifier as an Integer value. The program must previously declare the corresponding variables before using the font() method. For example:


OdString typeface;
OdInt16 charset;
OdInt16 family;
bool bold;
bool italic;

pTextStyle->font(typeface, bold, italic, charset, family);

odPrintConsoleString(L"\nText Style = %s", pTextStyle->getName());
odPrintConsoleString(L"\nFont name = %s", typeface.c_str());
odPrintConsoleString(L"\nCharacter set = %d", charset);
odPrintConsoleString(L"\nPitch and Family = %d", family);
odPrintConsoleString(L"\nStyles: %s %s", ((bold) ? L"Bold" : L""), ((italic) ? L"Italic" : L""));

To set the Windows font, use the setFont() method that requires five arguments — the registered font name as an OdString value, bold attribute as a Boolean value, italic attribute as a Boolean value, character set number as an Integer value, and pitch and family identifier as an Integer value. The method does not return a value. For example:


OdString typeface = L"Arial";
OdInt16 charset = 0;
OdInt16 family = 34;
bool bold = true;
bool italic = false;

pTextStyle->setFont(typeface, bold, italic, charset, family);

AutoCAD fonts

To work with AutoCAD fonts, a text style requires the font filename that defines the shape of characters. AutoCAD fonts are subdivided into uni-fonts, big-fonts, and shape-libraries. Uni-fonts are used to draw typical text. Big-fonts are used to draw Asian-language text and special characters. Shape-libraries are used to draw shape entities. The uni-font format and big-font format are divided into separate .shx files. The shape-library has the same format that is uni-font file, but it also stores the definition of shapes. A text style defines how objects must work with the loaded .shx file.

The big-font file extends typical font files and has the ability to plot characters from different languages and specific characters. When a text entity draws a character, the system searches its shape in the usual uni-font file. If the character shape is not found in the typical uni-font file, the system searches the shape for this character in the big-font file. The big-font file can only have the SHX format. When the text style uses AutoCAD fonts, use the fileName() and setFileName() methods for working with uni-fonts and the bigFontFileName() and setBigFontFileName() methods for working with big-fonts.

To get the uni-font filename, use the fileName() method that does not have arguments and returns the name of the font file associated with this text style as an OdString value. For example:


OdString unifontfile = pTextStyle->fileName();
odPrintConsoleString(L"\nUni-Font filename = %s", unifontfile.c_str());

The bigFontFileName() method does not have arguments and returns the name of the big-font file associated with this text style as an OdString value. For example:


OdString bigfontfile = pTextStyle->bigFontFileName();
odPrintConsoleString(L"\nBig-Font filename = %s", bigfontfile.c_str());

To set the uni-font, use the setFileName() method that requires one argument — the name of the uni-font file as an OdString value — and does not return a value. For example:


pTextStyle->setFileName(L"complex.shx");

To set the big-font, use the setBigFontFileName() method that requires one argument — the name of the big-font file as an OdString value — and does not return a value. For example:


pTextStyle->setBigFontFileName(L"bigfont.shx");

Note: The text style record object stores and requires the uni-font filename and big-font filename without a path (only filename).

Shape status

The shape status determines whether the font file associated with a text style should be interpreted as a set of shapes or letters. The text style defines this property as a Boolean value which is True when the font file is a set of shapes or False when the font file is a set of letters. The value is False (Text) by default.

To check the shape status, use the isShapeFile() method; it does not have arguments and returns the status as a Boolean value. For example:


odPrintConsoleString(L"\nFont file is a set of %ls", (pTextStyle->isShapeFile()) ? L"shapes" : L"letters");

To switch the shape status, use the setIsShapeFile() method; it requires one argument — the shape status as a Boolean value — and does not return a value. For example:


// Set Shape
pTextStyle->setIsShapeFile(true);

// Set Text
pTextStyle->setIsShapeFile(false);

See Also

Working with Text Styles

Specific Properties of Text Styles

Example of Working with the Text Style Record Object

Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.