Package com.itextpdf.kernel.font
Class PdfFont
- Direct Known Subclasses:
-
PdfSimpleFont
,PdfType0Font
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
true if the font is to be embedded in the PDF.protected static final byte[]
protected FontProgram
protected boolean
false, if the font comes from PdfDocument.static final int
The upper bound value for char code.protected boolean
Indicates if all the glyphs and widths for that particular encoding should be included in the document.protected List
-
Constructor Summary
ModifierConstructorDescriptionprotected
PdfFont()
protected
PdfFont
(PdfDictionary fontDictionary) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSubsetRange
(int[] range) Adds a character range when subsetting.abstract int
appendAnyGlyph
(String text, int from, List<Glyph> glyphs) Append any single glyph, even notdef.boolean
appendDecodedCodesToGlyphsList
(List<Glyph> list, PdfString characterCodes) Decodes sequence of character codes (e.g.abstract int
appendGlyphs
(String text, int from, int to, List<Glyph> glyphs) Append all supported glyphs and return number of processed chars.boolean
containsGlyph
(int unicode) Check whether font contains glyph with specified unicode.abstract byte[]
convertToBytes
(Glyph glyph) abstract byte[]
convertToBytes
(GlyphLine glyphLine) abstract byte[]
convertToBytes
(String text) Converts the text into bytes to be placed in the document.abstract GlyphLine
createGlyphLine
(String content) abstract String
abstract GlyphLine
decodeIntoGlyphLine
(PdfString characterCodes) Decodes sequence of character codes (e.g.void
flush()
To manually flush aPdfObject
behind this wrapper, you have to ensure that this object is added to the document, i.e.int
getAscent
(int unicode, float fontSize) Gets the ascent of a char code in normalized 1000 units.int
Gets the ascent of aString
in points.abstract float
getContentWidth
(PdfString content) int
getDescent
(int unicode, float fontSize) Gets the descent of a char code in points.int
getDescent
(String text, float fontSize) Gets the descent of aString
in points.protected abstract PdfDictionary
getFontDescriptor
(String fontName) abstract Glyph
getGlyph
(int unicode) Get glyph by unicodeprotected PdfStream
getPdfFontStream
(byte[] fontStreamBytes, int[] fontStreamLengths) CreatePdfStream
based onfontStreamBytes
.int
getWidth
(int unicode) Returns the width of a certain character of this font in 1000 normalized units.float
getWidth
(int unicode, float fontSize) Returns the width of a certain character of this font in points.int
Returns the width of a string of this font in 1000 normalized units.float
Gets the width of aString
in points.boolean
isBuiltWith
(String fontProgram, String encoding) Checks whether thePdfFont
was built with corresponding fontProgram and encoding or CMAP.boolean
boolean
isSubset()
Indicates if all the glyphs and widths for that particular encoding should be included in the document.protected boolean
Defines if the object behind this wrapper must be an indirect object in the resultant document.void
setSubset
(boolean subset) Indicates if all the glyphs and widths for that particular encoding should be included in the document.splitString
(String text, float fontSize, float maxWidth) toString()
protected static String
updateSubsetPrefix
(String fontName, boolean isSubset, boolean isEmbedded) Adds a unique subset prefix to be added to the font name when the font is embedded and subsetted.abstract void
writeText
(GlyphLine text, int from, int to, PdfOutputStream stream) abstract void
writeText
(String text, PdfOutputStream stream) Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
Field Details
-
SIMPLE_FONT_MAX_CHAR_CODE_VALUE
public static final int SIMPLE_FONT_MAX_CHAR_CODE_VALUEThe upper bound value for char code. As for simple fonts char codes are a single byte values, it may vary from 0 to 255.- See Also:
-
fontProgram
-
EMPTY_BYTES
protected static final byte[] EMPTY_BYTES -
notdefGlyphs
-
newFont
protected boolean newFontfalse, if the font comes from PdfDocument. -
embedded
protected boolean embeddedtrue if the font is to be embedded in the PDF. -
subset
protected boolean subsetIndicates if all the glyphs and widths for that particular encoding should be included in the document. -
subsetRanges
-
-
Constructor Details
-
PdfFont
-
PdfFont
protected PdfFont()
-
-
Method Details
-
getGlyph
Get glyph by unicode- Parameters:
-
unicode
- a unicode code point - Returns:
-
Glyph
if it exists or .NOTDEF if supported, otherwisenull
.
-
containsGlyph
public boolean containsGlyph(int unicode) Check whether font contains glyph with specified unicode.- Parameters:
-
unicode
- a unicode code point - Returns:
- true if font contains glyph, represented with the unicode code point, otherwise false.
-
createGlyphLine
-
appendGlyphs
Append all supported glyphs and return number of processed chars. Composite font supports surrogate pairs.- 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
Append any single glyph, even notdef. Returns number of processed chars: 2 in case surrogate pair, otherwise 1.- 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
-
convertToBytes
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.- Parameters:
-
text
- the text to convert - Returns:
- the conversion
-
convertToBytes
-
decode
-
decodeIntoGlyphLine
Decodes sequence of character codes (e.g. from content stream) into aGlyphLine
- Parameters:
-
characterCodes
- 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
Decodes sequence of character codes (e.g. from content stream) to sequence of glyphs and appends them to the passed list.- Parameters:
-
list
- the list to the end of which decoded glyphs are to be added -
characterCodes
- 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
-
convertToBytes
-
writeText
-
writeText
-
getWidth
public int getWidth(int unicode) Returns the width of a certain character of this font in 1000 normalized units.- Parameters:
-
unicode
- a certain character. - Returns:
- a width in Text Space.
-
getWidth
public float getWidth(int unicode, float fontSize) Returns the width of a certain character of this font in points.- Parameters:
-
unicode
- a certain character. -
fontSize
- the font size. - Returns:
- a width in points.
-
getWidth
Returns the width of a string of this font in 1000 normalized units.- Parameters:
-
text
- a string content. - Returns:
- a width of string in Text Space.
-
getWidth
Gets the width of aString
in points.- Parameters:
-
text
- theString
to get the width of -
fontSize
- the font size - Returns:
- the width in points
-
getDescent
Gets the descent of aString
in points. The descent will always be less than or equal to zero even if all the characters have an higher descent.- Parameters:
-
text
- theString
to get the descent of -
fontSize
- the font size - Returns:
- the descent in points
-
getDescent
public int getDescent(int unicode, float fontSize) Gets the descent of a char code in points. The descent will always be less than or equal to zero even if all the characters have an higher descent.- Parameters:
-
unicode
- the char code to get the descent of -
fontSize
- the font size - Returns:
- the descent in points
-
getAscent
Gets the ascent of aString
in points. The ascent will always be greater than or equal to zero even if all the characters have a lower ascent.- Parameters:
-
text
- theString
to get the ascent of -
fontSize
- the font size - Returns:
- the ascent in points
-
getAscent
public int getAscent(int unicode, float fontSize) Gets the ascent of a char code in normalized 1000 units. The ascent will always be greater than or equal to zero even if all the characters have a lower ascent.- Parameters:
-
unicode
- the char code to get the ascent of -
fontSize
- the font size - Returns:
- the ascent in points
-
getFontProgram
-
isEmbedded
public boolean isEmbedded() -
isSubset
public boolean isSubset()Indicates if all the glyphs and widths for that particular encoding should be included in the document.- Returns:
-
false
to include all the glyphs and widths.
-
setSubset
public void setSubset(boolean subset) Indicates if all the glyphs and widths for that particular encoding should be included in the document. When set totrue
only the glyphs used will be included in the font. When set tofalse
the full font will be included and all subset ranges will be removed.- Parameters:
-
subset
- new value of property subset - See Also:
-
addSubsetRange
public void addSubsetRange(int[] range) Adds a character range when subsetting. The range is anint
array where the first element is the start range inclusive and the second element is the end range inclusive. Several ranges are allowed in the same array. Note, #setSubset(true) will be called implicitly therefore this range is an addition to the used glyphs.- Parameters:
-
range
- the character range
-
splitString
-
isBuiltWith
Checks whether thePdfFont
was built with corresponding fontProgram and encoding or CMAP. Default value is false unless overridden.- Parameters:
-
fontProgram
- a font name or path to a font program -
encoding
- an encoding or CMAP - Returns:
- true, if the PdfFont was built with the fontProgram and encoding. Otherwise false.
- See Also:
-
flush
public void flush()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.- Overrides:
-
flush
in classPdfObjectWrapper<PdfDictionary>
-
getFontDescriptor
-
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()Description copied from class:PdfObjectWrapper
Defines if the object behind this wrapper must be an indirect object in the resultant document.
If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.
Return value of this method shouldn't depend on any logic, it should return always true or false.- Specified by:
-
isWrappedObjectMustBeIndirect
in classPdfObjectWrapper<PdfDictionary>
- Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
updateSubsetPrefix
Adds a unique subset prefix to be added to the font name when the font is embedded and subsetted.- Parameters:
-
fontName
- the original font name. -
isSubset
- denotes whether font in question is subsetted, i.e. only used symbols are kept in it. -
isEmbedded
- denotes whether font in question is embedded into the PDF document. - Returns:
- the font name prefixed with subset if isSubset and isEmbedded are true, otherwise original font name is returned intact.
-
getPdfFontStream
CreatePdfStream
based onfontStreamBytes
.- Parameters:
-
fontStreamBytes
- original font data, must be not null. -
fontStreamLengths
- array to generateLength*
keys, must be not null. - Returns:
-
the PdfStream containing the font or
null
, if there is an error reading the font. - Throws:
-
PdfException
- Method will throw exception iffontStreamBytes
isnull
.
-
toString
-