org.pz.platypus
Class TypefaceMap

java.lang.Object
  extended by org.pz.platypus.TypefaceMap

public class TypefaceMap
extends java.lang.Object

Map that maps a typeface family to font files on the runtime system that implement that typeface family. Entries consist of a typeface name -> linked-list of file URIs. So, for example, Arial -> c:\windows\fonts\arial.ttf, c:\windows\fonts\ariali.ttf, etc. This map is consulted when the user specifies a typeface other than the 14 base PDF fonts

Author:
alb

Field Summary
private  GDD gdd
           
private  java.util.HashMap<java.lang.String,java.util.LinkedList<java.lang.String>> map
           
 
Constructor Summary
TypefaceMap(GDD Gdd)
           
 
Method Summary
 void addFamily(java.lang.String family, java.util.LinkedList<java.lang.String> filenames)
          As a family name with a linked list of one or more associated font files
 void addFontFileToFamily(java.lang.String family, java.lang.String filename)
          add a filename to a family, as long as the filename was not previously added .
 java.lang.String[] extractFamilyNames(java.lang.String fontFilename, com.lowagie.text.pdf.BaseFont bf)
          Uses iText to extract the family name (or in case of .ttc the names) of the font family.
 java.lang.String[] getFamilyFilenames(java.lang.String family)
          Returns the list of filenames that correspond to a font/typeface family.
(package private)  java.util.LinkedList<java.lang.String> getFontFileList(java.lang.String[] fontDirs)
          Return a linked list of font files found in the passed-in list of font directories.
 java.util.HashMap<java.lang.String,java.util.LinkedList<java.lang.String>> getMap()
          Used mostly for testing
 void loadFamilies()
          Load the font families with their respective font files into the table 1.
 void loadFontFile(java.lang.String fontFilename, com.lowagie.text.pdf.BaseFont bf)
          Loads an individual font file to the map.
 void loadFromFile(java.lang.String filename)
          Load the Typeface map from a configuration file consisting on line entries of the form: family=fontFilename;
 void loadLine(java.lang.String line)
          Loads a line from the config file.
 void loadMapFromFile()
          Reads the config/fontlist.txt file in PLATYPUS_HOME and loads the entries into the map.
(package private)  void writeMapEntryToFile(java.io.PrintWriter out, java.lang.String family, java.lang.String[] files)
          Writes a single map entry to file
 void writeMapToFile(java.lang.String filename)
          Writes the current map to an output file after sorting the entries on font family.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private java.util.HashMap<java.lang.String,java.util.LinkedList<java.lang.String>> map

gdd

private GDD gdd
Constructor Detail

TypefaceMap

public TypefaceMap(GDD Gdd)
Method Detail

loadMapFromFile

public void loadMapFromFile()
Reads the config/fontlist.txt file in PLATYPUS_HOME and loads the entries into the map.

Throws:
InvalidConfigFileException - if the fontlist.txt file is missing

writeMapToFile

public void writeMapToFile(java.lang.String filename)
Writes the current map to an output file after sorting the entries on font family.

Parameters:
filename - name of file to write out.

writeMapEntryToFile

void writeMapEntryToFile(java.io.PrintWriter out,
                         java.lang.String family,
                         java.lang.String[] files)
Writes a single map entry to file

Parameters:
out - the file writer for text
family - the family part of the map entry
files - the files part of the map entry

loadFamilies

public void loadFamilies()
Load the font families with their respective font files into the table 1. Get the list of font directories 2. Get the list of fonts files from within those directories 3. For each font file, load its family and name into the table 4. Write out a file with the family and font files to PLATYPUS_HOME/config


loadFontFile

public void loadFontFile(java.lang.String fontFilename,
                         com.lowagie.text.pdf.BaseFont bf)
Loads an individual font file to the map. First extracts the family, then if no error occurred, loads the family and the font name to the map.

Parameters:
fontFilename - font file to load to map
bf - is the base font

extractFamilyNames

public java.lang.String[] extractFamilyNames(java.lang.String fontFilename,
                                             com.lowagie.text.pdf.BaseFont bf)
Uses iText to extract the family name (or in case of .ttc the names) of the font family.

Parameters:
fontFilename - font file
bf - base font we create to get the family font name
Returns:
the font's family name(s) or an empty array if an error occurred. For explanation of .ttc handling, see: http://itextdocs.lowagie.com/tutorial/fonts/getting/index.php

getFontFileList

java.util.LinkedList<java.lang.String> getFontFileList(java.lang.String[] fontDirs)
Return a linked list of font files found in the passed-in list of font directories. Font files must use a supported format: .ttf, .otf, .afm, or .ttc

Parameters:
fontDirs - array of directory names that should contain fonts
Returns:
linked list of filenames. Will have length = 0, if not font files were found.

addFamily

public void addFamily(java.lang.String family,
                      java.util.LinkedList<java.lang.String> filenames)
As a family name with a linked list of one or more associated font files

Parameters:
family - font family (key)
filenames - font files associated with the family (value)

addFontFileToFamily

public void addFontFileToFamily(java.lang.String family,
                                java.lang.String filename)
add a filename to a family, as long as the filename was not previously added .

Parameters:
family - the family name
filename - the filename to add

getFamilyFilenames

public java.lang.String[] getFamilyFilenames(java.lang.String family)
Returns the list of filenames that correspond to a font/typeface family.

Parameters:
family - the family to look up
Returns:
an array of filenames; an empty array in the event that the family is not found

loadFromFile

public void loadFromFile(java.lang.String filename)
Load the Typeface map from a configuration file consisting on line entries of the form: family=fontFilename;

Parameters:
filename - name of the file to read

loadLine

public void loadLine(java.lang.String line)
Loads a line from the config file. Note: lines commencing with a # are comments

Parameters:
line - the line read from the file containing: family=file name/location

getMap

public java.util.HashMap<java.lang.String,java.util.LinkedList<java.lang.String>> getMap()
Used mostly for testing

Returns:
the hash map


Copyright © 2008-10 Pacific Data Works LLC