org.faceless.pdf2
Class PDFFont

java.lang.Object
  extended by org.faceless.pdf2.PDFFont
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
OpenTypeFont, StandardCJKFont, StandardFont, Type1Font

public abstract class PDFFont
extends Object

The PDFFont is the abstract superclass for all Fonts in a PDF document. It defines properties which are common to all fonts, regardless of writing direction.

Since:
1.0
See Also:
PDFStyle, LayoutBox

Method Summary
abstract  float getAscender()
          Get the Ascender for the font (the maximum height above the baseline the font extends), as a proportion of the point size.
 String[] getAvailableFeatures()
          Return the list of available features for this font.
 String getBaseName()
          Return the Base Font Name for this font.
 float getBottom(String s)
          Get the bottom-most Y co-ordinate if this String was rendered in 1 point high text at position (0,0)
 int getCharWidth(char c)
          Return the width of the specified character in millipoints if the font size was 1 point.
 int getCharWidth(int codepoint)
          Return the width of the specified character in millipoints if the font size was 1 point.
abstract  float getDefaultLeading()
           Get the default leading for this font - the preferred distance between two successive baselines of text.
abstract  float getDescender()
          Get the Descender for the font (the maximum height below the baseline the font extends), as a proportion of the point size.
 boolean getFeature(String feature)
          Returns whether the specified feature is currently set
 int getKerning(char c1, char c2)
          Get the horizontal character-to-character (or "pair-wise") kerning in this font for the specified characters, in millipoints.
 int getKerning(int codepoint1, int codepoint2)
          Get the horizontal character-to-character (or "pair-wise") kerning in this font for the specified characters, in millipoints.
 float getLeft(String s)
          Get the left-most X co-ordinate if this String was rendered in 1 point high text at position (0,0)
 float getRight(String s)
          Get the right-most X co-ordinate if this String was rendered in 1 point high text at position (0,0)
abstract  float getStrikeoutPosition()
          Get the strikeout position, as a proportion of the font size.
abstract  float getStrikeoutThickness()
          Get the strikeout thickness, as a proportion of the font size.
abstract  float getSubscriptPosition()
           Get the recommended position of a sub-script version of this font, as a proportion of the sub-scripted font size.
abstract  float getSubscriptSize()
           Get the recommended size of a super/sub script version of this font, as a proportion of the normal font size.
abstract  float getSuperscriptPosition()
           Get the recommended position of a super-script version of this font, as a proportion of the sub-scripted font size.
 float getTop(String s)
          Get the top-most Y co-ordinate if this String was rendered in 1 point high text at position (0,0)
abstract  float getUnderlinePosition()
          Get the underline position, as a proportion of the font size.
abstract  float getUnderlineThickness()
          Get the underline thickness, as a proportion of the font size.
abstract  float getXHeight()
          Get the X-Height of the font - normally the height of a lower-case 'x' character
 boolean isDefined(char c)
          Return true if the specified Unicode character is defined in the font.
 boolean isDefined(int codepoint)
          Return true if the specified Unicode character is defined in the font.
 boolean isHorizontal()
          Return true if the specified font is written Left-to-Right or Right-to-Left.
abstract  boolean isMonospace()
          Return true if every character has the same width (like Courier), false if every character is potentially a different width (like Times-Roman)
 int ligaturize(char[] buf, int off, int len, Locale locale)
          Substitute ligatures into the specified character array where appropriate.
 String ligaturize(String s, Locale locale)
           Return the specified string with ligatures substituted where appropriate.
 boolean requote(char[] buf, int off, int len, Locale locale)
          Substitute "curly-quotes" into the specified buffer where appropriate.
 String requote(String s, Locale l)
          Substitute curly quotes into the document.
 void setFeature(String feature, boolean on)
          Set or clear an optional feature on a font.
 String toString()
           
 PDFFont versionBold()
          Return a bold version of the current font, if available.
 PDFFont versionItalic()
          Return an italic version of the current font, if available.
 PDFFont versionNonBold()
          Return a non-bold version of the current font, if available.
 PDFFont versionNonItalic()
          Return a non-italic version of the current font, if available.
 PDFFont versionRegular()
          Return a non-bold, non-italic version of the current font, if available.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getLeft

public final float getLeft(String s)
Get the left-most X co-ordinate if this String was rendered in 1 point high text at position (0,0)


getTop

public final float getTop(String s)
Get the top-most Y co-ordinate if this String was rendered in 1 point high text at position (0,0)


getBottom

public final float getBottom(String s)
Get the bottom-most Y co-ordinate if this String was rendered in 1 point high text at position (0,0)


getRight

public final float getRight(String s)
Get the right-most X co-ordinate if this String was rendered in 1 point high text at position (0,0)


isDefined

public final boolean isDefined(char c)
Return true if the specified Unicode character is defined in the font.


isDefined

public final boolean isDefined(int codepoint)
Return true if the specified Unicode character is defined in the font. This method is identical to isDefined(char) but takes an int, to cater for the new Unicode 4.0 codepoints added in Java 1.5.

Parameters:
codepoint - a Unicode codepoint between U+0000 and U+10FFFD
Since:
2.2.6

getCharWidth

public final int getCharWidth(char c)
Return the width of the specified character in millipoints if the font size was 1 point.

Since:
1.2

getCharWidth

public int getCharWidth(int codepoint)
Return the width of the specified character in millipoints if the font size was 1 point. This method is identical to the getCharWidth(char) method but takes an int to cater for the new Unicode 4.0 codepoints added in Java 1.5.

Parameters:
codepoint - a Unicode codepoint between U+0000 and U+10FFFD
Since:
2.2.6

getBaseName

public String getBaseName()
Return the Base Font Name for this font.


getKerning

public final int getKerning(char c1,
                            char c2)
Get the horizontal character-to-character (or "pair-wise") kerning in this font for the specified characters, in millipoints. This is the distance to move the text cursor left after drawing character c1 in order to correctly position character c2. For many fonts and combinations of characters, this returns zero.

Since:
1.1.14
See Also:
PDFStyle.setTrackKerning(float)

getKerning

public int getKerning(int codepoint1,
                      int codepoint2)
Get the horizontal character-to-character (or "pair-wise") kerning in this font for the specified characters, in millipoints. This method is identical to getKerning(char,char) but takes ints, to handle the new Unicode 4.0 characters defined in Java 1.5

Parameters:
codepoint1 - a Unicode codepoint between U+0000 and U+10FFFD
codepoint2 - a Unicode codepoint between U+0000 and U+10FFFD
Since:
2.2.6

isHorizontal

public final boolean isHorizontal()
Return true if the specified font is written Left-to-Right or Right-to-Left.


isMonospace

public abstract boolean isMonospace()
Return true if every character has the same width (like Courier), false if every character is potentially a different width (like Times-Roman)

Since:
1.1.23

getAscender

public abstract float getAscender()
Get the Ascender for the font (the maximum height above the baseline the font extends), as a proportion of the point size.

Since:
1.1

getDescender

public abstract float getDescender()
Get the Descender for the font (the maximum height below the baseline the font extends), as a proportion of the point size. The returned value is usually negative.

Since:
1.1

getDefaultLeading

public abstract float getDefaultLeading()

Get the default leading for this font - the preferred distance between two successive baselines of text. Values are a ratio of the font size, and are typically between 1 and 1.3

Note that the values of the different spacing-between-lines methods have changed - in versions 1.0.4 and earlier this routine normally returned 1 and the spacing was set by the PDFStyle.setTextLineSpacing(float) method. Since 1.1, the values for these two methods are effectively reversed. See the relevant method comments in the PDFStyle class for more information.


getUnderlineThickness

public abstract float getUnderlineThickness()
Get the underline thickness, as a proportion of the font size.

Since:
1.1

getUnderlinePosition

public abstract float getUnderlinePosition()
Get the underline position, as a proportion of the font size. Like the getDescender() method, the returned value is almost always negative, indicating below the baseline.

Since:
1.1

getStrikeoutThickness

public abstract float getStrikeoutThickness()
Get the strikeout thickness, as a proportion of the font size.

Since:
1.1

getStrikeoutPosition

public abstract float getStrikeoutPosition()
Get the strikeout position, as a proportion of the font size.

Since:
1.1

getSubscriptSize

public abstract float getSubscriptSize()

Get the recommended size of a super/sub script version of this font, as a proportion of the normal font size. Typical value is around 0.6.

For some fonts (like CJK or barcode fonts) where there is no concept of super or subscript, this value is entirely arbitrary.

Since:
1.1

getSuperscriptPosition

public abstract float getSuperscriptPosition()

Get the recommended position of a super-script version of this font, as a proportion of the sub-scripted font size. Value is always positive.

For some fonts (like CJK or barcode fonts) where there is no concept of super or subscript, this value is entirely arbitrary.

Since:
1.1

getSubscriptPosition

public abstract float getSubscriptPosition()

Get the recommended position of a sub-script version of this font, as a proportion of the sub-scripted font size. Value is almost always zero or negative.

For some fonts (like CJK or barcode fonts) where there is no concept of super or subscript, this value is entirely arbitrary.

Since:
1.1

getXHeight

public abstract float getXHeight()
Get the X-Height of the font - normally the height of a lower-case 'x' character

Since:
2.11.18

setFeature

public void setFeature(String feature,
                       boolean on)
Set or clear an optional feature on a font. For most fonts the only possible features are "latinligatures", which controls the use of ligatures for "fi", "fl" and so on, and "kerning" to turn on or off the standard inter-character kerning for fonts (both these default to on). OpenType fonts have more to choose from.

Parameters:
feature - the feature name
on - whether to set or clear the feature
Since:
2.11.21

getAvailableFeatures

public String[] getAvailableFeatures()
Return the list of available features for this font.

Returns:
a list of feature names that can be passed to setFeature(java.lang.String, boolean)
Since:
2.11.22
See Also:
setFeature(java.lang.String, boolean)

getFeature

public boolean getFeature(String feature)
Returns whether the specified feature is currently set

Parameters:
feature - the feature name
Since:
2.11.23

ligaturize

public int ligaturize(char[] buf,
                      int off,
                      int len,
                      Locale locale)
Substitute ligatures into the specified character array where appropriate. Which ligatures are available depends on those that are defined in the font. The zero-width non-joiner (U+200D) can be used to inhibit ligatures Also replaces all instances of the Unicode Line or Paragraph separators (U+2028 and U+2029) with a standard newline character.

Parameters:
buf - the buffer to modify
off - the offset into the buffer for the start of the data
len - the length of the data in the buffer
locale - controls which language the buffer is in. Currently not used.
Returns:
the new length of the buffer - will always be the same (if no substitutions were made) or less than the original length.
Since:
1.2.1

requote

public boolean requote(char[] buf,
                       int off,
                       int len,
                       Locale locale)
Substitute "curly-quotes" into the specified buffer where appropriate. The resulting buffer will be the same length, but may have had it's contents altered. If this font does not have the required quote characters, no substitution is made.

Parameters:
buf - the buffer to modify
off - the offset into the buffer to the start of the data
len - the length of the data in the buffer
locale - determines which style of quote is substituted. Recognized languages are english, dutch, italian, spanish, portuguese, catalan, turkish, czech, german, slovak, danish, swedish, norwegian, finnish, polish and hungarian
Returns:
true if quotes were substituted, false otherwise
Since:
1.2.1

requote

public String requote(String s,
                      Locale l)
Substitute curly quotes into the document. As for requote(char[],int,int,Locale) but returns the end result as a (possibly) new String. Obviously not as efficient, but more convenient

Since:
2.0

ligaturize

public String ligaturize(String s,
                         Locale locale)

Return the specified string with ligatures substituted where appropriate. As for the ligaturize(char[],int,int,Locale) method, but returns an entirely new String. Obviously not as efficient as the other method, but more convenient.

Parameters:
s - the string to ligaturize
locale - controls which language the buffer is in. Currently not used.
Since:
1.1

versionItalic

public PDFFont versionItalic()
Return an italic version of the current font, if available. By default this just returns this font.

Since:
2.11

versionBold

public PDFFont versionBold()
Return a bold version of the current font, if available. By default this just returns this font.

Since:
2.11

versionNonBold

public PDFFont versionNonBold()
Return a non-bold version of the current font, if available. By default this just returns this font.

Since:
2.11

versionNonItalic

public PDFFont versionNonItalic()
Return a non-italic version of the current font, if available. By default this just returns this font.

Since:
2.11

versionRegular

public PDFFont versionRegular()
Return a non-bold, non-italic version of the current font, if available. By default this just returns this font.

Since:
2.11

toString

public String toString()


Copyright © 2001-2012 Big Faceless Organization