org.pz.platypus.plugin.pdf
Class PdfFontFactory

java.lang.Object
  extended by org.pz.platypus.plugin.pdf.PdfFontFactory

public class PdfFontFactory
extends java.lang.Object

Handles the complexities of creating a font for iText

Author:
alb

Field Summary
private  GDD gdd
           
private  PdfData pdfData
           
 
Constructor Summary
PdfFontFactory(GDD Gdd, PdfData pdd)
           
 
Method Summary
(package private)  java.lang.String computeBase14ItextFontName(PdfFont font)
          Gets the iText font name for any of the Base14 fonts.
(package private)  int computeItextStyle(PdfFont f)
          iText font style captures bold, italic, strikethru, underline.
 com.lowagie.text.Font createItextFont(PdfFont f)
          Creates an iText Font object based on a passed-in PdfFont
(package private)  java.lang.String createItextFontName(PdfFont f)
          Get the name by which iText refers to this font.
(package private)  void errFontNotFound(java.lang.String typefaceName)
           
(package private)  void errTtcFileHandling(java.lang.String fontFile)
           
(package private)  boolean findAndRegisterFont(java.lang.String typefaceName)
          Get the filenames from the typefaceMap and register them in iText's FontFactory.
(package private)  com.lowagie.text.Font getCp1252Font(java.lang.String fontName, float size, int style)
          Gets the font with CP1252 (aka WINANSI) encoding
(package private)  com.lowagie.text.Font getIdentityHFont(java.lang.String fontName, float size, int style)
          Opens a font using the IDENTITY-H encoding.
(package private)  boolean isBase14Font(java.lang.String fontName)
          Determines whehter the current font is one of the Base14 Acrobat fonts, built into every PDF reader.
(package private)  boolean isRegisteredWithItext(java.lang.String fontName)
          This test whether a font is registered by name or by family name in iText.
(package private)  java.lang.String[] lookupFontFilenames(java.lang.String typefaceName)
          Get the names of the actual font files that are the implementation of this typeface
private  void registerFont(java.lang.String fontFile)
          Actual font registration.
(package private)  void registerOneFont(java.lang.String fontFile, java.lang.String typeface)
          Unfortunately, iText does not pass along the exception if the file cannot be found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gdd

private GDD gdd

pdfData

private PdfData pdfData
Constructor Detail

PdfFontFactory

public PdfFontFactory(GDD Gdd,
                      PdfData pdd)
Method Detail

createItextFont

public com.lowagie.text.Font createItextFont(PdfFont f)
Creates an iText Font object based on a passed-in PdfFont

Parameters:
f - the PdfFont containing the parameters for the font
Returns:
the iText Font object

computeItextStyle

int computeItextStyle(PdfFont f)
iText font style captures bold, italic, strikethru, underline. Since we handle strikethrough and underline ourselves, we use it to communicate italic and bold only. This computation done here.

Parameters:
f - the PdfFont whose style is being checked
Returns:
the iText Style

computeBase14ItextFontName

java.lang.String computeBase14ItextFontName(PdfFont font)
Gets the iText font name for any of the Base14 fonts.

Parameters:
font - the PdfFont whose name we're looking up.
Returns:
the iText name or null if an error has occured

createItextFontName

java.lang.String createItextFontName(PdfFont f)
Get the name by which iText refers to this font. This routine is mostly occupied with the special handling of the Base14 fonts. For all other fonts, this method makes sure the font is registered with iText and returns its name as registered by iText (which is the family name for the font).

Parameters:
f - PdfFont whose iText name we're getting
Returns:
a string containing the iText usable name for this font. If passed-in font is null or the font name is not recognized or found, TIMES_ROMAN is returned.

isRegisteredWithItext

boolean isRegisteredWithItext(java.lang.String fontName)
This test whether a font is registered by name or by family name in iText. Either way is good enough for our purposes.

Parameters:
fontName - the font we're checking
Returns:
true if iText has the font registered by name or by family name, false otherwise.

findAndRegisterFont

boolean findAndRegisterFont(java.lang.String typefaceName)
Get the filenames from the typefaceMap and register them in iText's FontFactory.

Parameters:
typefaceName - name of the typeface
Returns:
true if the font is now registered, false if an error occurred. (Font was not in fontlist.)

getCp1252Font

com.lowagie.text.Font getCp1252Font(java.lang.String fontName,
                                    float size,
                                    int style)
Gets the font with CP1252 (aka WINANSI) encoding

Parameters:
fontName - name of font to get
size - size in points
style - bold, italic, etc.
Returns:
the font, or null if an error occurred.

getIdentityHFont

com.lowagie.text.Font getIdentityHFont(java.lang.String fontName,
                                       float size,
                                       int style)
Opens a font using the IDENTITY-H encoding.

Parameters:
fontName - the name assigned to the font in the font list
size - the size in points
style - bold, italic, etc.
Returns:
the Font if opened; null if the file could not be opened or an error occurred.

isBase14Font

boolean isBase14Font(java.lang.String fontName)
Determines whehter the current font is one of the Base14 Acrobat fonts, built into every PDF reader. These fonts require special hanldling, and so this routine helps identify them, based on their font face name.

Parameters:
fontName - name of the font face
Returns:
true if it's a base14 font name, false otherwise.

lookupFontFilenames

java.lang.String[] lookupFontFilenames(java.lang.String typefaceName)
Get the names of the actual font files that are the implementation of this typeface

Parameters:
typefaceName - the typefaces
Returns:
an array of strings containing the file names.

registerFont

private void registerFont(java.lang.String fontFile)
Actual font registration. Takes care of specious warning emitted by iText registering a TrueType collection (.ttc) file called from RegisterOneFont()

Parameters:
fontFile - the complete filename including the path

registerOneFont

void registerOneFont(java.lang.String fontFile,
                     java.lang.String typeface)
Unfortunately, iText does not pass along the exception if the file cannot be found. Rather, iText rethrows the exception internally and prints the stack trace. So, the only way to avoid this is to check for each file first before doing the registration.

Parameters:
fontFile - the file location and name
typeface - the name of the typeface to register the font for

errFontNotFound

void errFontNotFound(java.lang.String typefaceName)

errTtcFileHandling

void errTtcFileHandling(java.lang.String fontFile)


Copyright © 2008-10 Pacific Data Works LLC