Package com.itextpdf.io.font
Class FontProgram
java.lang.Object
com.itextpdf.io.font.FontProgram
- Direct Known Subclasses:
-
CidFont,TrueTypeFont,Type1Font,Type3Font
Base representation of a font program and its glyph, naming, and metric data.
Glyph metrics exposed by this abstraction use the normalized 1000-unit PDF glyph space.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intAverage glyph width in normalized glyph units.static final intprotected StringThe font's encoding name.protected FontIdentificationprotected FontMetricsMetrics extracted from the font program.protected FontNamesNaming data extracted from the font program.static final intprotected booleanIndicates that character codes are interpreted using the font's built-in encoding rather than a Unicode-oriented encoding.protected StringCID registry name associated with this font, ornullfor fonts without a CID registry.static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleconvertGlyphSpaceToTextSpace(double value) Converts a normalized glyph-space value to PDF text space without losing double precision.static floatconvertGlyphSpaceToTextSpace(float value) Converts a normalized glyph-space value to PDF text space.static intconvertGlyphSpaceToTextSpace(int value) Converts an integral normalized glyph-space value to PDF text space.static floatconvertTextSpaceToGlyphSpace(float value) Converts a PDF text-space value to normalized glyph space.intGets the amount of glyphs in this font program.protected voidEnsures that an existing Unicode space glyph is also addressable through its font code.intGets the average glyph width.int[]getCharBBox(int unicode) Get glyph's bbox.Gets the parsed font identification data.Gets the parsed font metric data.Gets the parsed font naming data.getGlyph(int unicode) Looks up a glyph by Unicode value.getGlyphByCode(int charCode) Looks up a glyph by its format-specific code.intgetKerning(int first, int second) Gets the kerning between two glyphs.abstract intgetKerning(Glyph first, Glyph second) Gets the kerning between two glyphs.abstract intComputes the PDF font descriptor flags for this program.Gets the CID registry name.intgetWidth(int unicode) Get glyph's width.booleanChecks whether this program supplies kerning pairs.booleanisBuiltWith(String fontName) Checks whether theFontProgramwas built with corresponding fontName.booleanChecks whether this program uses its built-in character encoding.protected voidsetBbox(int[] bbox) Sets the normalized font bounding box from a four-element coordinate array.protected voidsetBold(boolean isBold) protected voidsetCapHeight(int capHeight) Sets the capital letters height.protected voidsetFixedPitch(boolean isFixedPitch) Sets whether the font declares a fixed width.protected voidsetFontFamily(String fontFamily) Sets a preferred font family name.protected voidsetFontName(String fontName) Sets the PostScript name of the font.protected voidsetFontStretch(String fontWidth) Sets font width in css notation (font-stretch property)protected voidsetFontWeight(int fontWeight) Sets font weight.protected voidsetItalicAngle(int italicAngle) Sets the PostScript italic angle.protected voidsetRegistry(String registry) Sets the CID registry associated with this font program.protected voidsetStemH(int stemH) Sets the dominant horizontal stem width.protected voidsetStemV(int stemV) Sets the dominant vertical stem width.protected voidsetTypoAscender(int ascender) Sets typo ascender.protected voidsetTypoDescender(int descender) Sets typo descender.protected voidsetXHeight(int xHeight) Sets the x-height in source font units.toString()
-
Field Details
-
HORIZONTAL_SCALING_FACTOR
public static final int HORIZONTAL_SCALING_FACTOR- See Also:
-
DEFAULT_WIDTH
public static final int DEFAULT_WIDTH- See Also:
-
UNITS_NORMALIZATION
public static final int UNITS_NORMALIZATION- See Also:
-
codeToGlyph
-
unicodeToGlyph
-
isFontSpecific
protected boolean isFontSpecificIndicates that character codes are interpreted using the font's built-in encoding rather than a Unicode-oriented encoding. -
fontNames
Naming data extracted from the font program. -
fontMetrics
Metrics extracted from the font program. -
fontIdentification
-
avgWidth
protected int avgWidthAverage glyph width in normalized glyph units. -
encodingScheme
The font's encoding name. This encoding is 'StandardEncoding' or 'AdobeStandardEncoding' for a font that can be totally encoded according to the characters names. For all other names the font is treated as symbolic. -
registry
CID registry name associated with this font, ornullfor fonts without a CID registry.
-
-
Constructor Details
-
FontProgram
public FontProgram()
-
-
Method Details
-
convertTextSpaceToGlyphSpace
public static float convertTextSpaceToGlyphSpace(float value) Converts a PDF text-space value to normalized glyph space.- Parameters:
-
value- value in text space - Returns:
-
value divided by
UNITS_NORMALIZATION
-
convertGlyphSpaceToTextSpace
public static float convertGlyphSpaceToTextSpace(float value) Converts a normalized glyph-space value to PDF text space.- Parameters:
-
value- value in normalized glyph space - Returns:
-
value multiplied by
UNITS_NORMALIZATION
-
convertGlyphSpaceToTextSpace
public static double convertGlyphSpaceToTextSpace(double value) Converts a normalized glyph-space value to PDF text space without losing double precision.- Parameters:
-
value- value in normalized glyph space - Returns:
-
value multiplied by
UNITS_NORMALIZATION
-
convertGlyphSpaceToTextSpace
public static int convertGlyphSpaceToTextSpace(int value) Converts an integral normalized glyph-space value to PDF text space.- Parameters:
-
value- value in normalized glyph space - Returns:
-
value multiplied by
UNITS_NORMALIZATION
-
countOfGlyphs
public int countOfGlyphs()Gets the amount of glyphs in this font program.- Returns:
- the amount of glyphs in this font program
-
getFontNames
Gets the parsed font naming data.- Returns:
- naming data owned by this program
-
getFontMetrics
Gets the parsed font metric data.- Returns:
- metric data owned by this program
-
getFontIdentification
Gets the parsed font identification data.- Returns:
- identification data owned by this program
-
getRegistry
Gets the CID registry name.- Returns:
-
CID registry, or
nullwhen none was supplied
-
getPdfFontFlags
public abstract int getPdfFontFlags()Computes the PDF font descriptor flags for this program.- Returns:
- bit set defined by the PDF font descriptor specification
-
isFontSpecific
public boolean isFontSpecific()Checks whether this program uses its built-in character encoding.- Returns:
-
truewhen character codes are font-specific
-
getWidth
public int getWidth(int unicode) Get glyph's width.- Parameters:
-
unicode- a unicode symbol or FontSpecif code. - Returns:
- Gets width in normalized 1000 units.
-
getAvgWidth
public int getAvgWidth()Gets the average glyph width.- Returns:
- average width in normalized glyph units
-
getCharBBox
public int[] getCharBBox(int unicode) Get glyph's bbox.- Parameters:
-
unicode- a unicode symbol or FontSpecif code. - Returns:
- Gets bbox in normalized 1000 units.
-
getGlyph
Looks up a glyph by Unicode value.- Parameters:
-
unicode- Unicode scalar value - Returns:
-
matching glyph, or
nullwhen unmapped
-
getGlyphByCode
Looks up a glyph by its format-specific code.- Parameters:
-
charCode- Type 1 character code or OpenType glyph index - Returns:
-
matching glyph, or
nullwhen absent
-
hasKernPairs
public boolean hasKernPairs()Checks whether this program supplies kerning pairs.- Returns:
-
trueif supplies,falseotherwise
-
getKerning
public int getKerning(int first, int second) Gets the kerning between two glyphs.- Parameters:
-
first- the first unicode value -
second- the second unicode value - Returns:
- the kerning to be applied
-
getKerning
Gets the kerning between two glyphs.- Parameters:
-
first- the first glyph -
second- the second glyph - Returns:
- the kerning to be applied
-
isBuiltWith
Checks whether theFontProgramwas built with corresponding fontName. Default value is false unless overridden.- Parameters:
-
fontName- a font name or path to a font program - Returns:
- true, if the FontProgram was built with the fontProgram. Otherwise false.
-
setRegistry
Sets the CID registry associated with this font program.- Parameters:
-
registry- CID registry name, ornullwhen unavailable
-
setTypoAscender
protected void setTypoAscender(int ascender) Sets typo ascender. See alsoFontMetrics.setTypoAscender(int).- Parameters:
-
ascender- typo ascender value in 1000-units
-
setTypoDescender
protected void setTypoDescender(int descender) Sets typo descender. See alsoFontMetrics.setTypoDescender(int).- Parameters:
-
descender- typo descender value in 1000-units
-
setCapHeight
protected void setCapHeight(int capHeight) Sets the capital letters height. See alsoFontMetrics.setCapHeight(int).- Parameters:
-
capHeight- cap height in 1000-units
-
setXHeight
protected void setXHeight(int xHeight) Sets the x-height in source font units.- Parameters:
-
xHeight- height of lowercase flat characters above the baseline
-
setItalicAngle
protected void setItalicAngle(int italicAngle) Sets the PostScript italic angle.Italic angle in counterclockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
- Parameters:
-
italicAngle- in counterclockwise degrees from the vertical
-
setStemV
protected void setStemV(int stemV) Sets the dominant vertical stem width.- Parameters:
-
stemV- Type 1/CFFStdVWvalue in glyph units
-
setStemH
protected void setStemH(int stemH) Sets the dominant horizontal stem width.- Parameters:
-
stemH- Type 1/CFFStdHWvalue in glyph units
-
setFontWeight
protected void setFontWeight(int fontWeight) Sets font weight.- Parameters:
-
fontWeight- integer form 100 to 900. SeeFontWeights.
-
setFontStretch
Sets font width in css notation (font-stretch property)- Parameters:
-
fontWidth-FontStretches.
-
setFixedPitch
protected void setFixedPitch(boolean isFixedPitch) Sets whether the font declares a fixed width.- Parameters:
-
isFixedPitch-truefor a monospaced font
-
setBold
protected void setBold(boolean isBold) -
setBbox
protected void setBbox(int[] bbox) Sets the normalized font bounding box from a four-element coordinate array.- Parameters:
-
bbox- lower-left x/y and upper-right x/y coordinates
-
setFontFamily
Sets a preferred font family name.- Parameters:
-
fontFamily- a preferred font family name.
-
setFontName
Sets the PostScript name of the font.If full name is null, it will be set as well.
- Parameters:
-
fontName- the PostScript name of the font, shall not be null or empty.
-
fixSpaceIssue
protected void fixSpaceIssue()Ensures that an existing Unicode space glyph is also addressable through its font code. -
toString
-