Font classes for supported Font Formats | API for .NET

Hierarchy of Aspose.Font classes

The hierarchy of Aspose.Font classes for supporting fonts of different formats is pretty simple.

Class Font is a single base class and any class, which supports some font format inherited from Font. There is common information for fonts of all formats gathered in this class. This information includes such data as font style, font name, postscript font name, font family, font metrics, the number of glyphs of the font, encoding, etc.

Class Font is an abstract class so the instance of the object of Aspose.Font.Font type, cannot be created directly. The reference on the just created object is returned by the static methods of this class that are responsible for the font loading that, family of overloaded methods Open().

As for the specific for one or another font format information, for providing such information are responsible objects inherited from base Aspose.Font.Font. The only data, specific for font format, which base Font class includes, is the value from FontType enumeration.

The next classes are inherited from Aspose.Font and used to work with specific font format: TtfFont, Type1Font, CffFont.

Interrelations between font format, FontType value and Aspose.Font object type

The table below shows the accordance between the formats, supported by Aspose.Font, the corresponding to these formats values from FontType enumeration, and classes used for manipulating each of these formats.

Font FormatFontType valueAspose.Font object type
TrueTypeTTFTtfFont
Type 1Type 1Type1Font
Compact Font Format (CFF)CFFCffFont

Interrelations between font file format, FontType value and Aspose.Font object type

The formats of the aforementioned fonts from FontType enumeration are wider terms than file formats for those fonts.

For example, TrueType format covers the following file formats available for loading with Aspose.Font: ttf, ttc, eot, woff, woff2. So the common feature for fonts with extensions .ttf, .ttc, .eot, .woff, .woff2 is that they are all related to TrueType font family.

That is why, if replacing in the table the column “Font Format” to the column “Font file format”, we will get the next table of relations between font file formats, fitting to them FontType values, and objects aimed to work with the corresponding font format in Aspose.Font.

Font file formatFontType valueAspose.Font object type
ttf, ttc, eot, woff, woff2TTFTtfFont
pfa, pfbType 1Type1Font
afm, pfmType 1Type1MetricFont
binary data of Compact Font Format typeCFFCffFont

Functionality of Aspose.Font.Font class

Functionality is defined by Font class can be divided into several areas.

Functionality defined by interfaces that Font class implements

The most important interface of the Font interfaces list is IFont interface. It provides properties for IGlyphAccessor and IFontSaver interfaces, that are implemented by Font class, so all the functionality, defined by interfaces which Font class implements is covered by this IFont interface.

Interface IFont defines properties that are common for all font formats supported by Aspose.Font. Below are the descriptions for each property.

Properties for manipulating font formats

Also, IFont interface defines method Convert(), which is used to convert font to another format. At the moment there are available conversions from any format supported by Aspose.Font for reading to TTF format. Supported font formats are represented in the table.

See Font converter for additional information on how to convert fonts with Aspose.Font.

Font loading

Font loading functionality is not covered by implemented interfaces and this functionality is represented by the family of static methods Open(). Parameters to pass into these methods are described in How to load fonts? article.

Font saving

Class Font implements interface IFontSaver, which declares functionality for font saving operations. To save a font use one of the overloaded methods Save() and pass the font file name or stream where to write the font.

In some cases there is a need to save a font into another format. For example, many web pages prefer working with fonts in WOFF format and if you want to place your font on such a page you will have to save the font into WOFF format. Method SaveToFormat() was designed for such cases.

Classes inherited from base Aspose.Font.Font class

CffFont and Type1Font classes

These classes are used to work with fonts of Compact Font Format and Adobe Type 1 font format respectively. These classes override certain properties and methods of Font class, adapting them for the actual font format.

TtfFont class

This class is designed to support fonts of TrueType format. A reference to an object of this type can be obtained by calling the static method Font.Open(), with passing TTF, as value for FontType enumeration. Method Font.Open() returns reference on base Font type, so the obtained reference has to be cast to TtfFont object type.

As known from the TrueType format specification, the font data is represented in different tables. At the moment Aspose.Font library supports following tables: head, cmap, glyf, loca, hhea, hmtx, maxp, OS/2, name, post, kern, cvt, fpgm, prep.

*The support for other tables specified by TrueType standard is planned to be implemented in the near future.

Support for TrueType tables in Aspose.Font implemented by classes from namespace Aspose.Font.TtfTables. Every class, which supports some table, has a name related to the corresponding table name. The naming of the class is fulfilled according to the next rule: the name of every class has the prefix Ttf, this prefix is followed by the name of the table and then the word “Table” ends the name of the class.

For example table head is supported by class TtfHeadTable, table hhea is supported by class TtfHheaTable, and so forth.

References on all classes which support TrueType tables are collected by the object of type TtfTableRepository.

TtfFont class gives the reference on the TtfTableRepository object as property TtfTables, so to get access to any TrueType table is possible by using syntax font.TtfTables, where font is the reference on TtfFont type.

Support for OpenType font features is represented by property CffFont. This property returns the reference on Font object, loaded from CFF table, which contains a Compact Font Format font representation.

Property IsSymbolic used to detect whether the font is symbolic - specialized font, that is composed of non-alphabetic characters, graphics, or both.

Access to font glyphs

Class TtfFont provides extended functionality to access font glyphs. In addition to methods, defined by interface IGlyphAccessor,
TtfFont provides two overloaded methods with the name GetGlyphById(), which require glyph identifiers in integer or string form.

Using these methods works faster than using method GetGlyphById() from IGlyphAccessor interface. Also, TtfFont class provides a set of overloaded methods GetGlyphComponentsById(). These methods are designed to work with composite glyphs.

Composite glyph is a glyph that references one or more other glyphs in the font. For example, the glyph for character Ä (Unicode U+00C4), can be composed of the glyph for character A (as the base glyph) and the diaeresis mark glyph.

Methods GetGlyphComponentsById() take the identifier of the composite glyph and return the list of glyphs the transferred composite glyph refers to.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.