Aspose.Font classes for supported font formats | Java

Hierarchy of com.aspose.font classes

The hierarchy of classes of com.aspose.font package that are aimed to support 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 com.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 com.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 com.aspose.font.Font and used to work with specific font format: TtfFont, Type1Font, CffFont.

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

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

Font Format FontType value com.aspose.font object type
TrueType TTF TtfFont
Type 1 Type 1 Type1Font
Compact Font Format (CFF) CFF CffFont

Interrelations between font file format, FontType value and com.aspose.font.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 com.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 com.aspose.font.

Font file format FontType value com.aspose.font object type
ttf, ttc, eot, woff, woff2 TTF TtfFont
pfa, pfb Type 1 Type1Font
afm, pfm Type 1 Type1MetricFont
binary data of Compact Font Format type CFF CffFont

Functionality of com.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 com.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 com.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, with passing TTF, as value for FontType enumeration. Method 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 class TtfTableBase. 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.