Close

Relief for ODA Team in Ukraine

Learn more
ODA PRC SDK
Usage of Fonts

Usage of Fonts: Introduction

Some PRC entities can include text information (for example, markup entities), therefore ODA PRC SDK requires access to particular font files in order to render text and calculate text extents correctly.

The best way to render is to use the same fonts that were originally used by the author of the .prc file. This means that the client operating system must have those fonts installed.

If a particular font cannot be found, ODA PRC SDK tries to substitute the missing font with a default font. This may cause the text to look different than when rendered with the original font (for example, due to different character dimensions).

Supported Font Types

ODA PRC SDK supports two types of fonts:

  • TrueType fonts
  • PostScript Fonts

TrueType and PostScript fonts can be represented with a file name (for example, «Arial.ttf» or «MyriadPro-Regular.otf») or with a typeface name (for example, «Times New Roman» or «Myriad CAD»).

The processing of True Type and PostScript fonts differs depending on the platform. For Windows platforms, native Windows API functions are used; for non-Windows platforms, the FreeType library is used (TD_XXXX_Freetype.*).

SHX fonts can be used for text rendering when appropriate fonts are not found, but SHX fonts can not be used for PRC text. SHX fonts (both regular SHX fonts and big fonts) are represented with a file name (for example, «simple.shx»).

Default ODA PRC SDK Fonts

The most common causes for incorrect text rendering and extents calculating is a missing font file. In such cases, ODA PRC SDK substitutes the missing font with a new font, but this causes vectorization and extents differences, for example, because of different character dimensions for applied and missing fonts.

ODA PRC SDK requires two PostScript fonts to be installed which will be used as default substitute fonts:

  • MyriadPro-Regular.otf (typeface name «Myriad Pro»)
  • MyriadCAD.otf (typeface name «Myriad CAD»)

If Myriad Pro and Myriad CAD fonts are not available, «simple.shx» font is used.

Default Font Searching Implementation

Font Handling routines are implemented in the OdPrcHostAppServices class. The following table describes the methods of the OdPrcHostAppServices classes used for font searching.

Method Description
getPreferableFont() Defines a preferable font name to search for by specifying a specified font name and type. The method takes two parameters:
  • Font name
  • Font type
Default implementation returns an empty string.
findFile() Searches and loads a font file. The method takes three parameters, but for the font file searching functionality it is enough to specify only the first one (file name).

To use a different search algorithm than the default implementation, re-implement this method.

getSubstituteFont() Allows a client custom application to substitute one font with another font before the fonts are used. The method takes two parameters:
  • Font name to be substituted
  • Substituted font type
Default implementation returns the result of the getAlternateFontName() method.
getAlternateFontName() Returns the string «MyriadPro-Regular.otf» (default implementation).
getSubstituteFontByChar() Searches for a specified symbol in a specified font. The method takes three parameters:
  • A font object (default implementation doesn't use it)
  • A char to find
  • A pointer to the database
Default implementation tries to load the font file «MyriadCAD.otf». If the font file is successfully loaded, searches the specified symbol in the font. If the symbol is found, returns typeface «Myriad CAD»; in the other case returns an empty string.
ttfFileNameByDescriptor() Searches for a font file specified by a typeface. The method takes two parameters:
  • A font typeface string.
  • A reference to a string object for storing the returned font file name.

The OdPrcHostAppServices class contains TrueType/PostScript font mapping, which is useful for non-Windows platforms.
The getSystemFontFolders() and collectFilePathsInDirectory() methods are called by the default implementation of the ttfFileNameByDescriptor() method.

The default algorithm for searching and loading a font file is represented in the schema below.


      Call getPreferableFont()

      If getPreferableFont() method returns a substitute font name
      .
      .  Call findFile() method with returned font name
      .  .
      .  .  Search the font file as is
      .  .  .
      .  .  If the font file is found
      .  .  . 
      .  .  .  Return the full path to the font file
      .  .  .
      .  .  Else 
      .  .  .  Search the font file in the current directory
      .  .  .
      .  .  .  If the font file is found
      .  .  .  .
      .  .  .  .  Return the full path to the font file
      .  .  .  .
      .  .  .  Else
      .  .  .
      .  .  .  .  Search the font file in the directory where the current .prc file is allocated
      .  .  .  .  .
      .  .  .  .  If the font file is found
      .  .  .  .  .
      .  .  .  .  .  Return the full path to the font file
      .  .  .  .  .
      .  .  .  .  Else
      .  .  .  .  .  If the font is a TrueType or a PostScript font and the platform is Windows
      .  .  .  .  .  .
      .  .  .  .  .  .  Search for the font file in the Window directory
      .  .  .  .  .  .
      .  .  .  .  .  .  If the font file is found 
      .  .  .  .  .  .  .
      .  .  .  .  .  .  .  Return the full path to the font file
      .  .  .  .  .  .  .
      .  .  .  .  .  .  ...
      .  .  .  .  .  ...
      .  .  .  .  .  
      .  .  .  .  .  Return an empty string
      .  .  .  .  ...
      .  .  .  ...
      .  .  ...
      .  ...
      ...

      If getPreferableFont() does not return a substitute name or findFile() returns an empty string
      
      .  If font typeface is available
      .  .
      .  .  Call ttfFileNameByDescriptor() to determine the font file name to be the typeface. 
      .  .
      .  .  If file name is determined
      .  .  .
      .  .  .  Creates a map entry for the typeface and font file. 
      .  .  .
      .  .  .  Call findFile() to get the font file full path.
      .  .  ...
      .  .  
      .  .  If font file name is not determined or findFile returns an empty string
      .  .  .
      .  .  .  If the platform is Windows
      .  .  .  .
      .  .  .  .  Create a Windows font without a font file name.
      .  .  .  ...
      .  .  ...
      .  ...
      .  
      .  If font typeface is not available or font file is not located for a current typeface
      .  .
      .  .  Call substituteFont() method
      .  .  
      .  .  If substituteFont() method returns an empty string 
      .  .  .
      .  .  .  ODA PRC SDK uses "simple.shx" font
      .  .  ...
      .  .
      .  ...
      ...

    

See Also

Work with .prc Files and File Structures

Get Started with ODA PRC SDK

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