PDF Clown
0.1.2

org.pdfclown.documents.contents.fonts
Class Font

java.lang.Object
  extended by org.pdfclown.objects.PdfObjectWrapper<PdfDictionary>
      extended by org.pdfclown.documents.contents.fonts.Font
All Implemented Interfaces:
Cloneable, IPdfObjectWrapper
Direct Known Subclasses:
CompositeFont, SimpleFont

@PDF(value=PDF10)
public abstract class Font
extends PdfObjectWrapper<PdfDictionary>

Abstract font [PDF:1.6:5.4].

Version:
0.1.1, 11/09/11
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).
protected  Set<Integer> usedCodes
          Used unicodes.
 
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(Object 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.
 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.
 int hashCode()
           
 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(PdfDirectObject baseObject)
          Wraps a font reference into a font object.
 
Methods inherited from class org.pdfclown.objects.PdfObjectWrapper
checkCompatibility, clone, delete, exists, getBaseDataObject, getBaseObject, getBaseObject, getContainer, getDataContainer, getDocument, getFile, getMetadata, retrieveName, retrieveNamedBaseObject, setBaseObject, setMetadata
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

codes

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

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


usedCodes

protected Set<Integer> usedCodes
Used unicodes.

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(PdfDirectObject baseObject)
Wraps a font reference into a font object.

Parameters:
baseObject - Font base 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(Object object)
Overrides:
equals in class PdfObjectWrapper<PdfDictionary>

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.


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.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

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

Project home page

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