public abstract class PdfFont extends PdfObjectWrapper<PdfDictionary>
Modifier and Type | Field and Description |
---|---|
protected static double[] |
DEFAULT_FONT_MATRIX
Deprecated.
|
protected boolean |
embedded
true if the font is to be embedded in the PDF.
|
protected static byte[] |
EMPTY_BYTES |
protected FontProgram |
fontProgram |
protected boolean |
newFont
false, if the font comes from PdfDocument.
|
protected Map<Integer,Glyph> |
notdefGlyphs |
static int |
SIMPLE_FONT_MAX_CHAR_CODE_VALUE
The upper bound value for char code.
|
protected boolean |
subset
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
|
protected List |
subsetRanges |
Modifier | Constructor and Description |
---|---|
protected |
PdfFont() |
protected |
PdfFont(PdfDictionary fontDictionary) |
Modifier and Type | Method and Description |
---|---|
void |
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.
|
protected static int[] |
compactRanges(List
Deprecated.
The logic has been moved to
TrueTypeFont .
|
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 |
decode(PdfString content) |
abstract GlyphLine |
decodeIntoGlyphLine(PdfString characterCodes)
Decodes sequence of character codes (e.g.
|
void |
flush()
To manually flush a PdfObject 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 |
getAscent(String text, float fontSize)
Gets the ascent of a String 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 a String in points.
|
protected abstract PdfDictionary |
getFontDescriptor(String fontName) |
double[] |
getFontMatrix()
Deprecated.
Use
FontProgram.UNITS_NORMALIZATION constant for conversion between text and glyph space. For now we opted to always expect that all PdfFont metrics in glyph-space are related to text space as 1 to 1000, as it is defined for the majority of fonts. For fonts which don't necessary follow this rule (see PdfType3Font ), we perform internal normalization of font metrics in order to adhere to this common expectation. This method will be removed in next major release.
|
FontProgram |
getFontProgram() |
abstract Glyph |
getGlyph(int unicode)
Get glyph by unicode
|
protected PdfStream |
getPdfFontStream(byte[] fontStreamBytes, int[] fontStreamLengths)
Create PdfStream based on fontStreamBytes .
|
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 |
getWidth(String text)
Returns the width of a string of this font in 1000 normalized units.
|
float |
getWidth(String text, float fontSize)
Gets the width of a String in points.
|
boolean |
isBuiltWith(String fontProgram, String encoding)
Checks whether the PdfFont was built with corresponding fontProgram and encoding or CMAP.
|
boolean |
isEmbedded() |
boolean |
isSubset()
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
|
protected boolean |
isWrappedObjectMustBeIndirect()
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.
|
List<String> |
splitString(String text, float fontSize, float maxWidth) |
String |
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) |
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
public static final int SIMPLE_FONT_MAX_CHAR_CODE_VALUE
protected FontProgram fontProgram
protected static final byte[] EMPTY_BYTES
@Deprecated protected static final double[] DEFAULT_FONT_MATRIX
protected boolean newFont
protected boolean embedded
protected boolean subset
protected ListsubsetRanges
protected PdfFont(PdfDictionary fontDictionary)
protected PdfFont()
public abstract Glyph getGlyph(int unicode)
unicode
- a unicode code point
Glyph
if it exists or .NOTDEF if supported, otherwise null
.
public boolean containsGlyph(int unicode)
unicode
- a unicode code point
public abstract int appendGlyphs(String text, int from, int to, List<Glyph> glyphs)
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.
public abstract int appendAnyGlyph(String text, int from, List<Glyph> glyphs)
text
- String to convert to glyphs.
from
- from index of the text.
glyphs
- array for a new glyph, shall not be null.
public abstract byte[] convertToBytes(String text)
text
- the text to convert
public abstract byte[] convertToBytes(GlyphLine glyphLine)
public abstract GlyphLine decodeIntoGlyphLine(PdfString characterCodes)
GlyphLine
characterCodes
- the string which is interpreted as a sequence of character codes. Note, that PdfString
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
GlyphLine
containing the glyphs encoded by the passed string
public boolean appendDecodedCodesToGlyphsList(List<Glyph> list, PdfString characterCodes)
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, that PdfString
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
public abstract float getContentWidth(PdfString content)
public abstract byte[] convertToBytes(Glyph glyph)
public abstract void writeText(GlyphLine text, int from, int to, PdfOutputStream stream)
public abstract void writeText(String text, PdfOutputStream stream)
@Deprecated public double[] getFontMatrix()
FontProgram.UNITS_NORMALIZATION
constant for conversion between text and glyph space. For now we opted to always expect that all PdfFont
metrics in glyph-space are related to text space as 1 to 1000, as it is defined for the majority of fonts. For fonts which don't necessary follow this rule (see PdfType3Font
), we perform internal normalization of font metrics in order to adhere to this common expectation. This method will be removed in next major release.
public int getWidth(int unicode)
unicode
- a certain character.
public float getWidth(int unicode, float fontSize)
unicode
- a certain character.
fontSize
- the font size.
public int getWidth(String text)
text
- a string content.
public float getWidth(String text, float fontSize)
String
in points.
text
- the String
to get the width of
fontSize
- the font size
public int getDescent(String text, float fontSize)
String
in points. The descent will always be less than or equal to zero even if all the characters have an higher descent.
text
- the String
to get the descent of
fontSize
- the font size
public int getDescent(int unicode, float fontSize)
unicode
- the char code to get the descent of
fontSize
- the font size
public int getAscent(String text, float fontSize)
String
in points. The ascent will always be greater than or equal to zero even if all the characters have a lower ascent.
text
- the String
to get the ascent of
fontSize
- the font size
public int getAscent(int unicode, float fontSize)
unicode
- the char code to get the ascent of
fontSize
- the font size
public FontProgram getFontProgram()
public boolean isEmbedded()
public boolean isSubset()
false
to include all the glyphs and widths.
public void setSubset(boolean subset)
true
only the glyphs used will be included in the font. When set to false
the full font will be included and all subset ranges will be removed.
subset
- new value of property subset
addSubsetRange(int[])
public void addSubsetRange(int[] range)
int
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.
range
- the character range
public boolean isBuiltWith(String fontProgram, String encoding)
PdfFont
was built with corresponding fontProgram and encoding or CMAP. Default value is false unless overridden.
fontProgram
- a font name or path to a font program
encoding
- an encoding or CMAP
PdfDocument.findFont(String, String)
, FontProgram.isBuiltWith(String)
, FontEncoding.isBuiltWith(String)
, CMapEncoding.isBuiltWith(String)
public void flush()
PdfObject
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 call PdfObjectWrapper.makeIndirect(PdfDocument)
. For example: wrapperInstance.makeIndirect(document).flush(); Note that not every wrapper require this, only those that have such warning in documentation.
flush
in class PdfObjectWrapper<PdfDictionary>
protected abstract PdfDictionary getFontDescriptor(String fontName)
protected boolean isWrappedObjectMustBeIndirect()
PdfObjectWrapper
isWrappedObjectMustBeIndirect
in class PdfObjectWrapper<PdfDictionary>
protected static String updateSubsetPrefix(String fontName, boolean isSubset, boolean isEmbedded)
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.
protected PdfStream getPdfFontStream(byte[] fontStreamBytes, int[] fontStreamLengths)
PdfStream
based on fontStreamBytes
.
fontStreamBytes
- original font data, must be not null.
fontStreamLengths
- array to generate Length*
keys, must be not null.
null
, if there is an error reading the font.
PdfException
- Method will throw exception if fontStreamBytes
is null
.
@Deprecated protected static int[] compactRanges(Listranges)
TrueTypeFont
.
ranges
- a List
of integer arrays, which are constituted by pairs of ints that denote each range limits. Each integer array size shall be a multiple of two.
Copyright © 1998–2023 iText Group NV. All rights reserved.