Class PdfFont
Represents a font object in a PDF document, providing access to font properties and metrics.
public class PdfFont : PdfObject, IDisposable
- Inheritance
-
PdfFont
- Implements
- Derived
- Inherited Members
Remarks
This class allows users to retrieve information about a font, such as its name, family, weight, and style, as well as access font data and glyph-specific metrics. It also provides methods to determine whether the font is embedded in the PDF and to retrieve glyph paths for rendering or analysis.
Properties
IsEmbedded
Gets a value indicating whether the font is embedded within the PDF document.
public bool IsEmbedded { get; }
Property Value
Remarks
An embedded font ensures that the font's appearance is preserved regardless of the availability of the font on the viewing system.
Name
Gets the name associated with the current instance.
public string Name { get; }
Property Value
Methods
GetAscent(float)
Calculates the ascent of the font for the specified font size.
public float? GetAscent(float fontSize)
Parameters
fontSize
floatThe size of the font, in points, for which the ascent is calculated. Must be greater than 0.
Returns
- float?
The ascent of the font as a floating-point value, or null if the ascent could not be determined.
Remarks
The ascent represents the distance from the baseline to the highest point of the font's glyphs for the given font size.
GetBaseFontName()
Retrieves the base font name of the current font.
public string GetBaseFontName()
Returns
- string
A string containing the base font name. The returned string represents the name of the font as defined in the PDF document. Returns an empty string if the font name cannot be determined.
Remarks
The base font name is typically used to identify the font in a PDF document. This method ensures that the font name is read as a UTF-8 encoded string.
GetDescent(float)
Calculates the descent value for the font at the specified size.
public float? GetDescent(float fontSize)
Parameters
fontSize
floatThe size of the font, in points, for which the descent is calculated. Must be greater than zero.
Returns
Remarks
The descent value represents the distance from the baseline to the lowest point of the font's glyphs, expressed as a negative value. This method returns null if the calculation fails.
GetFamilyName()
Retrieves the family name of the font associated with this instance.
public string GetFamilyName()
Returns
- string
A string containing the family name of the font. Returns an empty string if the family name cannot be determined.
Remarks
The family name is typically used to identify the general design of the font, such as "Arial" or "Times New Roman". This method ensures the name is returned as a UTF-8 encoded string.
GetFlags()
Retrieves the font flags associated with the current font.
public int GetFlags()
Returns
- int
An integer representing the font flags. The value is a bitmask where each bit represents a specific font property, such as whether the font is fixed-pitch, serif, symbolic, or others.
Remarks
The returned bitmask can be used to determine various characteristics of the font. For example, specific bits may indicate whether the font is bold, italic, or symbolic. Refer to the PDF specification for details on the meaning of each bit.
GetFontData()
Retrieves the raw font data associated with the current font.
public byte[] GetFontData()
Returns
- byte[]
A byte array containing the raw font data. If the font has no data, an empty array is returned.
Remarks
This method returns the font data as a byte array. If the font has no associated data, an empty array is returned. The caller can use this data for further processing, such as embedding the font in a document or analyzing its structure.
Exceptions
- dotPDFiumException
Thrown if the font data cannot be retrieved due to an internal error.
GetGlyphPath(uint, float)
Retrieves the glyph path for the specified glyph ID and font size.
public PdfGlyphPath? GetGlyphPath(uint glyphId, float fontSize)
Parameters
glyphId
uintThe ID of the glyph to retrieve the path for.
fontSize
floatThe size of the font, in points, used to scale the glyph path.
Returns
- PdfGlyphPath
A PdfGlyphPath object representing the path of the specified glyph, or null if the glyph path could not be retrieved.
Remarks
The glyph path represents the vector outline of the glyph, which can be used for rendering or analysis. Ensure that the font size is a positive value to avoid unexpected behavior.
GetGlyphWidth(uint, float)
Retrieves the width of a specified glyph at a given font size.
public float? GetGlyphWidth(uint glyphId, float fontSize)
Parameters
glyphId
uintThe identifier of the glyph whose width is to be retrieved.
fontSize
floatThe size of the font, in points, used to calculate the glyph's width. Must be greater than 0.
Returns
Remarks
This method queries the width of a glyph using the underlying font handle. The result is dependent on the font's metrics and the specified font size. If the glyph ID is invalid or the operation fails, the method returns null.
GetItalicAngle()
Retrieves the italic angle of the font.
public int? GetItalicAngle()
Returns
- int?
The italic angle of the font in degrees, or null if the angle cannot be determined. A positive value indicates a right-leaning italic angle, while a negative value indicates a left-leaning italic angle.
GetWeight()
Gets the weight of the font.
public int GetWeight()
Returns
- int
An integer representing the weight of the font. The value typically ranges from 100 (Thin) to 900 (Black), where higher values indicate a bolder font weight.
Remarks
The font weight is a numerical representation of the font's thickness or boldness. This value can be used to determine the visual style of the font in rendering or layout operations.