de.vc.jfo.tools

## Class FontMapper

- java.lang.Object
- - java.util.Observable
  - - de.vc.jfo.tools.FontMapper

- All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable
  Direct Known Subclasses:
    FontMapper

      public class FontMapper
      extends java.util.Observable
      implements java.lang.Cloneable, java.lang.Comparable

  A font mapper substitutes a font-name with another. This might be useful for converting into XSL-FO format if XSL-FO render doesn't support all fonts of the source document. Also a font-mapper can transcode characters, e.i. characters are replaced.
  Following example replaces all fonts containing "times" (at any position if font name) with "Times" and unmapped fonts are replaced by default font "Helvetica":
  `FontMapper fm = new FontMapper();
  fm.addMappingRule("*times*", "Times");
  fm.setDefaultFont("Helvetica");
  `

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `LINE_HEIGHT_DEFAULT`
    `static int` | `LINE_HEIGHT_NONE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FontMapper()` Creates a FontMapper.
    `FontMapper(de.vc.config.Configuration config)` Creates a FontMapper based on a configuration.
    `FontMapper(java.io.InputStream xml)` Creates a FontMapper from a XML font-mapping stream.
    `FontMapper(java.lang.String xmlFile)` Creates a FontMapper from a XML font-mapping file.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `FontMappingRule` | `addMappingRule(java.lang.String inFont, java.lang.String outFont)` Adds mapping information for a font.
    `de.vc.config.Configuration` | `buildConfiguration()` Builds a configuration containing all mapping rules, default font and character transcodings.
    `void` | `clearMapping()` Removes all mapping rules except the default font.
    `FontMapper` | `cloned()` A deep clone of this mapping is returned.
    `int` | `compareTo(java.lang.Object o)`
    `void` | `configure(de.vc.config.Configuration config)` Set up this mapper from a configuration.
    `void` | `configure(java.io.InputStream configuration)` Configure this font mapper with new configuration.
    `java.lang.String` | `getDefaultFont()` Gets the default font.
    `int` | `getDefaultLineHeight()` Gets the default line height (percentage) applied to paragraphs (fo:block).
    `java.util.List` | `getEntries()` Gets an unmodifieable list of all FontMappingEntries.
    `java.lang.String` | `getForRenderer()` Get's the name of the renderer for which the font-mapping should be used.
    `java.lang.String` | `getID()`
    `FontMappingRule` | `getMappingRule(java.lang.String font)` Gets the mapping entry of a font.
    `java.util.Map` | `getNameMap()` Gets a map of input font-name/pattern (String) to output font-name (String).
    `boolean` | `hasID()` Return true if this mapper has an ID.
    `boolean` | `isGlobalMapper()` Returns true if this mapper is for global use and not dedicated for a certain renderer.
    `Measure` | `lineHeightForFont(java.lang.String font)` Returns the line height for a given font.
    `void` | `logMapping()` Writes mapping infos through the logger (INFO level).
    `java.lang.String` | `mapFontName(java.lang.String font)` Maps an input font according to registered mapping rules to an output font.
    `int` | `matches(java.lang.String renderer)`
    `void` | `removeMappingRule(java.lang.String font)` Removes a mapping.
    `boolean` | `renameRule(java.lang.String oldFont, java.lang.String newFont)` Renames a mapping rule.
    `void` | `setDefaultFont(java.lang.String defaultFont)` Sets the default font, a null value disables the default font.
    `void` | `setDefaultLineHeight(int defaultLineHeight)` Sets the default line height (percentage) or disables line height.
    `void` | `setForRenderer(java.lang.String forRenderer)`
    `void` | `setID(java.lang.String id)`
    `void` | `storeTo(java.io.OutputStream os)` Stores mapping information into given OutputStream.
    `java.lang.String` | `transcodeText(java.lang.String font, java.lang.String text)` Transcodes a string according substitution rules of a font.

    - ### Methods inherited from class java.util.Observable

      `addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### LINE_HEIGHT_NONE

          public static final int LINE_HEIGHT_NONE

      See Also:
        Constant Field Values

    - #### LINE_HEIGHT_DEFAULT

          public static final int LINE_HEIGHT_DEFAULT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FontMapper

          public FontMapper()

      Creates a FontMapper.

    - #### FontMapper

          public FontMapper(java.lang.String xmlFile)
                     throws de.vc.config.ConfigurationException,
                            java.io.IOException

      Creates a FontMapper from a XML font-mapping file.
      Parameters:
        `xmlFile` - XML file
      Throws:
        `java.io.IOException`
        `de.vc.config.ConfigurationException`

    - #### FontMapper

          public FontMapper(java.io.InputStream xml)
                     throws de.vc.config.ConfigurationException,
                            java.io.IOException

      Creates a FontMapper from a XML font-mapping stream.
      Parameters:
        `xml` - XML stream.
      Throws:
        `java.io.IOException`
        `de.vc.config.ConfigurationException`

    - #### FontMapper

          public FontMapper(de.vc.config.Configuration config)
                     throws de.vc.config.ConfigurationException,
                            java.io.IOException

      Creates a FontMapper based on a configuration.
      Parameters:
        `config` - Configuration.
      Throws:
        `java.io.IOException`
        `de.vc.config.ConfigurationException`

  - ### Method Detail

    - #### mapFontName

          public java.lang.String mapFontName(java.lang.String font)

      Maps an input font according to registered mapping rules to an output font. If `font==null` the default font is returned.
      Parameters:
        `font` - Input font.
      Returns:
        Output font.

    - #### lineHeightForFont

          public Measure lineHeightForFont(java.lang.String font)

      Returns the line height for a given font.
      Parameters:
        `font` - Fontname
      Returns:
        Line-height (unit=Percentage).

    - #### addMappingRule

          public FontMappingRule addMappingRule(java.lang.String inFont,
                                       java.lang.String outFont)

      Adds mapping information for a font. The font name is not case-sensitive and wildcards (* and ?) are accepted.
      Example:
      `addMappingRule("*Arial*","Helvetica");`
      All fonts that contains 'Arial' are mapped to 'Helvetica'.
      Parameters:
        `inFont` - Input font that will be replaced. Font name may contain wildcards (* and ?).
        `outFont` - Output font that is replacing input font.
      Returns:
        FontMappingRule that was created.

    - #### renameRule

          public boolean renameRule(java.lang.String oldFont,
                           java.lang.String newFont)

      Renames a mapping rule.
      Parameters:
        `oldFont` - Old input font.
        `newFont` - New input font.
      Returns:
        boolean

    - #### removeMappingRule

          public void removeMappingRule(java.lang.String font)

      Removes a mapping.
      Parameters:
        `font` - Name of input font.

    - #### getNameMap

          public java.util.Map getNameMap()

      Gets a map of input font-name/pattern (String) to output font-name (String).
      Returns:
        Map.

    - #### clearMapping

          public void clearMapping()

      Removes all mapping rules except the default font.

    - #### setDefaultFont

          public void setDefaultFont(java.lang.String defaultFont)

      Sets the default font, a null value disables the default font.
      Parameters:
        `defaultFont` - Name of default font.

    - #### getDefaultFont

          public java.lang.String getDefaultFont()

      Gets the default font.
      Returns:
        Default font, a null value means that no default font is applied.

    - #### getDefaultLineHeight

          public int getDefaultLineHeight()

      Gets the default line height (percentage) applied to paragraphs (fo:block). A font mapping rule may contain another line height for a certain font.
      Returns:
        Line height (percentage) or LINE_HEIGHT_NONE.
      See Also:
        `LINE_HEIGHT_NONE`

    - #### getForRenderer

          public java.lang.String getForRenderer()

      Get's the name of the renderer for which the font-mapping should be used.
      Returns:
        Name of renderer.

    - #### isGlobalMapper

          public boolean isGlobalMapper()

      Returns true if this mapper is for global use and not dedicated for a certain renderer.
      Returns:
        true if used global.

    - #### hasID

          public boolean hasID()

      Return true if this mapper has an ID.
      Returns:
        true, mapper has an ID.

    - #### setDefaultLineHeight

          public void setDefaultLineHeight(int defaultLineHeight)

      Sets the default line height (percentage) or disables line height.
      Parameters:
        `defaultLineHeight` - Line height (percentage) or LINE_HEIGHT_NONE.
      See Also:
        `LINE_HEIGHT_NONE`

    - #### setForRenderer

          public void setForRenderer(java.lang.String forRenderer)

    - #### transcodeText

          public java.lang.String transcodeText(java.lang.String font,
                                       java.lang.String text)

      Transcodes a string according substitution rules of a font. During transcoding some or all characters are replaced with other characters. This might be useful, if the replaced font has another symbol table then the new font.
      Parameters:
        `font` - Font of `text`.
        `text` - Text.
      Returns:
        Transcoded text.

    - #### getMappingRule

          public FontMappingRule getMappingRule(java.lang.String font)

      Gets the mapping entry of a font.
      Parameters:
        `font` - Input font name/pattern.
      Returns:
        FontMappingRule or null if not mapped.

    - #### getEntries

          public java.util.List getEntries()

      Gets an unmodifieable list of all FontMappingEntries.
      Returns:
        List of `FontMappingRule`.

    - #### storeTo

          public void storeTo(java.io.OutputStream os)

      Stores mapping information into given OutputStream. OutputStream is closed.
      Parameters:
        `os` - OutputStream.

    - #### cloned

          public FontMapper cloned()

      A deep clone of this mapping is returned.
      Returns:
        Clone.

    - #### configure

          public void configure(java.io.InputStream configuration)
                         throws de.vc.config.ConfigurationException,
                                java.io.IOException

      Configure this font mapper with new configuration.
      Parameters:
        `configuration` - New configuration.
      Throws:
        `de.vc.config.ConfigurationException`
        `java.io.IOException`

    - #### configure

          public void configure(de.vc.config.Configuration config)
                         throws de.vc.config.ConfigurationException

      Set up this mapper from a configuration.
      Parameters:
        `config` - Configuration.
      Throws:
        `de.vc.config.ConfigurationException`

    - #### buildConfiguration

          public de.vc.config.Configuration buildConfiguration()

      Builds a configuration containing all mapping rules, default font and character transcodings.
      Returns:
        Configuration

    - #### logMapping

          public void logMapping()

      Writes mapping infos through the logger (INFO level).

    - #### matches

          public int matches(java.lang.String renderer)

    - #### compareTo

          public int compareTo(java.lang.Object o)

      Specified by:
        `compareTo` in interface `java.lang.Comparable`
      Parameters:
        `o` - the Object to be compared.
      Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

    - #### getID

          public java.lang.String getID()

    - #### setID

          public void setID(java.lang.String id)

© 2003-2011 by Sascha Schmidt (vision-cloud.de). All Rights Reserved.