Package com.itextpdf.kernel.font
Class PdfSimpleFont<T extends FontProgram>
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
-
- com.itextpdf.kernel.font.PdfFont
-
- com.itextpdf.kernel.font.PdfSimpleFont<T>
-
- Direct Known Subclasses:
PdfTrueTypeFont
,PdfType1Font
,PdfType3Font
public abstract class PdfSimpleFont<T extends FontProgram> extends PdfFont
-
-
Field Summary
Fields Modifier and Type Field Description protected FontEncoding
fontEncoding
protected boolean
forceWidthsOutput
Forces the output of the width array.protected CMapToUnicode
toUnicode
Currently only exists for the fonts that are parsed from the document.protected byte[]
usedGlyphs
The array used with single byte encodings.-
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 Modifier Constructor Description protected
PdfSimpleFont()
protected
PdfSimpleFont(PdfDictionary fontDictionary)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
addFontStream(PdfDictionary fontDescriptor)
int
appendAnyGlyph(java.lang.String text, int from, java.util.List<Glyph> glyphs)
Append any single glyph, even notdef.boolean
appendDecodedCodesToGlyphsList(java.util.List<Glyph> list, PdfString characterCodes)
Decodes sequence of character codes (e.g.int
appendGlyphs(java.lang.String text, int from, int to, java.util.List<Glyph> glyphs)
Append all supported glyphs and return number of processed chars.protected PdfArray
buildWidthsArray(int firstChar, int lastChar)
byte[]
convertToBytes(Glyph glyph)
byte[]
convertToBytes(GlyphLine glyphLine)
byte[]
convertToBytes(java.lang.String text)
Converts the text into bytes to be placed in the document.GlyphLine
createGlyphLine(java.lang.String content)
java.lang.String
decode(PdfString content)
GlyphLine
decodeIntoGlyphLine(PdfString content)
Decodes sequence of character codes (e.g.protected void
flushFontData(java.lang.String fontName, PdfName subtype)
float
getContentWidth(PdfString content)
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.FontEncoding
getFontEncoding()
Get the font encoding.CMapToUnicode
getToUnicode()
Get the mapping of character codes to unicode values based on /ToUnicode entry of font dictionary.private boolean
isAppendableGlyph(Glyph glyph)
Checks whether the glyph is appendable, i.e.protected boolean
isBuiltInFont()
Indicates that the font is built in, i.e.boolean
isBuiltWith(java.lang.String fontProgram, java.lang.String encoding)
Checks whether thePdfFont
was built with corresponding fontProgram and encoding or CMAP.boolean
isForceWidthsOutput()
Gets the state of the property.protected void
setFontProgram(T fontProgram)
void
setForceWidthsOutput(boolean forceWidthsOutput)
Set totrue
to force the generation of the widths array.void
writeText(GlyphLine text, int from, int to, PdfOutputStream stream)
void
writeText(java.lang.String text, PdfOutputStream stream)
-
Methods inherited from class com.itextpdf.kernel.font.PdfFont
addSubsetRange, containsGlyph, flush, getAscent, getAscent, getDescent, getDescent, getFontProgram, getGlyph, getPdfFontStream, getWidth, getWidth, getWidth, getWidth, isEmbedded, isSubset, 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
-
fontEncoding
protected FontEncoding fontEncoding
-
forceWidthsOutput
protected boolean forceWidthsOutput
Forces the output of the width array. Only matters for the 14 built-in fonts.
-
usedGlyphs
protected byte[] usedGlyphs
The array used with single byte encodings.
-
toUnicode
protected CMapToUnicode toUnicode
Currently only exists for the fonts that are parsed from the document. In the future, we might provide possibility to add custom mappings after a font has been created from a font file.
-
-
Constructor Detail
-
PdfSimpleFont
protected PdfSimpleFont(PdfDictionary fontDictionary)
-
PdfSimpleFont
protected PdfSimpleFont()
-
-
Method Detail
-
isBuiltWith
public boolean isBuiltWith(java.lang.String fontProgram, java.lang.String encoding)
Description copied from class:PdfFont
Checks whether thePdfFont
was built with corresponding fontProgram and encoding or CMAP. Default value is false unless overridden.- Overrides:
isBuiltWith
in classPdfFont
- Parameters:
fontProgram
- a font name or path to a font programencoding
- an encoding or CMAP- Returns:
- true, if the PdfFont was built with the fontProgram and encoding. Otherwise false.
- See Also:
PdfDocument.findFont(String, String)
,FontProgram.isBuiltWith(String)
,FontEncoding.isBuiltWith(String)
,CMapEncoding.isBuiltWith(String)
-
createGlyphLine
public GlyphLine createGlyphLine(java.lang.String content)
- Specified by:
createGlyphLine
in classPdfFont
-
appendGlyphs
public int appendGlyphs(java.lang.String text, int from, int to, java.util.List<Glyph> glyphs)
Description copied from class:PdfFont
Append all supported glyphs and return number of processed chars. Composite font supports surrogate pairs.- Specified by:
appendGlyphs
in classPdfFont
- Parameters:
text
- String to convert to glyphs.from
- from index of the text.to
- to index of the text.glyphs
- array for a new glyphs, shall not be null.- Returns:
- number of processed chars from text.
-
appendAnyGlyph
public int appendAnyGlyph(java.lang.String text, int from, java.util.List<Glyph> glyphs)
Description copied from class:PdfFont
Append any single glyph, even notdef. Returns number of processed chars: 2 in case surrogate pair, otherwise 1.- Specified by:
appendAnyGlyph
in classPdfFont
- Parameters:
text
- String to convert to glyphs.from
- from index of the text.glyphs
- array for a new glyph, shall not be null.- Returns:
- number of processed chars: 2 in case surrogate pair, otherwise 1
-
isAppendableGlyph
private boolean isAppendableGlyph(Glyph glyph)
Checks whether the glyph is appendable, i.e. has valid unicode and code values.- Parameters:
glyph
- not-nullGlyph
-
getFontEncoding
public FontEncoding getFontEncoding()
Get the font encoding.- Returns:
- the
FontEncoding
-
getToUnicode
public CMapToUnicode getToUnicode()
Get the mapping of character codes to unicode values based on /ToUnicode entry of font dictionary.- Returns:
- the
CMapToUnicode
built based on /ToUnicode, or null if /ToUnicode is not available
-
convertToBytes
public byte[] convertToBytes(java.lang.String text)
Description copied from class:PdfFont
Converts the text into bytes to be placed in the document. The conversion is done according to the font and the encoding and the characters used are stored.- Specified by:
convertToBytes
in classPdfFont
- Parameters:
text
- the text to convert- Returns:
- the conversion
-
convertToBytes
public byte[] convertToBytes(GlyphLine glyphLine)
- Specified by:
convertToBytes
in classPdfFont
-
convertToBytes
public byte[] convertToBytes(Glyph glyph)
- Specified by:
convertToBytes
in classPdfFont
-
writeText
public void writeText(GlyphLine text, int from, int to, PdfOutputStream stream)
-
writeText
public void writeText(java.lang.String text, PdfOutputStream stream)
-
decodeIntoGlyphLine
public GlyphLine decodeIntoGlyphLine(PdfString content)
Decodes sequence of character codes (e.g. from content stream) into aGlyphLine
- Specified by:
decodeIntoGlyphLine
in classPdfFont
- Parameters:
content
- the string which is interpreted as a sequence of character codes. Note, thatPdfString
acts as a storage for char code values specific to given font, therefore individual character codes must not be interpreted as code units of the UTF-16 encoding- Returns:
- the
GlyphLine
containing the glyphs encoded by the passed string
-
appendDecodedCodesToGlyphsList
public boolean appendDecodedCodesToGlyphsList(java.util.List<Glyph> list, PdfString characterCodes)
Decodes sequence of character codes (e.g. from content stream) to sequence of glyphs and appends them to the passed list.- Overrides:
appendDecodedCodesToGlyphsList
in classPdfFont
- Parameters:
list
- the list to the end of which decoded glyphs are to be addedcharacterCodes
- the string which is interpreted as a sequence of character codes. Note, thatPdfString
acts as a storage for char code values specific to given font, therefore individual character codes must not be interpreted as code units of the UTF-16 encoding- Returns:
- true if all codes where successfully decoded, false otherwise
-
getContentWidth
public float getContentWidth(PdfString content)
- Specified by:
getContentWidth
in classPdfFont
-
isForceWidthsOutput
public boolean isForceWidthsOutput()
Gets the state of the property.- Returns:
- value of property forceWidthsOutput
-
setForceWidthsOutput
public void setForceWidthsOutput(boolean forceWidthsOutput)
Set totrue
to force the generation of the widths array.- Parameters:
forceWidthsOutput
-true
to force the generation of the widths array
-
flushFontData
protected void flushFontData(java.lang.String fontName, PdfName subtype)
-
isBuiltInFont
protected boolean isBuiltInFont()
Indicates that the font is built in, i.e. it is one of the 14 Standard fonts- Returns:
true
in case the font is a Standard font andfalse
otherwise
-
getFontDescriptor
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.- Specified by:
getFontDescriptor
in classPdfFont
- Returns:
- the PdfDictionary containing the font descriptor or
null
.
-
buildWidthsArray
protected PdfArray buildWidthsArray(int firstChar, int lastChar)
-
addFontStream
protected abstract void addFontStream(PdfDictionary fontDescriptor)
-
setFontProgram
protected void setFontProgram(T fontProgram)
-
-