Table of Contents

Class PdfFont

Namespace
iText.Kernel.Font
Assembly
itext.kernel.dll
public abstract class PdfFont : PdfObjectWrapper<PdfDictionary>
Inheritance
PdfFont
Derived
Inherited Members

Constructors

PdfFont()

protected PdfFont()

PdfFont(PdfDictionary)

protected PdfFont(PdfDictionary fontDictionary)

Parameters

fontDictionary PdfDictionary

Fields

EMPTY_BYTES

protected static readonly byte[] EMPTY_BYTES

Field Value

byte[]

SIMPLE_FONT_MAX_CHAR_CODE_VALUE

The upper bound value for char code.

public const int SIMPLE_FONT_MAX_CHAR_CODE_VALUE = 255

Field Value

int

Remarks

The upper bound value for char code. As for simple fonts char codes are a single byte values, it may vary from 0 to 255.

embedded

true if the font is to be embedded in the PDF.

protected bool embedded

Field Value

bool

fontProgram

protected FontProgram fontProgram

Field Value

FontProgram

newFont

false, if the font comes from PdfDocument.

protected bool newFont

Field Value

bool

notdefGlyphs

protected IDictionary<int, Glyph> notdefGlyphs

Field Value

IDictionary<int, Glyph>

subset

Indicates if all the glyphs and widths for that particular encoding should be included in the document.

protected bool subset

Field Value

bool

subsetRanges

protected IList<int[]> subsetRanges

Field Value

IList<int[]>

Methods

AddSubsetRange(int[])

Adds a character range when subsetting.

public virtual void AddSubsetRange(int[] range)

Parameters

range int[]

the character range

Remarks

Adds a character range when subsetting. The range is an 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.

AppendAnyGlyph(string, int, IList<Glyph>)

Append any single glyph, even notdef.

public abstract int AppendAnyGlyph(string text, int from, IList<Glyph> glyphs)

Parameters

text string

String to convert to glyphs.

from int

from index of the text.

glyphs IList<Glyph>

array for a new glyph, shall not be null.

Returns

int

number of processed chars: 2 in case surrogate pair, otherwise 1

Remarks

Append any single glyph, even notdef. Returns number of processed chars: 2 in case surrogate pair, otherwise 1.

AppendDecodedCodesToGlyphsList(IList<Glyph>, PdfString)

Decodes sequence of character codes (e.g. from content stream) to sequence of glyphs and appends them to the passed list.

public virtual bool AppendDecodedCodesToGlyphsList(IList<Glyph> list, PdfString characterCodes)

Parameters

list IList<Glyph>

the list to the end of which decoded glyphs are to be added

characterCodes PdfString

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

Returns

bool

true if all codes where successfully decoded, false otherwise

AppendGlyphs(string, int, int, IList<Glyph>)

Append all supported glyphs and return number of processed chars.

public abstract int AppendGlyphs(string text, int from, int to, IList<Glyph> glyphs)

Parameters

text string

String to convert to glyphs.

from int

from index of the text.

to int

to index of the text.

glyphs IList<Glyph>

array for a new glyphs, shall not be null.

Returns

int

number of processed chars from text.

Remarks

Append all supported glyphs and return number of processed chars. Composite font supports surrogate pairs.

ContainsGlyph(int)

Check whether font contains glyph with specified unicode.

public virtual bool ContainsGlyph(int unicode)

Parameters

unicode int

a unicode code point

Returns

bool

true if font contains glyph, represented with the unicode code point, otherwise false.

ConvertToBytes(string)

Converts the text into bytes to be placed in the document.

public abstract byte[] ConvertToBytes(string text)

Parameters

text string

the text to convert

Returns

byte[]

the conversion

Remarks

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.

ConvertToBytes(Glyph)

public abstract byte[] ConvertToBytes(Glyph glyph)

Parameters

glyph Glyph

Returns

byte[]

ConvertToBytes(GlyphLine)

public abstract byte[] ConvertToBytes(GlyphLine glyphLine)

Parameters

glyphLine GlyphLine

Returns

byte[]

CreateGlyphLine(string)

public abstract GlyphLine CreateGlyphLine(string content)

Parameters

content string

Returns

GlyphLine

Decode(PdfString)

public abstract string Decode(PdfString content)

Parameters

content PdfString

Returns

string

DecodeIntoGlyphLine(PdfString)

Decodes sequence of character codes (e.g. from content stream) into a GlyphLine

public abstract GlyphLine DecodeIntoGlyphLine(PdfString characterCodes)

Parameters

characterCodes PdfString

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

Returns

GlyphLine

the GlyphLine containing the glyphs encoded by the passed string

Flush()

To manually flush a PdfObject behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference.

public override void Flush()

Remarks

To manually flush a 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 MakeIndirect(PdfDocument). For example: wrapperInstance.makeIndirect(document).flush(); Note that not every wrapper require this, only those that have such warning in documentation.

GetAscent(int, float)

Gets the ascent of a char code in normalized 1000 units.

public virtual float GetAscent(int unicode, float fontSize)

Parameters

unicode int

the char code to get the ascent of

fontSize float

the font size

Returns

float

the ascent in points

Remarks

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.

GetAscent(string, float)

Gets the ascent of a String in points.

public virtual float GetAscent(string text, float fontSize)

Parameters

text string

the String to get the ascent of

fontSize float

the font size

Returns

float

the ascent in points

Remarks

Gets the ascent of a String in points. The ascent will always be greater than or equal to zero even if all the characters have a lower ascent.

GetContentWidth(PdfString)

public abstract float GetContentWidth(PdfString content)

Parameters

content PdfString

Returns

float

GetDescent(int, float)

Gets the descent of a char code in points.

public virtual float GetDescent(int unicode, float fontSize)

Parameters

unicode int

the char code to get the descent of

fontSize float

the font size

Returns

float

the descent in points

Remarks

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.

GetDescent(string, float)

Gets the descent of a String in points.

public virtual float GetDescent(string text, float fontSize)

Parameters

text string

the String to get the descent of

fontSize float

the font size

Returns

float

the descent in points

Remarks

Gets the descent of a String in points. The descent will always be less than or equal to zero even if all the characters have a higher descent.

GetFontDescriptor(string)

protected abstract PdfDictionary GetFontDescriptor(string fontName)

Parameters

fontName string

Returns

PdfDictionary

GetFontProgram()

public virtual FontProgram GetFontProgram()

Returns

FontProgram

GetGlyph(int)

Get glyph by unicode

public abstract Glyph GetGlyph(int unicode)

Parameters

unicode int

a unicode code point

Returns

Glyph

Glyph if it exists or .NOTDEF if supported, otherwise null.

GetPdfFontStream(byte[], int[])

Create PdfStream based on fontStreamBytes.

protected virtual PdfStream GetPdfFontStream(byte[] fontStreamBytes, int[] fontStreamLengths)

Parameters

fontStreamBytes byte[]

original font data, must be not null.

fontStreamLengths int[]

array to generate Length* keys, must be not null.

Returns

PdfStream

the PdfStream containing the font or null , if there is an error reading the font.

GetWidth(int)

Returns the width of a certain character of this font in 1000 normalized units.

public virtual int GetWidth(int unicode)

Parameters

unicode int

a certain character.

Returns

int

a width in Text Space.

GetWidth(int, float)

Returns the width of a certain character of this font in points.

public virtual float GetWidth(int unicode, float fontSize)

Parameters

unicode int

a certain character.

fontSize float

the font size.

Returns

float

a width in points.

GetWidth(string)

Returns the width of a string of this font in 1000 normalized units.

public virtual int GetWidth(string text)

Parameters

text string

a string content.

Returns

int

a width of string in Text Space.

GetWidth(string, float)

Gets the width of a String in points.

public virtual float GetWidth(string text, float fontSize)

Parameters

text string

the String to get the width of

fontSize float

the font size

Returns

float

the width in points

IsBuiltWith(string, string)

Checks whether the PdfFont was built with corresponding fontProgram and encoding or CMAP.

public virtual bool IsBuiltWith(string fontProgram, string encoding)

Parameters

fontProgram string

a font name or path to a font program

encoding string

an encoding or CMAP

Returns

bool

true, if the PdfFont was built with the fontProgram and encoding. Otherwise false.

Remarks

Checks whether the PdfFont was built with corresponding fontProgram and encoding or CMAP. Default value is false unless overridden.

See Also

IsEmbedded()

public virtual bool IsEmbedded()

Returns

bool

IsSubset()

Indicates if all the glyphs and widths for that particular encoding should be included in the document.

public virtual bool IsSubset()

Returns

bool

false to include all the glyphs and widths.

IsWrappedObjectMustBeIndirect()

protected override bool IsWrappedObjectMustBeIndirect()

Returns

bool

SetSubset(bool)

Indicates if all the glyphs and widths for that particular encoding should be included in the document.

public virtual void SetSubset(bool subset)

Parameters

subset bool

new value of property subset

Remarks

Indicates if all the glyphs and widths for that particular encoding should be included in the document. When set to 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.

See Also

SplitString(string, float, float)

public virtual IList<string> SplitString(string text, float fontSize, float maxWidth)

Parameters

text string
fontSize float
maxWidth float

Returns

IList<string>

ToString()

public override string ToString()

Returns

string

UpdateSubsetPrefix(string, bool, bool)

Adds a unique subset prefix to be added to the font name when the font is embedded and subsetted.

protected static string UpdateSubsetPrefix(string fontName, bool isSubset, bool isEmbedded)

Parameters

fontName string

the original font name.

isSubset bool

denotes whether font in question is subsetted, i.e. only used symbols are kept in it.

isEmbedded bool

denotes whether font in question is embedded into the PDF document.

Returns

string

the font name prefixed with subset if isSubset and isEmbedded are true, otherwise original font name is returned intact.

WriteText(string, PdfOutputStream)

public abstract void WriteText(string text, PdfOutputStream stream)

Parameters

text string
stream PdfOutputStream

WriteText(GlyphLine, int, int, PdfOutputStream)

public abstract void WriteText(GlyphLine text, int from, int to, PdfOutputStream stream)

Parameters

text GlyphLine
from int
to int
stream PdfOutputStream