Package com.itextpdf.kernel.font
Class PdfFont
- Direct Known Subclasses:
-
PdfSimpleFont,PdfType0Font
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleantrue if the font is to be embedded in the PDF.protected static final byte[]protected FontProgramprotected booleanfalse, if the font comes from PdfDocument.static final intThe upper bound value for char code.protected booleanIndicates if all the glyphs and widths for that particular encoding should be included in the document.protected List -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPdfFont()protectedPdfFont(PdfDictionary fontDictionary) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSubsetRange(int[] range) Adds a character range when subsetting.abstract intappendAnyGlyph(String text, int from, List<Glyph> glyphs) Append any single glyph, even notdef.booleanappendDecodedCodesToGlyphsList(List<Glyph> list, PdfString characterCodes) Decodes sequence of character codes (e.g.abstract intappendGlyphs(String text, int from, int to, List<Glyph> glyphs) Append all supported glyphs and return number of processed chars.booleancontainsGlyph(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 GlyphLinecreateGlyphLine(String content) abstract Stringabstract GlyphLinedecodeIntoGlyphLine(PdfString characterCodes) Decodes sequence of character codes (e.g.voidflush()To manually flush aPdfObjectbehind this wrapper, you have to ensure that this object is added to the document, i.e.floatgetAscent(int unicode, float fontSize) Gets the ascent of a char code in normalized 1000 units.floatGets the ascent of aStringin points.abstract floatgetContentWidth(PdfString content) floatgetDescent(int unicode, float fontSize) Gets the descent of a char code in points.floatgetDescent(String text, float fontSize) Gets the descent of aStringin points.protected abstract PdfDictionarygetFontDescriptor(String fontName) abstract GlyphgetGlyph(int unicode) Get glyph by unicodeprotected PdfStreamgetPdfFontStream(byte[] fontStreamBytes, int[] fontStreamLengths) CreatePdfStreambased onfontStreamBytes.intgetWidth(int unicode) Returns the width of a certain character of this font in 1000 normalized units.floatgetWidth(int unicode, float fontSize) Returns the width of a certain character of this font in points.intReturns the width of a string of this font in 1000 normalized units.floatGets the width of aStringin points.booleanisBuiltWith(String fontProgram, String encoding) Checks whether thePdfFontwas built with corresponding fontProgram and encoding or CMAP.booleanbooleanisSubset()Indicates if all the glyphs and widths for that particular encoding should be included in the document.protected booleanDefines if the object behind this wrapper must be an indirect object in the resultant document.voidsetSubset(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 StringupdateSubsetPrefix(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 voidwriteText(GlyphLine text, int from, int to, PdfOutputStream stream) abstract voidwriteText(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:
-
Glyphif 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, thatPdfStringacts 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
GlyphLinecontaining 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, thatPdfStringacts 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 aStringin points.- Parameters:
-
text- theStringto get the width of -
fontSize- the font size - Returns:
- the width in points
-
getDescent
Gets the descent of aStringin points. The descent will always be less than or equal to zero even if all the characters have a higher descent.- Parameters:
-
text- theStringto get the descent of -
fontSize- the font size - Returns:
- the descent in points
-
getDescent
public float 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 a 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 aStringin points. The ascent will always be greater than or equal to zero even if all the characters have a lower ascent.- Parameters:
-
text- theStringto get the ascent of -
fontSize- the font size - Returns:
- the ascent in points
-
getAscent
public float 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:
-
falseto 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 totrueonly the glyphs used will be included in the font. When set tofalsethe 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 anintarray 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 thePdfFontwas 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 aPdfObjectbehind 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:
-
flushin classPdfObjectWrapper<PdfDictionary>
-
getFontDescriptor
-
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()Description copied from class:PdfObjectWrapperDefines 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:
-
isWrappedObjectMustBeIndirectin 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
CreatePdfStreambased 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 iffontStreamBytesisnull.
-
toString
-