org.foray.font
Class FontServer4a

java.lang.Object
  extended by org.foray.font.FontServer4a
All Implemented Interfaces:
org.axsl.font.FontServer, FontParserClient

public class FontServer4a
extends Object
implements org.axsl.font.FontServer, FontParserClient

An implementation of the aXSL FontServer interface. It is designed to be a singleton, but is not required to be so.


Field Summary
 
Fields inherited from interface org.axsl.font.FontServer
OBLIQUE_SIMULATION_INVALID, SMALL_CAP_SIMULATION_INVALID, SMALL_CAP_SIMULATION_NATIVE, STRETCH_SIMULATION_INVALID
 
Constructor Summary
FontServer4a()
          Zero-argument constructor used for resource discovery purposes.
FontServer4a(org.apache.commons.logging.Log logger, org.axsl.ps.PsServer psServer)
          Constructor.
 
Method Summary
 boolean fontOutputFactoryAvailable(String mimeType)
          Reports on the availability of FontOutputFactory4a instances by mime-type.
 List<org.axsl.font.Font> getAllFonts(boolean freeStandingFonts, boolean systemFonts)
           
 URL getBaseFontURL()
          Returns the base URL used for finding font files.
protected  URL getBaseURL()
          Returns the base general URL.
protected  RegisteredFontDesc getDefaultFont(boolean freeStandingFont)
          Finds a default registered font.
 RegisteredFontDesc getDefaultFreeStandingFont()
          Returns the fallback free-standing font when no other font can be used.
protected  RegisteredFontDesc getDefaultSystemFont()
          Returns the fallback system font when no other font can be used.
 org.axsl.ps.Encoding getEncoding(String name)
           
 EntityResolver getEntityResolver()
          Returns the EntityResolver for this server.
 String getFontFamilyForAlias(String alias)
           
protected  Graphics2D getGraphics2D()
          Returns a graphics environment.
 org.apache.commons.logging.Log getLogger()
          Returns the logger that should be used as the system logger.
 FontOutputFactory4a getOutputFactory(String mimeType)
          Returns the output factory for a given mime type.
 org.axsl.ps.PsServer getPsServer()
          Returns the PostScript server.
 RegisteredFont getRegisteredFont(String name)
          Returns the font registered to a given name.
 RegisteredFontFamily getRegisteredFontFamily(String fontFamilyName)
          Returns a named registered font family.
 List<String> getSystemFontFamilyList()
           
 List<Font> getSystemFontList()
           
 boolean isRegisteredFont(String fontID)
           
 boolean isRegisteredFontFamily(String name)
           
 boolean isRegisteredFontFamilyAlias(String alias)
          Indicates whether a given String has been registered as a font-family alias.
 FontConsumer4a makeFontConsumer()
           
 FontSelector makeFontSelector(FontConsumer4a consumer)
          Returns the font-selector that should be used by a given font consumer.
 Collection<RegisteredFontFamily> registeredFontFamilies()
          Returns the collection of registered font-family instances.
 void registerFont(String fontID, DataSource fontFileSource, DataSource metricsFileSource, String collectionID, org.axsl.font.Font.Embedding requestedEmbedding, String systemName)
           
 void registerFont(String fontID, RegisteredFont rf)
          Maps a given font name to its related RegisteredFont instance.
 void registerFontDescription(String fontFamily, String fontID, org.axsl.ps.Encoding encoding, org.axsl.font.Font.Style style, org.axsl.font.Font.Weight weight, org.axsl.font.Font.Variant variant, org.axsl.font.Font.Stretch stretch, float simulatedSmallCaps, float simulatedOblique, float simulatedBackslant, float[] simulatedStretch)
           
 void registerFontFamily(String name)
           
 RegisteredFontFamily registerFontFamily2(String name)
          Add a RegisteredFontFamily to the Collection.
 void registerFontFamilyAlias(String alias, String realFamily)
          Add an alias to a RegisteredFontFamily.
 void registerFontOutputFactory(FontOutputFactory4a factory)
          Registers a FontOutputFactory4a for use by this server.
 void registerFontSelectorFactory(String name, FontSelectorFactory factory)
          Register a FontSelectorFactory for use in the font system.
protected  void registerStandardOutputFactories()
          Registers each of the standard output factories.
 void setBaseFontURL(URL url)
          Set the base URL for Font locations, unless it has already been set.
 void setBaseURL(URL url)
          Set the base URL for general resources, unless it has already been set.
 void setEntityResolver(EntityResolver entityResolver)
          Sets the EntityResolver for this server.
 void setFatalConfigurationError(boolean hasError)
          Use this method to indicate that a configuration error has occurred which cannot be recovered.
 void setup(InputStream fontConfigFile, Map<String,String> fontConfigOptions)
          Registers the FreeStanding fonts that are available based on font configuration file and options.
 void setUsingFreeStandingFonts(boolean using)
          Set parameter determining whether FreeStanding fonts will be setup.
 void setUsingSystemFonts(boolean using)
          Set parameter determining whether System fonts will be setup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FontServer4a

public FontServer4a(org.apache.commons.logging.Log logger,
                    org.axsl.ps.PsServer psServer)
Constructor.

Parameters:
logger - The Logger to be used for system-level messages. Please note that the FontConsumer also has a method for obtaining a Logger instance. These two instances can be the same, or, if desired, system-level messages can be logged to the FontServer logger, and messages that are more client-related can be logged to the FontConsumer logger.
psServer - The PostScript server.

FontServer4a

public FontServer4a()
Zero-argument constructor used for resource discovery purposes. This constructor is used primarily for utility and testing purposes. Use of it is somewhat more risky than using the standard constructor FontServer4a(Log, PsServer).

Method Detail

registerStandardOutputFactories

protected void registerStandardOutputFactories()
                                        throws org.axsl.font.FontException
Registers each of the standard output factories.

Throws:
org.axsl.font.FontException - For an invalid factory.

getRegisteredFontFamily

public RegisteredFontFamily getRegisteredFontFamily(String fontFamilyName)
Returns a named registered font family.

Parameters:
fontFamilyName - The font family being sought.
Returns:
The registered font family instance, or null if neither the family is found nor an alias.

getDefaultFreeStandingFont

public RegisteredFontDesc getDefaultFreeStandingFont()
Returns the fallback free-standing font when no other font can be used.

Returns:
The fallback free-standing font.

getDefaultSystemFont

protected RegisteredFontDesc getDefaultSystemFont()
Returns the fallback system font when no other font can be used.

Returns:
The fallback system font.

getDefaultFont

protected RegisteredFontDesc getDefaultFont(boolean freeStandingFont)
Finds a default registered font.

Parameters:
freeStandingFont - Indicates whether free-standing fonts should be sought or system fonts (mutually exclusive).
Returns:
A default registered font description.

setBaseURL

public void setBaseURL(URL url)
Set the base URL for general resources, unless it has already been set.

Parameters:
url - The base URL for general resources.

getBaseURL

protected URL getBaseURL()
Returns the base general URL.

Returns:
The base general URL.

setBaseFontURL

public void setBaseFontURL(URL url)
Set the base URL for Font locations, unless it has already been set.

Parameters:
url - The base URL for fonts.

getBaseFontURL

public URL getBaseFontURL()
Returns the base URL used for finding font files.

Returns:
The base URL used for finding font files.

setup

public void setup(InputStream fontConfigFile,
                  Map<String,String> fontConfigOptions)
           throws org.axsl.font.FontException
Registers the FreeStanding fonts that are available based on font configuration file and options.

Parameters:
fontConfigFile - The URL for the font configuration file that should be used during setup.
fontConfigOptions - An optional Map of font configuration options. Implementations that do not wish to use this should simply ignore it. Clients that do not wish to use it should pass null. This can be used for any purpose, but is intended primarily to allow an implementation to allow keys to be embedded in font configuration files, and then to replace those keys with the mapped value during parsing.
Throws:
org.axsl.font.FontException - on font configuration error.

getGraphics2D

protected Graphics2D getGraphics2D()
Returns a graphics environment.

Returns:
A graphics environment.

registerFontFamily2

public RegisteredFontFamily registerFontFamily2(String name)
                                         throws org.axsl.font.FontException
Add a RegisteredFontFamily to the Collection.

Parameters:
name - the name of the font family (e.g. "Courier")
Returns:
The registered font family instance.
Throws:
org.axsl.font.FontException - If the font-family is already registered.

registerFontFamilyAlias

public void registerFontFamilyAlias(String alias,
                                    String realFamily)
                             throws org.axsl.font.FontException
Add an alias to a RegisteredFontFamily.

Specified by:
registerFontFamilyAlias in interface org.axsl.font.FontServer
Parameters:
alias - The name of the font family alias (e.g. "sans-serif").
realFamily - The name of the real font family to which this alias should be associated (e.g. "Helvetica").
Throws:
org.axsl.font.FontException - If the realFamily does not exist, or if the alias is already registered to another font-family.

getLogger

public org.apache.commons.logging.Log getLogger()
Returns the logger that should be used as the system logger. Note that each FontConsumer instance can set up its own logger as well. This default logger will be used only for system-wide messages, and in cases where the FontConsumer instance does not have a logger.

Specified by:
getLogger in interface FontParserClient
Returns:
The logger that should be used as a default logger.

setUsingFreeStandingFonts

public void setUsingFreeStandingFonts(boolean using)
Set parameter determining whether FreeStanding fonts will be setup. Set before running setup(). Default value is true. Please note that running setup() when this value is false will prevent any FontConsumer from using FreeStandingFonts, regardless of what settings that FontConsumer may have.

Parameters:
using - When true, FreeStanding fonts will be configured.

setUsingSystemFonts

public void setUsingSystemFonts(boolean using)
Set parameter determining whether System fonts will be setup. Set before running setup(). Default value is false. Please note that running setup() when this value is false will prevent any FontConsumer from using SystemFonts, regardless of what settings that FontConsumer may have.

Parameters:
using - When true, System fonts will be configured.

setFatalConfigurationError

public void setFatalConfigurationError(boolean hasError)
Use this method to indicate that a configuration error has occurred which cannot be recovered.

Parameters:
hasError - Set to true to indicate that the server configuration is so bad that the server should not be used.

getSystemFontFamilyList

public List<String> getSystemFontFamilyList()
Specified by:
getSystemFontFamilyList in interface org.axsl.font.FontServer

getSystemFontList

public List<Font> getSystemFontList()
Specified by:
getSystemFontList in interface org.axsl.font.FontServer

getEncoding

public org.axsl.ps.Encoding getEncoding(String name)
Specified by:
getEncoding in interface org.axsl.font.FontServer

getAllFonts

public List<org.axsl.font.Font> getAllFonts(boolean freeStandingFonts,
                                            boolean systemFonts)
Specified by:
getAllFonts in interface org.axsl.font.FontServer

getEntityResolver

public EntityResolver getEntityResolver()
Returns the EntityResolver for this server.

Returns:
The EntityResolver.

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)
Sets the EntityResolver for this server.

Parameters:
entityResolver - The new EntityResolver.

registerFontOutputFactory

public void registerFontOutputFactory(FontOutputFactory4a factory)
Registers a FontOutputFactory4a for use by this server. This method can be used both to support custom FontOutput types and to override standard types. Note that if a factory was previously registered for the mime-type of the factory now being registered, the new registration overrides the previous registration. If this behavior is not desired, check the return value of fontOutputFactoryAvailable(String) before registering the new factory.

Parameters:
factory - The factory which should be registered.

getOutputFactory

public FontOutputFactory4a getOutputFactory(String mimeType)
Returns the output factory for a given mime type.

Parameters:
mimeType - The mime type for which an output factory is desired.
Returns:
The appropriate output factory, or null if none is registered for the mime type.

fontOutputFactoryAvailable

public boolean fontOutputFactoryAvailable(String mimeType)
Reports on the availability of FontOutputFactory4a instances by mime-type.

Parameters:
mimeType - The mime-type for which a factory is sought.
Returns:
True iff a factory has already been registered for the given mime-type.

registerFontFamily

public void registerFontFamily(String name)
                        throws org.axsl.font.FontException
Specified by:
registerFontFamily in interface org.axsl.font.FontServer
Throws:
org.axsl.font.FontException

isRegisteredFontFamily

public boolean isRegisteredFontFamily(String name)
Specified by:
isRegisteredFontFamily in interface org.axsl.font.FontServer

getFontFamilyForAlias

public String getFontFamilyForAlias(String alias)
Specified by:
getFontFamilyForAlias in interface org.axsl.font.FontServer

isRegisteredFontFamilyAlias

public boolean isRegisteredFontFamilyAlias(String alias)
Indicates whether a given String has been registered as a font-family alias.

Parameters:
alias - The alias which is being tested.
Returns:
True iff this alias is already registered.

registerFont

public void registerFont(String fontID,
                         DataSource fontFileSource,
                         DataSource metricsFileSource,
                         String collectionID,
                         org.axsl.font.Font.Embedding requestedEmbedding,
                         String systemName)
                  throws org.axsl.font.FontException
Specified by:
registerFont in interface org.axsl.font.FontServer
Throws:
org.axsl.font.FontException

getRegisteredFont

public RegisteredFont getRegisteredFont(String name)
Returns the font registered to a given name.

Parameters:
name - The name of the font being sought.
Returns:
The registered font instance, or null if the font name has not been registered.

registerFont

public void registerFont(String fontID,
                         RegisteredFont rf)
                  throws org.axsl.font.FontException
Maps a given font name to its related RegisteredFont instance.

Parameters:
fontID - The name of the font to be associated.
rf - The registered font instance to be associated with the name.
Throws:
org.axsl.font.FontException - If the fontID is already registered.

isRegisteredFont

public boolean isRegisteredFont(String fontID)
Specified by:
isRegisteredFont in interface org.axsl.font.FontServer

registerFontDescription

public void registerFontDescription(String fontFamily,
                                    String fontID,
                                    org.axsl.ps.Encoding encoding,
                                    org.axsl.font.Font.Style style,
                                    org.axsl.font.Font.Weight weight,
                                    org.axsl.font.Font.Variant variant,
                                    org.axsl.font.Font.Stretch stretch,
                                    float simulatedSmallCaps,
                                    float simulatedOblique,
                                    float simulatedBackslant,
                                    float[] simulatedStretch)
                             throws org.axsl.font.FontException
Specified by:
registerFontDescription in interface org.axsl.font.FontServer
Throws:
org.axsl.font.FontException

makeFontSelector

public FontSelector makeFontSelector(FontConsumer4a consumer)
Returns the font-selector that should be used by a given font consumer.

Parameters:
consumer - The consumer for which a font-selector is needed.
Returns:
The font-selector instance.

registerFontSelectorFactory

public void registerFontSelectorFactory(String name,
                                        FontSelectorFactory factory)
                                 throws org.axsl.font.FontException
Register a FontSelectorFactory for use in the font system.

Parameters:
name - The name by which this factory should be referred in FontConsumer4a.setFontSelectorAutoType(String).
factory - The factory instance that should be used to create FontSelectors for name when requested.
Throws:
org.axsl.font.FontException - If either name, or factory is invalid.

makeFontConsumer

public FontConsumer4a makeFontConsumer()
Specified by:
makeFontConsumer in interface org.axsl.font.FontServer

registeredFontFamilies

public Collection<RegisteredFontFamily> registeredFontFamilies()
Returns the collection of registered font-family instances.

Returns:
The collection of registered font-family instances.

getPsServer

public org.axsl.ps.PsServer getPsServer()
Returns the PostScript server.

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


Copyright © 2017. All rights reserved.