Platypus

org.pz.platypus.plugin.pdf
Class PdfFont

java.lang.Object
  extended by org.pz.platypus.plugin.pdf.PdfFont
All Implemented Interfaces:
java.lang.Cloneable

public class PdfFont
extends java.lang.Object
implements java.lang.Cloneable

Handles fonts for the PDF plugin


Field Summary
private  boolean bold
          is font bold?
private  GDD gdd
           
private  boolean italics
          is fond italic?
private  com.lowagie.text.Font iTfont
          the iText font
private  PdfData pdfData
           
private  float size
          font size
private  Source source
          file and line number of last change
private  java.lang.String typeface
          the font typeface in the form of a string used by iText
 
Constructor Summary
PdfFont(PdfData pdd)
           
PdfFont(PdfData pdd, java.lang.String fontName, PdfFont existingFont)
          Constructor for cloning an existing PdfFont, but specifying a different typeface.
 
Method Summary
 PdfFont clone()
           
(package private)  int computeItextStyle()
          iText font style captures bold, italic, strikethru, underline.
(package private)  com.lowagie.text.Font createFont(PdfFont f)
          Creates an iText Font object based on the class fields
(package private)  java.lang.String createItextFontName(PdfFont f)
          Get the name by which iText refers to this font.
(package private)  boolean findAndRegisterFont(java.lang.String typefaceName)
          Get the filenames from the typefaceMap and register them in iText's FontFactory.
 boolean getBold()
           
(package private)  com.lowagie.text.Font getCp1252Font(java.lang.String fontName, float size, int style)
          Gets the font with CP1252 (aka WINANSI) encoding
 java.lang.String getFace()
           
(package private)  com.lowagie.text.Font getIdentityHFont(java.lang.String fontName, float size, int style)
          Opens a font using the IDENTITY-H encoding.
 boolean getItalics()
           
 com.lowagie.text.Font getItextFont()
          Get the iText font
 float getSize()
           
 Source getSource()
           
(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.
private  boolean isFileOtf(java.lang.String fontName)
          Looks up a font in the fontlist and determines whether it uses the .otf font format.
(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, java.lang.String typeface)
          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.
 void setBold(boolean onOff, Source newSource)
          set bold on/off and re-create the iText font to record the change.
 void setFace(java.lang.String newFace, Source newSource)
           
 void setItalics(boolean onOff, Source newSource)
          set italics on/off and re-create the iText font to record the change.
 void setSize(float newSize, Source newSource)
           
 void setToDefault()
          Initializes all PdfFont fields to defaults, and sets line number to 0
(package private)  void ttcFileErrorMsg(GDD gdd, java.lang.String fontFile)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iTfont

private com.lowagie.text.Font iTfont
the iText font


typeface

private java.lang.String typeface
the font typeface in the form of a string used by iText


size

private float size
font size


bold

private boolean bold
is font bold?


italics

private boolean italics
is fond italic?


source

private Source source
file and line number of last change


gdd

private GDD gdd

pdfData

private PdfData pdfData
Constructor Detail

PdfFont

public PdfFont(PdfData pdd)

PdfFont

public PdfFont(PdfData pdd,
               java.lang.String fontName,
               PdfFont existingFont)
Constructor for cloning an existing PdfFont, but specifying a different typeface.

Parameters:
pdd - PDF data
fontName - the name of the new font/typeface
existingFont - the font to clone the other attributes from
Method Detail

setToDefault

public void setToDefault()
Initializes all PdfFont fields to defaults, and sets line number to 0


clone

public PdfFont clone()
Overrides:
clone in class java.lang.Object

createFont

com.lowagie.text.Font createFont(PdfFont f)
Creates an iText Font object based on the class fields

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

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.

isFileOtf

private boolean isFileOtf(java.lang.String fontName)
Looks up a font in the fontlist and determines whether it uses the .otf font format.

Parameters:
fontName - name of font to verify
Returns:
true if it's an .otf font, otherwise false.

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.

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.

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.

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.)

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

registerFont

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

Parameters:
fontFile - the complete filename including the path
typeface - the name by which the typeface is registered.

ttcFileErrorMsg

void ttcFileErrorMsg(GDD gdd,
                     java.lang.String fontFile)

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.

computeItextStyle

int computeItextStyle()
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.

Returns:
the iText Style

getBold

public boolean getBold()

getItalics

public boolean getItalics()

getItextFont

public com.lowagie.text.Font getItextFont()
Get the iText font

Returns:
the iText font

getFace

public java.lang.String getFace()

getSize

public float getSize()

getSource

public Source getSource()

setBold

public void setBold(boolean onOff,
                    Source newSource)
set bold on/off and re-create the iText font to record the change.

Parameters:
onOff - the new value for the italics setting
newSource - the file and line # of the token that changed italics

setItalics

public void setItalics(boolean onOff,
                       Source newSource)
set italics on/off and re-create the iText font to record the change.

Parameters:
onOff - the new value for the italics setting
newSource - the file and line # of the token that changed italics

setSize

public void setSize(float newSize,
                    Source newSource)

setFace

public void setFace(java.lang.String newFace,
                    Source newSource)

Platypus

Copyright © 2006-10 Pacific Data Works LLC. (platypus.pz.org)