Text and Font Questions

  1. FAQ

When I read some text from a dwg file (CAD 2000 version), I get some characters like "\M+5BFAA\M+5B9D8", but it should be the Chinese character "开关". This error appears when I use Java platform in Linux, on Windows it works well.

DWG file version CAD 2000 contents text string in multi byte coding. Higher dwg versions store text in unicode. So for conversion multi byte to unicode you need to initialize map by next way once during start your application - OdCharMapper.initialize("adinit.dat"). "adinit.dat" must be with full path place.

More detail information about font support you can find here (ODA login required).

There is a flag option with OdPdfExportEx that allows the use of embedded TTF fonts. Does this enable the PDF export to collect the fonts from the DWG file?

When the texts are exported into pdf, the TTF fonts can be exported two ways.

Just reference to the font, so pdf viewer should find this font in the system when open the pdf file.

Whole TTF font file is exported into pdf. This leads to increasing file size but pdf viewer will open the font from the pdf and render the text as it should be rendered - so there will be no portability problems.

Pdf export does not collect the fonts from the drawing at all, it collects them from the system. This flag makes pdf export to embed the whole font files into pdf file.

More info in  documentation about pdf export parameters.

What happens if the DWG file does not contain the font data?

If DWG file does not contain the font data, it does not contain the texts, so nothing will happen, there is nothing to export (regarding fonts of course).

How to export drawings in model space to a multy pages pdf by windows area, not layout because the drawings are with different frames?

There is no direct way to export different windows areas to different pages. But there are two other ways:

You can create several layouts in the drawing, put the viewports with necessary areas on these layouts, so you will be able to export each layout to different page of the pdf.

You can try PdfPublish to do that. With Publish you can export the drawing into pdf and then put the references on the drawing into several pages of your pdf or even into several places of the one page, and then apply the clipping on them (https://www.opendesign.com/blog/2018/december/publishing-2d-cad-objects).

What would happen if the font type used in the input file is not found during the conversion?

ODA Drawings SDK supports TTF and SHX fonts but ODA does not redistribute font files. If required font is not found by default built-in font similar to Simplex will be used. For details see Font Handling topic.

How to get shapes from text with SHX fonts

See /Drawing/Examples/ExCommands/ExTxtExp.cpp It's implementation of exploding shx text into lines and ellipses and TTF into triangles to outlines.

How to place a text object in center of a closed polyline? When I set center’s coordinates as the position of the text, the text is placed starting from this point to the right.

Use pText->setAlignmentPoint(OdGePoint3d(outlineCenter.x() , outlineCenter.y(), outlineCenter.z())) and set text alignment by next way

pText->setHorizontalMode(OdDb::TextHorzMode::kTextCenter );
pText->setVerticalMode(OdDb::TextVertMode::kTextVertMid) ;

Method adjustAlignment(); is called while text entity is closed but may be called directly after append in block

m_blockTableRecordPtr->appendOdDbEntity(pText); 
pText->adjustAlignment(NULL);

Why does Autodesk® AutoCAD® not display .otf fonts from a .dwg file created by ODA SDKs?

AutoCAD does not support .otf fonts and works with .ttf fonts only. ODA works correctly with both .otf and .ttf fonts.

Why is the output text from OdaMfcApp not the same as the output text from OdSvgExportEx?

The difference is caused by different algorithms for locating .shx fonts. You can set a breakpoint in OdaMfcApp::findFile() and see what is happening. The OdSvgExportEx sample does not try to find fonts in Autodesk® AutoCAD® folders.

How to extract all text data enclosed in a drawing's objects?

To learn how to extract text data, see the Text Data Extraction topic and the Drawing/Examples/OdExtractTextEx sample application.

How to delete a text style?

A text style can be deleted using:

styleId.safeOpenObject(OdDb::kForWrite)->erase(true);

Note: "Standard" and current text styles cannot be deleted.

How to set single-line text upside-down?

See the following OdDbText class methods: setRotation(), mirrorInX(), mirrorInY().

Can MText text format codes be stripped from MText objects?

Yes, they can. Use the OdDbMText::explodeFragments() method and these next members in the OdDbMTextFragment structure:

int changeStyle; 	// 0 == No change; 1 == Change to original; 2 == Change to other
bool lineBreak; 	// Text is followed by a line break.
bool newParagraph; 	// Text fragment starts a new paragraph.

How to explode a text entity into polylines?

You can find the implementation of the TextContourExplode commands which explode both .shx and .ttf text into polylines in the Drawing/Examples/ExCustObjs/DrxDebugCmds.cpp file.

Why does Japanese text look garbled when opening in TrueView if the code page is set to CP_ANSI_932?

You need to set the correct Unicode text to your text entity. For example:

char* txt = ""; // Some multi-byte Japanese text in CP_ANSI_932
   OdAnsiString mbStr(txt, CP_ANSI_932);
   OdString unicodeStr(mbStr);
   OdDbTextPtr textEnt; // Some database text entity
   textEnt->setTextString(unicodeStr);

While saving, drawing text content will be decoded automatically in a suitable format by ODA.

How to return Unicode values for special symbols when the OdDbMText object is exploded into MTextFragments?

The OdDbMTextFragment structure has the OdString text member which contains Unicode characters.

Why does multi-line text look different after exploding on Windows® and non-Windows platforms?

You need the same fonts on different platforms for getting the same result. Some fonts cannot be available in both non-Windows and Windows platforms. In this case the unavailable font is substituted by the available one and you can get a separate text entity for each phrase, word or even symbol. If the font that is used in the multi-line text is available on your computer, it will be applied to all symbols and you get one text entity. See the Font Handling topic in the Developer's Guide.

How to obtain the font name and size of an OdDbText object?

Use the OdDbTextStyleTableRecord::font() method for getting the characteristics such as typeface, bold, italic, charset, pitch_and_family of the Windows font associated with the text style.

If the font() method returns an empty typeface, use the OdDbTextStyleTableRecord::fileName() method. This method returns the name of the uni-font file associated with this text style. Text size is a property of the OdDbText entity and the height() method returns its value. For more details, see the Font Handling topic in the Developer's Guide.

Why are Kanji characters displayed incorrectly after reading a .dxf file on macOS?

At run-time and in the latest .dwg versions, text is stored in Unicode. Older versions store text as MBCS. To convert text to Unicode it is necessary to know a code page, which is stored in the .dwg/.dxf file. But very old versions (or .dxf files generated by some applications) may have no code page information. In this case a default system code page is used. Implementation of the systemCodePage can be found in the Kernel/Extensions/ExServices/ExSystemServices.cpp file.

Loading such a file can be different depending on the computer's language settings. On non-Windows platforms, the OdCharMapper should be initialized with the adinit.dat file containing text conversion tables for MBCS code pages. The file resides in the /Kernel folder. Also, see the Drawing/Examples/OdReadEx/OdReadEx.cpp file.

Why is a font that is used in a .dwg file displayed incorrectly?

The font might not be available for the application that is displaying the drawing. Here is a list of possible ways to resolve this issue:

OdString fontFile = pHostApp->findFile(L"fontFileName.ttf"); // Or use the full path name
OdTtfDescriptor descr;
pHostApp->ttfFileNameByDescriptor(descr, fontFile);
  1. Put the font file in the same folder as the drawing. Be sure that the font contains the needed characters.
  2. If the drawing is placed in another folder than the application, use the ACAD environment variable for setting the folder with the needed font or use the application's findFile() method to specify where the font file is located:

Detailed information about font handling can be found here: https://docs.opendesign.com/td/FontHandling.html

Why do text objects in a .dxf file have incorrect alignment when the file is opened by the OdaMfcApp application?

ODA SDK does not recalculate the text position for text entities when loading a .dxf file because this recalculation can corrupt the position during round-tripping if the referenced font is not available. Client applications based on ODA SDKs version 3.5 or higher can override this default behavior by calling the OdDbHostAppServices::setDxfTextAdjustAlignment(true); method.

Why are gdt symbols in a .dwg file that is created in an application other than an Autodesk® AutoCAD® package displayed incorrectly?

Not all gdt symbols are present in other fonts. To display the symbols correctly, you need the correct font with the same encoding. Thus there is no need to convert character codes. For example, to display Cyrillic characters you should use a Cyrillic font, but no recording is required.

To see all characters in a TTF font on Microsoft® Windows®, you can use the Windows Character Map.

Detailed information about font handling can be found in the Developer's Guide, Font Handling topic.

Why does text containing only Chinese characters have the wrong height and width?

Not all fonts have Chinese symbols. In this case Teigha substitutes another font instead of the font used in a drawing, but it is not the same. Note that you can get a different result with Autodesk® AutoCAD® and a one text entity may use different fonts.

What font is used in ODA SDK by default?

ODA SDK contains two built-in default SHX fonts, a simple font similar to txt.shx and a gdt font. The detailed information about font support can be found in the Font Handling topic in the Developer's Guide.

How to set text to "underline", "overline" and "strikeout"?

You can find special codes for managing OdDbText entity properties such as "underline" and "overline" in the Single-Line Text Special Codes and Unicode Symbols topic of the Developer's Guide. For OdDbMText special codes, see the Multi-Line Text Format Codes topic.

Does ODA SDK provide an alternative .shx file with the same character set as Autodesk® AutoCAD® provides with the simplex.shx file?

ODA SDK does not provide any extra font files. There is a built-in font similar to simplex.shx with minimal symbols (Latin and digits).