PDF Clown
0.0.8

it.stefanochizzolini.clown.documents.contents.fonts
Class Font

java.lang.Object
  extended by it.stefanochizzolini.clown.objects.PdfObjectWrapper<PdfDictionary>
      extended by it.stefanochizzolini.clown.documents.contents.fonts.Font
Direct Known Subclasses:
CompositeFont, SimpleFont

public abstract class Font
extends PdfObjectWrapper<PdfDictionary>

Abstract font [PDF:1.6:5.4].

Version:
0.0.8
Author:
Stefano Chizzolini (http://www.stefanochizzolini.it)

Nested Class Summary
static class Font.FlagsEnum
          Font descriptor flags [PDF:1.6:5.7.1].
 
Field Summary
protected  BiMap<ByteArray,Integer> codes
          Unicodes by character code.
protected  int defaultGlyphWidth
          Default glyph width.
protected  Map<Integer,Integer> glyphIndexes
          Glyph indexes by unicode.
protected  Map<Integer,Integer> glyphKernings
          Glyph kernings by (left-right) glyph index pairs.
protected  Map<Integer,Integer> glyphWidths
          Glyph widths by glyph index.
protected  boolean symbolic
          Whether the font encoding is custom (that is non-Unicode).
 
Constructor Summary
protected Font(Document context)
          Creates a new font structure within the given document context.
protected Font(PdfDirectObject baseObject)
          Loads an existing font structure.
 
Method Summary
 String decode(byte[] code)
          Gets the text from the given internal representation.
 byte[] encode(String text)
          Gets the internal representation of the given text.
 boolean equals(Font object)
           
static Font get(Document context, File file)
          Creates the representation of a font.
static Font get(Document context, IInputStream fontData)
          Creates the representation of a font.
static Font get(Document context, String path)
          Creates the representation of a font.
 double getAscent()
          Gets the unscaled vertical offset from the baseline to the ascender line (ascent).
 double getAscent(double size)
          Gets the vertical offset from the baseline to the ascender line (ascent), scaled to the given font size.
 double getDescent()
          Gets the unscaled vertical offset from the baseline to the descender line (descent).
 double getDescent(double size)
          Gets the vertical offset from the baseline to the descender line (descent), scaled to the given font size.
protected abstract  PdfDictionary getDescriptor()
          Gets the font descriptor.
 EnumSet<Font.FlagsEnum> getFlags()
          Gets the font descriptor flags.
 double getHeight(char textChar)
          Gets the unscaled height of the given character.
 double getHeight(char textChar, double size)
          Gets the height of the given character, scaled to the given font size.
 double getHeight(String text)
          Gets the unscaled height of the given text.
 double getHeight(String text, double size)
          Gets the height of the given text, scaled to the given font size.
 double getKernedWidth(String text, double size)
          Gets the width (kerning inclusive) of the given text, scaled to the given font size.
 int getKerning(char textChar1, char textChar2)
          Gets the unscaled kerning width between two given characters.
 int getKerning(String text)
          Gets the unscaled kerning width inside the given text.
 double getKerning(String text, double size)
          Gets the kerning width inside the given text, scaled to the given font size.
 double getLineHeight()
          Gets the unscaled line height.
 double getLineHeight(double size)
          Gets the line height, scaled to the given font size.
 String getName()
          Gets the PostScript name of the font.
static double getScalingFactor(double size)
          Gets the scaling factor to be applied to unscaled metrics to get actual measures.
 String getType()
          Gets the font type.
 int getWidth(char textChar)
          Gets the unscaled width of the given character.
 double getWidth(char textChar, double size)
          Gets the width of the given character, scaled to the given font size.
 int getWidth(String text)
          Gets the unscaled width (kerning exclusive) of the given text.
 double getWidth(String text, double size)
          Gets the width (kerning exclusive) of the given text, scaled to the given font size.
 boolean isSymbolic()
          Gets whether the font encoding is custom (that is non-Unicode).
protected  void load()
          Loads font information from existing PDF font structure.
protected abstract  void onLoad()
          Notifies the loading of font information from an existing PDF font structure.
static Font wrap(PdfReference reference)
          Wraps a font reference into a font object.
 
Methods inherited from class it.stefanochizzolini.clown.objects.PdfObjectWrapper
clone, delete, getBaseDataObject, getBaseObject, getContainer, getDocument, getFile, setBaseObject, setContainer, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

codes

protected BiMap<ByteArray,Integer> codes
Unicodes by character code.

Note

When this map is populated, symbolic variable shall accordingly be set.


defaultGlyphWidth

protected int defaultGlyphWidth
Default glyph width.


glyphIndexes

protected Map<Integer,Integer> glyphIndexes
Glyph indexes by unicode.


glyphKernings

protected Map<Integer,Integer> glyphKernings
Glyph kernings by (left-right) glyph index pairs.


glyphWidths

protected Map<Integer,Integer> glyphWidths
Glyph widths by glyph index.


symbolic

protected boolean symbolic
Whether the font encoding is custom (that is non-Unicode).

Constructor Detail

Font

protected Font(Document context)
Creates a new font structure within the given document context.


Font

protected Font(PdfDirectObject baseObject)
Loads an existing font structure.

Method Detail

get

public static Font get(Document context,
                       String path)
Creates the representation of a font.


get

public static Font get(Document context,
                       File file)
Creates the representation of a font.


get

public static Font get(Document context,
                       IInputStream fontData)
Creates the representation of a font.


getScalingFactor

public static final double getScalingFactor(double size)
Gets the scaling factor to be applied to unscaled metrics to get actual measures.


wrap

public static final Font wrap(PdfReference reference)
Wraps a font reference into a font object.

Parameters:
reference - Reference to a font object.
Returns:
Font object associated to the reference.

decode

public final String decode(byte[] code)
Gets the text from the given internal representation.

Parameters:
code - Internal representation to decode.
Since:
0.0.6

encode

public final byte[] encode(String text)
Gets the internal representation of the given text.

Parameters:
text - Text to encode.
Since:
0.0.6

equals

public final boolean equals(Font object)

getAscent

public double getAscent()
Gets the unscaled vertical offset from the baseline to the ascender line (ascent). The value is a positive number.


getAscent

public final double getAscent(double size)
Gets the vertical offset from the baseline to the ascender line (ascent), scaled to the given font size. The value is a positive number.

Parameters:
size - Font size.

getDescent

public double getDescent()
Gets the unscaled vertical offset from the baseline to the descender line (descent). The value is a negative number.


getDescent

public final double getDescent(double size)
Gets the vertical offset from the baseline to the descender line (descent), scaled to the given font size. The value is a negative number.

Parameters:
size - Font size.

getFlags

public EnumSet<Font.FlagsEnum> getFlags()
Gets the font descriptor flags.


getHeight

public final double getHeight(char textChar)
Gets the unscaled height of the given character.

Parameters:
textChar - Character whose height has to be calculated.

getHeight

public final double getHeight(char textChar,
                              double size)
Gets the height of the given character, scaled to the given font size.

Parameters:
textChar - Character whose height has to be calculated.
size - Font size.

getHeight

public final double getHeight(String text)
Gets the unscaled height of the given text.

Parameters:
text - Text whose height has to be calculated.

getHeight

public final double getHeight(String text,
                              double size)
Gets the height of the given text, scaled to the given font size.

Parameters:
text - Text whose height has to be calculated.
size - Font size.

getKernedWidth

public final double getKernedWidth(String text,
                                   double size)
Gets the width (kerning inclusive) of the given text, scaled to the given font size.

Parameters:
text - Text whose width has to be calculated.
size - Font size.

getKerning

public final int getKerning(char textChar1,
                            char textChar2)
Gets the unscaled kerning width between two given characters.

Parameters:
textChar1 - Left character.
textChar2 - Right character,

getKerning

public final int getKerning(String text)
Gets the unscaled kerning width inside the given text.

Parameters:
text - Text whose kerning has to be calculated.

getKerning

public final double getKerning(String text,
                               double size)
Gets the kerning width inside the given text, scaled to the given font size.

Parameters:
text - Text whose kerning has to be calculated.
size - Font size.

getLineHeight

public double getLineHeight()
Gets the unscaled line height.


getLineHeight

public final double getLineHeight(double size)
Gets the line height, scaled to the given font size.

Parameters:
size - Font size.

getName

public final String getName()
Gets the PostScript name of the font.


getType

public final String getType()
Gets the font type.


getWidth

public int getWidth(char textChar)
Gets the unscaled width of the given character.

Parameters:
textChar - Character whose width has to be calculated.

getWidth

public final double getWidth(char textChar,
                             double size)
Gets the width of the given character, scaled to the given font size.

Parameters:
textChar - Character whose height has to be calculated.
size - Font size.

getWidth

public int getWidth(String text)
Gets the unscaled width (kerning exclusive) of the given text.

Parameters:
text - Text whose width has to be calculated.

getWidth

public final double getWidth(String text,
                             double size)
Gets the width (kerning exclusive) of the given text, scaled to the given font size.

Parameters:
text - Text whose width has to be calculated.
size - Font size.

isSymbolic

public boolean isSymbolic()
Gets whether the font encoding is custom (that is non-Unicode).


getDescriptor

protected abstract PdfDictionary getDescriptor()
Gets the font descriptor.


load

protected void load()
Loads font information from existing PDF font structure.


onLoad

protected abstract void onLoad()
Notifies the loading of font information from an existing PDF font structure.


PDF Clown
0.0.8

Project home page

Copyright © 2006-2010 Stefano Chizzolini. Some Rights Reserved.
This documentation is available under the terms of the GNU Free Documentation License.