org.foray.font.config
Class RegisteredFont

java.lang.Object
  extended by org.foray.font.config.RegisteredFont
All Implemented Interfaces:
FontParserClient

public class RegisteredFont
extends Object
implements FontParserClient

Class representing a font that has been registered for use with FOray. RegisteredFont is not really a Font, as it is not part of the Font hierarcy (i.e. it does not subclass Font). It is really the bridge between the font configuration and the actual Font classes. It first encapsulates the information from the "font" element in the font-configuration. During font resolution, a RegisteredFontDesc element (representing a "font-description" element in font-configuration) is selected, which in turn points to RegisteredFont instance. It then, as requested, converts that information into actual Font instances that can be used by the client application.

It is tempting to question why this separate class is needed. Because fonts can be registered from several sources (hard-coded, font configuration, operating system registration, and directly by the client application), a separate registry concept ensures that all of the registered fonts can be managed, even though they may not have been parsed yet. It is good to not parse the font until it is known to be necessary. Note that the data stored in RegisteredFont corresponds to the data passed in the <font> element of the font configuration file. Data from the actual font file itself tends to be stored in FreeStandingFont or one of its subclasses.


Field Summary
static String[] STANDARD_PDF_FONT_NAMES
          Array of the base-14 font names.
 
Constructor Summary
RegisteredFont(FontServer4a server, String fontName, DataSource fontFileSource, DataSource metricsFileSource, String ttcName, org.axsl.font.Font.Embedding embedding, String systemName)
          Constructor useful for registering a Font that has not yet been read.
RegisteredFont(FontServer4a server, String fontID, String fontFileDescription, byte[] fontFileContents, String metricsFileDescription, byte[] metricsFileContents, String collectionID, org.axsl.font.Font.Embedding embedding, String systemName)
          Constructor useful for registering a font whose contents have been extracted from a document.
 
Method Summary
 FontParser createFontFileReader()
          Creates a font file reader for this registered font.
 Type1MetricsParser createMetricsFileReader()
          Creates a metrics file reader for this registered font.
 Font4a getBestFont()
          Returns the FreeStandingFont linked to this registered font, if it exists, or the System font if no FreeStandingFont exists.
 String getConfiguredFontName()
          Returns the configured font name.
 FontServer4a getFontServer()
          Returns the parent font server.
 FreeStandingFont getFreeStandingFont()
          Returns the FreeStandingFont manifestation of this font.
 org.apache.commons.logging.Log getLogger()
          Returns the logger.
 Panose getPanose()
          Returns the Panose instance, if any, that should be used to evaluate this font description.
 org.axsl.ps.PsServer getPsServer()
          Returns the PostScript server, which is used to make instances of certain classes needed for parsing.
 URL getSerializedMetricsFile()
          Returns the serialized metrics file.
 SystemFont getSystemFont()
          Returns the SystemFont manifestation of this font.
 String getSystemName()
          Returns the system name for this registerered font.
 String getTTCName()
          Return the registered TrueType collection name that should be used to access this font within a TTC file.
 boolean hasFontContent()
          Indicates whether this can return the content of the font.
 boolean hasFreeStandingFont()
          Indicates whether a FreeStandingFont manifestation of this registered font exists.
 boolean hasSystemFont()
          Indicates whether a SystemFont manifestation of this registered font exists.
 boolean isEmbedding()
          Indicates whether this font should be embedded.
 boolean isSubsetting()
          Indicates whether this font should be subsetted.
protected  void setSerializedMetricsFile(URL serializedMetricsFile)
          Sets the serialized metrics file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDARD_PDF_FONT_NAMES

public static final String[] STANDARD_PDF_FONT_NAMES
Array of the base-14 font names.

Constructor Detail

RegisteredFont

public RegisteredFont(FontServer4a server,
                      String fontName,
                      DataSource fontFileSource,
                      DataSource metricsFileSource,
                      String ttcName,
                      org.axsl.font.Font.Embedding embedding,
                      String systemName)
               throws org.axsl.font.FontException
Constructor useful for registering a Font that has not yet been read.

Parameters:
server - The parent font server.
fontName - The name of the font.
fontFileSource - The source of the font file, if any.
metricsFileSource - The source of the metrics file, if any.
ttcName - The font name to be used within a TrueType Collection file to select the proper font.
embedding - Indicates whether and how much of the font should be embedded.
systemName - A non-null value indicates that this font can manifest itself as a SystemFont.
Throws:
org.axsl.font.FontException - For an error during font registration.

RegisteredFont

public RegisteredFont(FontServer4a server,
                      String fontID,
                      String fontFileDescription,
                      byte[] fontFileContents,
                      String metricsFileDescription,
                      byte[] metricsFileContents,
                      String collectionID,
                      org.axsl.font.Font.Embedding embedding,
                      String systemName)
               throws org.axsl.font.FontException
Constructor useful for registering a font whose contents have been extracted from a document.

Parameters:
server - The parent font server.
fontID - A unique ID for this font (e.g. "Courier-Bold").
fontFileDescription - A description of the font file. This is used primarily in user messages.
fontFileContents - Byte array containing the font file contents.
metricsFileDescription - A description of the metrics file. This is used primarily in user messages.
metricsFileContents - Byte array containing the metrics contents. This is always null for TrueType and OpenType fonts.
collectionID - For TrueType collections, indicates which font in the collection corresponds to this font.
embedding - One of "none", "all", or "subset", indicating whether this font should be embedded in output documents.
systemName - For system fonts only, this is the name that should be supplied to the operating system font registry to obtain the font from it. For other fonts, set this to null.
Throws:
org.axsl.font.FontException - If a font with this fontID is already registered.
Method Detail

createFontFileReader

public FontParser createFontFileReader()
                                throws org.axsl.font.FontException
Creates a font file reader for this registered font.

Returns:
The reader.
Throws:
org.axsl.font.FontException - For errors opening the font file reader.

createMetricsFileReader

public Type1MetricsParser createMetricsFileReader()
                                           throws org.axsl.font.FontException
Creates a metrics file reader for this registered font.

Returns:
The reader.
Throws:
org.axsl.font.FontException - For errors opening the metrics file reader.

getFreeStandingFont

public FreeStandingFont getFreeStandingFont()
Returns the FreeStandingFont manifestation of this font.

Returns:
The FreeStandingFont manifestation, if any, of this RegisteredFont.

getSystemFont

public SystemFont getSystemFont()
Returns the SystemFont manifestation of this font.

Returns:
The SystemFont manifestation, if any, of this RegisteredFont.

getSystemName

public String getSystemName()
Returns the system name for this registerered font.

Returns:
The "system-name" as configured by the user. This is the name of the AWT font (not font-family) that can be created.

getTTCName

public String getTTCName()
Return the registered TrueType collection name that should be used to access this font within a TTC file.

Returns:
The TTC name.

getFontServer

public FontServer4a getFontServer()
Returns the parent font server.

Returns:
The parent font server.

getLogger

public org.apache.commons.logging.Log getLogger()
Returns the logger.

Specified by:
getLogger in interface FontParserClient
Returns:
The logger.

getConfiguredFontName

public String getConfiguredFontName()
Returns the configured font name.

Returns:
Returns the configuredFontName.

isEmbedding

public boolean isEmbedding()
Indicates whether this font should be embedded.

Returns:
Returns the embedding.

isSubsetting

public boolean isSubsetting()
Indicates whether this font should be subsetted.

Returns:
Returns the subsetting.

hasFontContent

public boolean hasFontContent()
Indicates whether this can return the content of the font.

Returns:
True if and only if, this can return the content of the font.

hasFreeStandingFont

public boolean hasFreeStandingFont()
Indicates whether a FreeStandingFont manifestation of this registered font exists.

Returns:
True iff a FreeStandingFont manifestation of this registered font exists.

hasSystemFont

public boolean hasSystemFont()
Indicates whether a SystemFont manifestation of this registered font exists.

Returns:
True iff a SystemFont manifestation of this registered font exists.

getPanose

public Panose getPanose()
Returns the Panose instance, if any, that should be used to evaluate this font description.

Returns:
The Panose value for this instance.

getSerializedMetricsFile

public URL getSerializedMetricsFile()
Returns the serialized metrics file.

Returns:
The serialized metrics file, or null if the there is no metrics file or if the metrics file is not serialized.

setSerializedMetricsFile

protected void setSerializedMetricsFile(URL serializedMetricsFile)
Sets the serialized metrics file.

Parameters:
serializedMetricsFile - The new serialized metrics file.

getBestFont

public Font4a getBestFont()
Returns the FreeStandingFont linked to this registered font, if it exists, or the System font if no FreeStandingFont exists.

Returns:
The best font associated with this registered font.

getPsServer

public org.axsl.ps.PsServer getPsServer()
Description copied from interface: FontParserClient
Returns the PostScript server, which is used to make instances of certain classes needed for parsing.

Specified by:
getPsServer in interface FontParserClient
Returns:
The PostScript server.


Copyright © 2017. All rights reserved.