Class PdfType3Font
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
-
- com.itextpdf.kernel.font.PdfFont
-
- com.itextpdf.kernel.font.PdfSimpleFont<Type3Font>
-
- com.itextpdf.kernel.font.PdfType3Font
-
public class PdfType3Font extends PdfSimpleFont<Type3Font>
Low-level API class for Type 3 fonts.In Type 3 fonts, glyphs are defined by streams of PDF graphics operators. These streams are associated with character names. A separate encoding entry maps character codes to the appropriate character names for the glyphs.
Note, that this class operates in a special way with glyph space units. In the code when working with fonts, iText expects that 1000 units of glyph-space correspond to 1 unit of text space. For Type3 fonts this is not always the case and depends on FontMatrix. That's why in
PdfType3Font
the font matrix and all font metrics in glyph space units are "normalized" in such way, that 1 to 1000 relation is preserved. This is done on Type3 font initialization, and is reverted back on font flushing, because the actual content streams of type3 font glyphs are left with original coordinates based on original font matrix. See also ISO-32000-2, 9.2.4 "Glyph positioning and metrics":"The glyph coordinate system is the space in which an individual character’s glyph is defined. All path coordinates and metrics shall be interpreted in glyph space. For all font types except Type 3, the units of glyph space are one-thousandth of a unit of text space; for a Type 3 font, the transformation from glyph space to text space shall be defined by a font matrix specified in an explicit FontMatrix entry in the font."
Note, that because of this when processing Type3 glyphs content streams either process them completely independent from this class or take this normalization into account.
To be able to be wrapped with this
PdfObjectWrapper
thePdfObject
must be indirect.
-
-
Field Summary
Fields Modifier and Type Field Description private static double[]
DEFAULT_FONT_MATRIX
private static int
FONT_BBOX_LLX
private static int
FONT_BBOX_LLY
private static int
FONT_BBOX_URX
private static int
FONT_BBOX_URY
private double[]
fontMatrix
private double
glyphSpaceNormalizationFactor
Used to normalize font metrics expressed in glyph space units.-
Fields inherited from class com.itextpdf.kernel.font.PdfSimpleFont
fontEncoding, forceWidthsOutput, toUnicode, usedGlyphs
-
Fields inherited from class com.itextpdf.kernel.font.PdfFont
embedded, EMPTY_BYTES, fontProgram, newFont, notdefGlyphs, SIMPLE_FONT_MAX_CHAR_CODE_VALUE, subset, subsetRanges
-
-
Constructor Summary
Constructors Constructor Description PdfType3Font(PdfDictionary fontDictionary)
Creates a Type 3 font based on an existing font dictionary, which must be an indirect object.PdfType3Font(PdfDocument document, boolean colorized)
Creates a Type 3 font.PdfType3Font(PdfDocument document, java.lang.String fontName, java.lang.String fontFamily, boolean colorized)
Creates a Type 3 font.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addFontStream(PdfDictionary fontDescriptor)
Type3Glyph
addGlyph(char c, int wx, int llx, int lly, int urx, int ury)
Defines a glyph.private void
addGlyphsFromCharProcs(PdfDictionary charProcsDic, int[] widths)
private void
addGlyphsFromDifferences(PdfArray differences, PdfDictionary charProcsDic, int[] widths)
protected PdfArray
buildWidthsArray(int firstChar, int lastChar)
boolean
containsGlyph(int unicode)
Check whether font contains glyph with specified unicode.private void
fillFontDescriptor(PdfDictionary fontDesc)
void
flush()
To manually flush aPdfObject
behind this wrapper, you have to ensure that this object is added to the document, i.e.private void
flushFontData()
protected PdfDocument
getDocument()
private int
getFirstEmptyCode()
Gets the first empty code that could be passed toFontEncoding.addSymbol(int, int)
protected PdfDictionary
getFontDescriptor(java.lang.String fontName)
Generates the font descriptor for this font ornull
if it is one of the 14 built in fonts.private double[]
getFontMatrix()
Gets the transformation matrix that defines relation between text and glyph spaces.Glyph
getGlyph(int unicode)
Get glyph by unicode(package private) double
getGlyphSpaceNormalizationFactor()
int
getNumberOfGlyphs()
Gets count of glyphs in Type 3 font.Type3Glyph
getType3Glyph(int unicode)
Returns aType3Glyph
by unicode.private void
initializeFontBBox(double[] fontBBoxRect)
private void
initializeTypoAscenderDescender(double[] fontBBoxRect)
private int
initializeUsedGlyphs(PdfDictionary fontDictionary)
boolean
isEmbedded()
boolean
isSubset()
Indicates if all the glyphs and widths for that particular encoding should be included in the document.private double
normalize1000UnitsToGlyphSpaceUnits(double value)
private void
normalize1000UnitsToGlyphSpaceUnits(double[] array)
private int
normalizeFirstLastChar(PdfNumber firstLast, int defaultValue)
private double
normalizeGlyphSpaceUnitsTo1000Units(double value)
private void
normalizeGlyphSpaceUnitsTo1000Units(double[] array)
private double[]
readFontBBox()
private double[]
readFontMatrix()
private double[]
readWidths(PdfDictionary fontDictionary)
void
setCapHeight(int capHeight)
Sets cap height.void
setFontFamily(java.lang.String fontFamily)
Sets a preferred font family name.void
setFontName(java.lang.String fontName)
Sets the PostScript name of the font.void
setFontStretch(java.lang.String fontWidth)
Sets font width in css notation (font-stretch property)void
setFontWeight(int fontWeight)
Sets font weight.(package private) void
setGlyphSpaceNormalizationFactor(double glyphSpaceNormalizationFactor)
void
setItalicAngle(int italicAngle)
Sets the PostScript italic angle.void
setPdfFontFlags(int flags)
Sets Font descriptor flags.-
Methods inherited from class com.itextpdf.kernel.font.PdfSimpleFont
appendAnyGlyph, appendDecodedCodesToGlyphsList, appendGlyphs, convertToBytes, convertToBytes, convertToBytes, createGlyphLine, decode, decodeIntoGlyphLine, flushFontData, getContentWidth, getFontEncoding, getToUnicode, isBuiltInFont, isBuiltWith, isForceWidthsOutput, setFontProgram, setForceWidthsOutput, writeText, writeText
-
Methods inherited from class com.itextpdf.kernel.font.PdfFont
addSubsetRange, getAscent, getAscent, getDescent, getDescent, getFontProgram, getPdfFontStream, getWidth, getWidth, getWidth, getWidth, isWrappedObjectMustBeIndirect, makeObjectIndirect, setSubset, splitString, toString, updateSubsetPrefix
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Field Detail
-
FONT_BBOX_LLX
private static final int FONT_BBOX_LLX
- See Also:
- Constant Field Values
-
FONT_BBOX_LLY
private static final int FONT_BBOX_LLY
- See Also:
- Constant Field Values
-
FONT_BBOX_URX
private static final int FONT_BBOX_URX
- See Also:
- Constant Field Values
-
FONT_BBOX_URY
private static final int FONT_BBOX_URY
- See Also:
- Constant Field Values
-
DEFAULT_FONT_MATRIX
private static final double[] DEFAULT_FONT_MATRIX
-
fontMatrix
private double[] fontMatrix
-
glyphSpaceNormalizationFactor
private double glyphSpaceNormalizationFactor
Used to normalize font metrics expressed in glyph space units. SeePdfType3Font
.
-
-
Constructor Detail
-
PdfType3Font
PdfType3Font(PdfDocument document, boolean colorized)
Creates a Type 3 font.- Parameters:
colorized
- defines whether the glyph color is specified in the glyph descriptions in the font.
-
PdfType3Font
PdfType3Font(PdfDocument document, java.lang.String fontName, java.lang.String fontFamily, boolean colorized)
Creates a Type 3 font.- Parameters:
document
- the target document of the new font.fontName
- the PostScript name of the font, shall not be null or empty.fontFamily
- a preferred font family name.colorized
- indicates whether the font will be colorized
-
PdfType3Font
PdfType3Font(PdfDictionary fontDictionary)
Creates a Type 3 font based on an existing font dictionary, which must be an indirect object.- Parameters:
fontDictionary
- a dictionary of type/Font
, must have an indirect reference.
-
-
Method Detail
-
getFontMatrix
private double[] getFontMatrix()
Gets the transformation matrix that defines relation between text and glyph spaces.- Returns:
- the font matrix
-
setFontName
public void setFontName(java.lang.String fontName)
Sets the PostScript name of the font.- Parameters:
fontName
- the PostScript name of the font, shall not be null or empty.
-
setFontFamily
public void setFontFamily(java.lang.String fontFamily)
Sets a preferred font family name.- Parameters:
fontFamily
- a preferred font family name.
-
setFontWeight
public void setFontWeight(int fontWeight)
Sets font weight.- Parameters:
fontWeight
- integer form 100 to 900. SeeFontWeights
.
-
setCapHeight
public void setCapHeight(int capHeight)
Sets cap height.- Parameters:
capHeight
- integer in glyph-space 1000-units
-
setItalicAngle
public void setItalicAngle(int italicAngle)
Sets the PostScript italic angle.Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
- Parameters:
italicAngle
- in counter-clockwise degrees from the vertical
-
setFontStretch
public void setFontStretch(java.lang.String fontWidth)
Sets font width in css notation (font-stretch property)- Parameters:
fontWidth
-FontStretches
.
-
setPdfFontFlags
public void setPdfFontFlags(int flags)
Sets Font descriptor flags.- Parameters:
flags
- font descriptor flags.- See Also:
FontDescriptorFlags
-
getType3Glyph
public Type3Glyph getType3Glyph(int unicode)
Returns aType3Glyph
by unicode.- Parameters:
unicode
- glyph unicode- Returns:
Type3Glyph
glyph, ornull
if this font does not contain glyph for the unicode
-
isSubset
public boolean isSubset()
Description copied from class:PdfFont
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
-
isEmbedded
public boolean isEmbedded()
- Overrides:
isEmbedded
in classPdfFont
-
getNumberOfGlyphs
public int getNumberOfGlyphs()
Gets count of glyphs in Type 3 font.- Returns:
- number of glyphs.
-
addGlyph
public Type3Glyph addGlyph(char c, int wx, int llx, int lly, int urx, int ury)
Defines a glyph. If the character was already defined it will return the same content- Parameters:
c
- the character to match this glyph.wx
- the advance this character will havellx
- the X lower left corner of the glyph bounding box. If thecolorize
option istrue
the value is ignoredlly
- the Y lower left corner of the glyph bounding box. If thecolorize
option istrue
the value is ignoredurx
- the X upper right corner of the glyph bounding box. If thecolorize
option istrue
the value is ignoredury
- the Y upper right corner of the glyph bounding box. If thecolorize
option istrue
the value is ignored- Returns:
- a content where the glyph can be defined
-
getGlyph
public Glyph getGlyph(int unicode)
Description copied from class:PdfFont
Get glyph by unicode
-
containsGlyph
public boolean containsGlyph(int unicode)
Description copied from class:PdfFont
Check whether font contains glyph with specified unicode.- Overrides:
containsGlyph
in classPdfFont
- Parameters:
unicode
- a unicode code point- Returns:
- true if font contains glyph, represented with the unicode code point, otherwise false.
-
flush
public void flush()
Description copied from class:PdfFont
To manually flush aPdfObject
behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference. Basically this means that before flushing you need to explicitly callPdfObjectWrapper.makeIndirect(PdfDocument)
. For example: wrapperInstance.makeIndirect(document).flush(); Note that not every wrapper require this, only those that have such warning in documentation.
-
getFontDescriptor
protected PdfDictionary getFontDescriptor(java.lang.String fontName)
Description copied from class:PdfSimpleFont
Generates the font descriptor for this font ornull
if it is one of the 14 built in fonts.- Overrides:
getFontDescriptor
in classPdfSimpleFont<Type3Font>
- Returns:
- the PdfDictionary containing the font descriptor or
null
.
-
buildWidthsArray
protected PdfArray buildWidthsArray(int firstChar, int lastChar)
- Overrides:
buildWidthsArray
in classPdfSimpleFont<Type3Font>
-
addFontStream
protected void addFontStream(PdfDictionary fontDescriptor)
- Specified by:
addFontStream
in classPdfSimpleFont<Type3Font>
-
getDocument
protected PdfDocument getDocument()
-
getGlyphSpaceNormalizationFactor
final double getGlyphSpaceNormalizationFactor()
-
setGlyphSpaceNormalizationFactor
final void setGlyphSpaceNormalizationFactor(double glyphSpaceNormalizationFactor)
-
addGlyphsFromDifferences
private void addGlyphsFromDifferences(PdfArray differences, PdfDictionary charProcsDic, int[] widths)
-
getFirstEmptyCode
private int getFirstEmptyCode()
Gets the first empty code that could be passed toFontEncoding.addSymbol(int, int)
- Returns:
- code from 1 to 255 or -1 if all slots are busy.
-
addGlyphsFromCharProcs
private void addGlyphsFromCharProcs(PdfDictionary charProcsDic, int[] widths)
-
flushFontData
private void flushFontData()
-
readWidths
private double[] readWidths(PdfDictionary fontDictionary)
-
initializeUsedGlyphs
private int initializeUsedGlyphs(PdfDictionary fontDictionary)
-
readFontBBox
private double[] readFontBBox()
-
readFontMatrix
private double[] readFontMatrix()
-
initializeTypoAscenderDescender
private void initializeTypoAscenderDescender(double[] fontBBoxRect)
-
initializeFontBBox
private void initializeFontBBox(double[] fontBBoxRect)
-
normalizeGlyphSpaceUnitsTo1000Units
private void normalizeGlyphSpaceUnitsTo1000Units(double[] array)
-
normalizeGlyphSpaceUnitsTo1000Units
private double normalizeGlyphSpaceUnitsTo1000Units(double value)
-
normalize1000UnitsToGlyphSpaceUnits
private void normalize1000UnitsToGlyphSpaceUnits(double[] array)
-
normalize1000UnitsToGlyphSpaceUnits
private double normalize1000UnitsToGlyphSpaceUnits(double value)
-
fillFontDescriptor
private void fillFontDescriptor(PdfDictionary fontDesc)
-
normalizeFirstLastChar
private int normalizeFirstLastChar(PdfNumber firstLast, int defaultValue)
-
-