A text entity stores content as a string, which is a sequence of letters represented by integer codes. The appearance of a letter is defined by a font which either is stored in a .shx font file or in a Microsoft® Windows® system font file. Font files store the definition of letters as the sequence of linear and circular segments, which defines the letter appearance. The definition encodes these segments in a binary format using relative coordinates for each letter. Each letter is drawn using a displacement method in the object coordinate system of a text entity. The binary format associates an 8-bit or 16-bit integer unique code with each letter definition. When the platform gets a code from the text content, it knows how to get the letter geometry to be drawn.
Letter definitions are not immediately accessed. To access the letters, the program must create a text style record object and must associate it with a .shx font file or Windows system font file. The shape status of this text style must be set to False to be interpreted as a set of letters. To plot text, the program must associate the text entity with a text style record object. In the following examples, the pText variable stores a pointer to the single-line text object or multi-line text object.
The property defines the text style that either is associated with a Windows font or a .shx font file. The property stores the ID of the text style record object which stores the settings of the font to be drawn and with which the text entity is associated. The text style property is associated with the "Standard" text style by default.
To get the text style, use the textStyle() method which does not have arguments and returns the OdDbObjectId instance associated with the text style record object. Then, use the safeOpenObject() method to obtain a smart pointer to this text style. For example:
OdDbObjectId idStyle = pText->textStyle();
if(!idStyle.isNull())
{
OdDbTextStyleTableRecordPtr pStyle = idStyle.safeOpenObject();
odPrintConsoleString(L"\nText style = %x - \"%s\"", idStyle.getHandle().ascii().c_str(),
pStyle->getName().c_str());
}
To set the text style, use the setTextStyle() method which requires an ID of the text style record object as the OdDbObjectId instance and does not return a value. The specified object ID must not be OdDb::kNull. To get the text style ID, use the getTextStyleTableId() method of the database object to obtain the ID of the text style table object, and then use the getAt() method to obtain ID of the text style record object. For example:
OdDbTextStyleTablePtr pTextStyles = pText->database()->getTextStyleTableId().safeOpenObject();
OdDbObjectId idStyle = pTextStyles->getAt(L"MyStyle");
if(!idStyle.isNull()) pText->setTextStyle( idStyle );
To associate a text style with a .shx file, get the text style table object using the getTextStyleTableId() method and safeOpenObject() method for write mode, and save the returned smart pointer to it in the declared variable. Next, create the text style record object using its static pseudo-constructor — the createObject() method — and save the returned smart pointer to it in the declared variable. Next, assign the name for the new text style using the setName() method, and set its shape status to False. Next, specify the .shx file name without a path, and add the text style record object to the text style table object using the add() method. Afterwards, the obtained ID can be set for the text entity using the setTextStyle() method. For example:
OdDbTextStyleTablePtr pTextStyles = pText->database()->getTextStyleTableId().safeOpenObject(OdDb::kForWrite);
OdDbTextStyleTableRecordPtr pTextStyle = OdDbTextStyleTableRecord::createObject();
try {
pTextStyle->setName(L"Times");
pTextStyle->setIsShapeFile(false);
pTextStyle->setFileName(L"times.shx");
pTextStyles->add(pTextStyle);
pText->setTextStyle( pTextStyle->objectId() );
}
catch(OdError& e)
{
odPrintConsoleString(L"\nError: %d -- %s\n", e.code(), e.description());
}
Note: If a program changes the text style of a text entity or .shx file of a text style, the text appearance changes.
Single-line and multi-line text can be horizontal or vertical. By default, text has a horizontal orientation. To change text orientation to vertical, the associated font must support dual orientation. In vertical orientation, each new text line is drawn to the right of the preceding line. Normally in each line the direction of vertical text runs from top to bottom as shown in the figure below.
Note: Vertical orientation is not supported for TrueType fonts and symbols.
To set and get the text orientation use the setIsVertical() and isVertical() methods of the OdDbTextStyleTableRecord class. The setIsVertical() method has one input boolean argument. If the value of this argument is true, the text will have a vertical orientation. If the value is false, the orientation will be horizontal. The isVertical() method returns a boolean value, which indicates whether the text is vertical (true value) or horizontal (false value).
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|