Class PdfType3Font
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
the PdfObject
must be indirect.
-
Field Summary
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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addFontStream
(PdfDictionary fontDescriptor) addGlyph
(char c, int wx, int llx, int lly, int urx, int ury) Defines a glyph.protected PdfArray
buildWidthsArray
(int firstChar, int lastChar) boolean
containsGlyph
(int unicode) Check whether font contains glyph with specified unicode.void
flush()
To manually flush aPdfObject
behind this wrapper, you have to ensure that this object is added to the document, i.e.protected PdfDocument
protected PdfDictionary
getFontDescriptor
(String fontName) Generates the font descriptor for this font ornull
if it is one of the 14 built in fonts.getGlyph
(int unicode) Get glyph by unicodeint
Gets count of glyphs in Type 3 font.getType3Glyph
(int unicode) Returns aType3Glyph
by unicode.boolean
boolean
isSubset()
Indicates if all the glyphs and widths for that particular encoding should be included in the document.void
setCapHeight
(int capHeight) Sets cap height.void
setFontFamily
(String fontFamily) Sets a preferred font family name.void
setFontName
(String fontName) Sets the PostScript name of the font.void
setFontStretch
(String fontWidth) Sets font width in css notation (font-stretch property)void
setFontWeight
(int fontWeight) Sets font weight.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, setSubset, splitString, toString, updateSubsetPrefix
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
Method Details
-
setFontName
Sets the PostScript name of the font.- Parameters:
-
fontName
- the PostScript name of the font, shall not be null or empty.
-
setFontFamily
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
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:
-
getType3Glyph
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
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 have -
llx
- the X lower left corner of the glyph bounding box. If thecolorize
option istrue
the value is ignored -
lly
- the Y lower left corner of the glyph bounding box. If thecolorize
option istrue
the value is ignored -
urx
- the X upper right corner of the glyph bounding box. If thecolorize
option istrue
the value is ignored -
ury
- 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
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
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
- Overrides:
-
buildWidthsArray
in classPdfSimpleFont<Type3Font>
-
addFontStream
- Specified by:
-
addFontStream
in classPdfSimpleFont<Type3Font>
-
getDocument
-