Class ExternalFontMapper

java.lang.Object
com.lowagie.text.pdf.DefaultFontMapper
uk.ac.starlink.ttools.plot.ExternalFontMapper
All Implemented Interfaces:
com.lowagie.text.pdf.FontMapper

public class ExternalFontMapper extends com.lowagie.text.pdf.DefaultFontMapper
IText FontMapper implementation that works with externally supplied TTF files. It is suitable for use with JLatexMath. The paths of externally stored TTF files are supplied to the mapper at construction time. There are utility methods for extracting lists of the locations of such paths from supplied zip (or jar) files.
Since:
4 May 2012
Author:
Mark Taylor
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.lowagie.text.pdf.DefaultFontMapper

    com.lowagie.text.pdf.DefaultFontMapper.BaseFontParameters
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExternalFontMapper(String[] fontLocations)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.lowagie.text.pdf.BaseFont
    awtToPdf(Font font)
     
    Creates a font mapper given a stream of strings giving resource paths, for resources available on the classpath.
    Creates a font mapper given a list of font resource paths, for resources available on the classpath.
    static void
    main(String[] args)
    When given the names of one or more zip/jar files as arguments, this writes to standard output the absolute paths of any entries that appear to be a TTF file.
    static String[]
    Reads lines of text from a stream.
    static void
    Writes lines of text to a stream.

    Methods inherited from class com.lowagie.text.pdf.DefaultFontMapper

    getAliases, getBaseFontParameters, getMapper, insertDirectory, insertNames, pdfToAwt, putAlias, putName

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExternalFontMapper

      public ExternalFontMapper(String[] fontLocations)
      Constructor.
      Parameters:
      fontLocations - locations for font TTF files as supplied to the FontFactory.register method; URLs work (probably files too)
  • Method Details

    • awtToPdf

      public com.lowagie.text.pdf.BaseFont awtToPdf(Font font)
      Specified by:
      awtToPdf in interface com.lowagie.text.pdf.FontMapper
      Overrides:
      awtToPdf in class com.lowagie.text.pdf.DefaultFontMapper
    • createMapperFromResourcePaths

      public static ExternalFontMapper createMapperFromResourcePaths(String[] paths)
      Creates a font mapper given a list of font resource paths, for resources available on the classpath. These are mapped to URLs and passed to the constructor.
      Parameters:
      paths - absolute resource path strings for TTF files
      Returns:
      new font mapper
    • createMapperFromResourceList

      public static ExternalFontMapper createMapperFromResourceList(InputStream in) throws IOException
      Creates a font mapper given a stream of strings giving resource paths, for resources available on the classpath. The stream is read and closed, and createMapperFromResourcePaths(java.lang.String[]) is called. Each resource is on a separate line, encoding is UTF-8.
      Parameters:
      in - input stream
      Returns:
      new font mapper
      Throws:
      IOException
    • readLines

      public static String[] readLines(InputStream in) throws IOException
      Reads lines of text from a stream.
      Parameters:
      in - input stream
      Returns:
      lines
      Throws:
      IOException
    • writeLines

      public static void writeLines(String[] lines, OutputStream out) throws IOException
      Writes lines of text to a stream.
      Parameters:
      lines - lines to write
      out - output stream
      Throws:
      IOException
    • main

      public static void main(String[] args) throws IOException
      When given the names of one or more zip/jar files as arguments, this writes to standard output the absolute paths of any entries that appear to be a TTF file. The output of this is suitable for use with the createMapperFromResourceList(java.io.InputStream) method.
      Parameters:
      args - list of zip file names
      Throws:
      IOException