Class Type1Font
- java.lang.Object
-
- org.faceless.pdf2.PDFFont
-
- org.faceless.pdf2.Type1Font
-
- All Implemented Interfaces:
Cloneable
public final class Type1Font extends PDFFont
Create a new PostScript Type 1 font. This class of font is commonly used on UNIX systems. The standard 14 fonts are a special class of Type 1 font.
Type 1 fonts give each character shape, or "glyph", a name, in the same way the PDF documents refer to glyphs by name (hardly surprising really, seeing as both Type 1 fonts and PDF documents are defined by Adobe). Because text written to the PDF via this library is specified in Unicode, Type 1 fonts need a "mapping" from Unicode character to Glyph name.
For many fonts this isn't a problem. Font's based on the latin character set (more specifically, fonts implementing a subset of the Adobe Standard Glyph List) already have their mapping defined. If the glyphs in the font have names taken from this list, no further thought needs to be given to this issue.
If not, it is necessary for the developer to supply a mapping between Unicode character and Glyph name. This is supplied as a
Map
where either the key is aString
representing the name and the value is aCharacter
, or the inverse (the key is aCharacter
and the value aString
). The former ordering is more useful for most Type 1 fonts, the latter was the only format accepted by this class prior to version 2.7.6.- Since:
- 1.0
- See Also:
OpenTypeFont
,StandardFont
-
-
Constructor Summary
Constructors Constructor Description Type1Font(InputStream afm, InputStream pfb)
Create a new Type 1 font, using the standard Adobe mapping from unicode to glyph name.Type1Font(InputStream afm, InputStream pfb, Map<?,?> mapping)
Create a new Type 1 font, using a user defined mapping from unicode to glyph name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description float
getAscender()
Get the Ascender for the font (the maximum height above the baseline the font extends), as a proportion of the point size.float
getCapHeight()
Get the Cap-Height of the font - normally the height of an upper-case 'O' characterfloat
getDefaultLeading()
Get the default leading for this font - the preferred distance between two successive baselines of text.BitSet
getDefinedCodepoints()
Return read-only BitSet containing all the Unicode codepoints defined in this fontfloat
getDescender()
Get the Descender for the font (the maximum height below the baseline the font extends), as a proportion of the point size.float
getStrikeoutPosition()
Get the strikeout position, as a proportion of the font size.float
getStrikeoutThickness()
Get the strikeout thickness, as a proportion of the font size.float
getSubscriptPosition()
Get the recommended position of a sub-script version of this font, as a proportion of the sub-scripted font size.float
getSubscriptSize()
Get the recommended size of a super/sub script version of this font, as a proportion of the normal font size.float
getSuperscriptPosition()
Get the recommended position of a super-script version of this font, as a proportion of the sub-scripted font size.float
getUnderlinePosition()
Get the underline position, as a proportion of the font size.float
getUnderlineThickness()
Get the underline thickness, as a proportion of the font size.float
getXHeight()
Get the X-Height of the font - normally the height of a lower-case 'x' character.boolean
isBold()
Return true if the font is boldboolean
isEmbedded()
Return true if this font is Embeddedboolean
isItalic()
Return true if the font is italicboolean
isMonospace()
Return true if every character has the same width (like Courier), false if every character is potentially a different width (like Times-Roman)boolean
isSerif()
Return true if the font is serifvoid
putLiteral(String key, String tokens)
Put a literal token sequnce.String
toString()
-
Methods inherited from class org.faceless.pdf2.PDFFont
clone, getAvailableFeatures, getBaseName, getBottom, getCharWidth, getCharWidth, getFeature, getKerning, getKerning, getLeft, getMetaData, getRight, getTop, getXMP, hasFeature, isDefined, isDefined, isHorizontal, isSubset, setFeature, setFeature, setMetaData, versionBold, versionItalic, versionNonBold, versionNonItalic, versionRegular
-
-
-
-
Field Detail
-
AGL
public static final Map<String,String> AGL
ThisMap
represents the Adobe Standard Glyph Lists. Some fonts which claim to be encoded using the Adobe Standard Glyph mapping deviate from the list slightly. Using this Map you can easily create a slight variation on the standard mapping to pass into the Type 1 constructor. For example, lets say your font has a glyph called "hyphenminus" instead of the standard name "hyphen". You could create the font like so:Map mymap = new HashMap(Type1Font.AGL); mymap.put("hyphenminus", new Character('-')); PDFFont myfont = new Type1Font(afmfile, pfbfile, mymap);
- Since:
- 2.1
-
-
Constructor Detail
-
Type1Font
public Type1Font(InputStream afm, InputStream pfb) throws IOException
Create a new Type 1 font, using the standard Adobe mapping from unicode to glyph name.- Parameters:
afm
- The.afm
(Adobe Font Metrics) file specifying the metrics for this fontpfb
- The.pfb
or.pfa
file containing the glyph shapes to be embedded in the PDF. If the font is not to be embedded, this should be null.- Throws:
IOException
- If the.afm
or.pfb
InputStream can't be read or parsed
-
Type1Font
public Type1Font(InputStream afm, InputStream pfb, Map<?,?> mapping) throws IOException
Create a new Type 1 font, using a user defined mapping from unicode to glyph name. The font can be embedded, which ensures that your viewers will see exactly the font you specified, at the cost of increasing the file size. If a font is not embedded and the viewer does not have the same font installed, the viewing software will substitute an "appropriate" font.
- Parameters:
afm
- The.afm
(Adobe Font Metrics) file specifying the metrics for this fontpfb
- The.pfb
or.pfa
file containing the glyph shapes to be embedded in the PDF. If the font is not to be embedded, this should be null.mapping
- The mapping between unicode and glyph name, as described in the class header above. A value ofnull
uses the Adobe Standard Glyph List- Throws:
IOException
- If the.afm
or.pfb
file can't be read or parsed
-
-
Method Detail
-
getDefaultLeading
public float getDefaultLeading()
Description copied from class:PDFFont
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 thePDFStyle
class for more information.- Specified by:
getDefaultLeading
in classPDFFont
-
getSubscriptPosition
public float getSubscriptPosition()
Description copied from class:PDFFont
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.
- Specified by:
getSubscriptPosition
in classPDFFont
-
getSuperscriptPosition
public float getSuperscriptPosition()
Description copied from class:PDFFont
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.
- Specified by:
getSuperscriptPosition
in classPDFFont
-
getSubscriptSize
public float getSubscriptSize()
Description copied from class:PDFFont
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.
- Specified by:
getSubscriptSize
in classPDFFont
-
getStrikeoutThickness
public float getStrikeoutThickness()
Description copied from class:PDFFont
Get the strikeout thickness, as a proportion of the font size.- Specified by:
getStrikeoutThickness
in classPDFFont
-
getStrikeoutPosition
public float getStrikeoutPosition()
Description copied from class:PDFFont
Get the strikeout position, as a proportion of the font size. The value is the distance from the baseline to the center of the strikeout, and shuold be positive.- Specified by:
getStrikeoutPosition
in classPDFFont
-
getUnderlineThickness
public float getUnderlineThickness()
Description copied from class:PDFFont
Get the underline thickness, as a proportion of the font size.- Specified by:
getUnderlineThickness
in classPDFFont
-
getUnderlinePosition
public float getUnderlinePosition()
Description copied from class:PDFFont
Get the underline position, as a proportion of the font size. Like thegetDescender()
method, the returned value is almost always negative, indicating below the baseline. The distance is from the baseline to the center of the underline.- Specified by:
getUnderlinePosition
in classPDFFont
-
getAscender
public float getAscender()
Description copied from class:PDFFont
Get the Ascender for the font (the maximum height above the baseline the font extends), as a proportion of the point size. The exact source of of this value is undefined except for OpenTypeFonts, where it comes from the "hhea.ascender" value normally, or the from "OS2.sTypoAscender" flag if the USE_TYPO_METRICS flag is set.- Specified by:
getAscender
in classPDFFont
-
getDescender
public float getDescender()
Description copied from class:PDFFont
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. The exact source of this value is undefined except for OpenTypeFonts, where it comes from the "hhea.descender" value normally, or the from "OS2.sTypoDescender" flag if the USE_TYPO_METRICS flag is set.- Specified by:
getDescender
in classPDFFont
-
getXHeight
public float getXHeight()
Description copied from class:PDFFont
Get the X-Height of the font - normally the height of a lower-case 'x' character.- Specified by:
getXHeight
in classPDFFont
-
getCapHeight
public float getCapHeight()
Description copied from class:PDFFont
Get the Cap-Height of the font - normally the height of an upper-case 'O' character- Specified by:
getCapHeight
in classPDFFont
-
isMonospace
public boolean isMonospace()
Description copied from class:PDFFont
Return true if every character has the same width (like Courier), false if every character is potentially a different width (like Times-Roman)- Specified by:
isMonospace
in classPDFFont
-
isItalic
public boolean isItalic()
Description copied from class:PDFFont
Return true if the font is italic
-
isBold
public boolean isBold()
Description copied from class:PDFFont
Return true if the font is bold
-
isSerif
public boolean isSerif()
Description copied from class:PDFFont
Return true if the font is serif
-
isEmbedded
public boolean isEmbedded()
Description copied from class:PDFFont
Return true if this font is Embedded- Overrides:
isEmbedded
in classPDFFont
-
getDefinedCodepoints
public BitSet getDefinedCodepoints()
Description copied from class:PDFFont
Return read-only BitSet containing all the Unicode codepoints defined in this font- Specified by:
getDefinedCodepoints
in classPDFFont
-
toString
public String toString()
-
-