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
The only data, specific for font format, which base Font class includes, is the value from FontType enumeration.
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|
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.
TrueType format covers the following file formats available for loading with com.aspose.font:
woff2. So the common feature for fonts with extensions
.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|
|binary data of
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
- string FontName - the name of the font.
- MultiLanguageString FontNames - name of the font in different languages.
- MultiLanguageString PostscriptNames - postscript name of the font, in different languages.
- string FontFamily - the name of the font family. To get more details about font families see Font family charpter.
- FontType FontType - type of font format, represented by FontType enumeration.
- FontStyle FontStyle - font style value from FontStyle class. Learn more information about font styles.
- string Style - the name of the font style, similar to property FontStyle, represented in its raw string form, provided by font data.
- FontDefinition FontDefinition - an object that describes the format and the source to load font from. Go to How to load fonts where you can learn in detail how to work with this object.
- int NumGlyphs - gets number of glyphs of the font.
- IFontMetrics Metrics - gets a reference on IFontMetrics interface which provides functionality related to common font metrics.
- IFontEncoding Encoding- gets a reference on IFontEncoding interface, which provides encoding functionality.
- IGlyphAccessor GlyphAccessor - gets a reference on IGlyphAccessor interface, which provides functionality to retrieve specified glyph identifiers and glyphs.
- IFontSaver FontSaver - provides a font saving functionality with IFontSaver interface.
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 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.
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
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.
This class is designed to support fonts of
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:
*The support for other tables specified by
TrueType standard is planned to be implemented in the near future.
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.
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 is the reference on
OpenType font features is represented by property CffFont. This property returns the reference on Font object,
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.