Skip to main content

OpenTypeFont

Version: 10.0

cete.dynamicpdf.text.opentypefont

OpenTypeFont​

  • Namespace: ceTe.DynamicPDF.Text
  • Assemblies: DynamicPDF.NETFramework40.dll, DynamicPDF.NETStandard20.dll

Represents an OpenType font.

public class OpenTypeFont : Font, IDisposable, IFontSubsettable
Public Class OpenTypeFont
Inherits Font
Implements IDisposable, IFontSubsettable

Inheritance: Object → Resource → Font → OpenTypeFont

Implements: IDisposable, IFontSubsettable

Licensing​

This class is a DynamicPDF Generator Professional Edition feature. One of the following licenses is required for non-evaluation usage:

  • DynamicPDF Generator for .NET Professional Edition
  • DynamicPDF Generator for .NET Enterprise Edition
  • DynamicPDF Merger for .NET Professional Edition
  • DynamicPDF Merger for .NET Enterprise Edition
  • DynamicPDF ReportWriter for .NET Professional Edition
  • DynamicPDF ReportWriter for .NET Enterprise Edition
  • DynamicPDF Core Suite for .NET Professional Edition
  • DynamicPDF Core Suite for .NET Enterprise Edition

Examples​

This example shows how to use the open type font.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.Text

Module MyModule

Sub Main()

' Create a PDF Document
Dim MyDocument As Document = New Document

' Create a Page and add it to the document
Dim MyPage As Page = New Page
MyDocument.Pages.Add(MyPage)

' Create a open type font
Dim MyOpentypefont As OpenTypeFont = New OpenTypeFont("Path of .otf file")

' Create a label
Dim MyLabel As ceTe.DynamicPDF.PageElements.Label = New ceTe.DynamicPDF.PageElements.Label("This text uses open type font ", 0, 0, 300, 300)

' Assign open type font to label
MyLabel.Font = MyOpentypefont

' Add label to the page
MyPage.Elements.Add(MyLabel)

' Save the PDF document
MyDocument.Draw("C:\MyDocument.pdf")

End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.Text;

public class Example
{
public static void CreatePDF(string outputPath, string fontPath)
{
// Create a PDF Document
Document document = new Document();

// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add(page);

// Create a open type font
OpenTypeFont opentypefont = new OpenTypeFont(fontPath);

//Create a label
Label label = new Label("This text uses opentype font ", 0, 0, 300, 300);

// Assign opentype font to label
label.Font = opentypefont;

// Add label to the page
page.Elements.Add(label);

// Save the PDF document
document.Draw(outputPath);
}
}

Remarks​

See the OpenType Fonts topic for more on OpenType fonts.

Constructors​

OpenTypeFont(Stream, LineBreaker)​

Intializes a new instance of OpenTypeFont class.

public OpenTypeFont(Stream reader, LineBreaker lineBreaker)
Public Sub New (reader As Stream, lineBreaker As LineBreaker)

Parameters​

Stream containing the opentype / truetype font data.

Line breaker to use for the opentype font.

OpenTypeFont(Stream, LineBreaker, Boolean)​

Intializes a new instance of OpenTypeFont class.

public OpenTypeFont(Stream reader, LineBreaker lineBreaker, bool useCharacterShaping)
Public Sub New (reader As Stream, lineBreaker As LineBreaker, useCharacterShaping As Boolean)

Parameters​

Stream containing the opentype / truetype font data.

Line breaker to use for the opentype font.

Value indicating whether to use the advance typographic tables (GSUB, GPOS) when writing the text. Setting this property to true will turn on character shaping.

Examples​

This example shows how to use the open type font with character shaping.

using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.Text;

public class Example
{
public static void CreatePDF(string outputPath, string fontPath)
{
// Create a stream
Stream stream = System.IO.File.OpenRead(fontPath);

// Create a open type font. Setting true enables character shaping usage.
OpenTypeFont openTypefont = new OpenTypeFont(stream, LineBreaker.Latin, true);

// Create a PDF Document
Document document = new Document();

// Create a new Page
Page page = new Page();

// Add the page to the document
document.Pages.Add(page);

//Create a label
Label label = new Label("This text uses opentype font with character shaping", 0, 0, 300, 300);

// Assign opentype font to label
label.Font = openTypefont;

// Add label to the page
page.Elements.Add(label);

// Save the PDF document
document.Draw(outputPath);
}
}

OpenTypeFont(String)​

Initializes a new instance of OpenTypeFont class.

public OpenTypeFont(string filePath)
Public Sub New (filePath As String)

Parameters​

Physical file path of the OpenType font file.

OpenTypeFont(String, Boolean)​

Initializes a new instance of OpenTypeFont class.

public OpenTypeFont(string filePath, bool useCharacterShaping)
Public Sub New (filePath As String, useCharacterShaping As Boolean)

Parameters​

Physical file path of the OpenType font file.

Value indicating whether to use the advance typographic tables (GSUB, GPOS) when writing the text. Setting this property to true will turn on character shaping.

Examples​

This example shows how to use the open type font with character shaping.

using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.Text;

public class Example
{
public static void CreatePDF(string outputPath, string fontPath)
{
// Create a open type font. Setting true enables character shaping usage.
OpenTypeFont openTypefont = new OpenTypeFont(fontPath, true);

// Create a PDF Document
Document document = new Document();

// Create a new Page
Page page = new Page();

// Add the page to the document
document.Pages.Add(page);

// Create a label
Label label = new Label("This text uses opentype font with character shaping", 0, 0, 300, 300);

// Assign opentype font to label
label.Font = openTypefont;

// Add label to the page
page.Elements.Add(label);

// Save the PDF document
document.Draw(outputPath);
}
}

OpenTypeFont(String, LineBreaker)​

Initializes a new instance of OpenTypeFont class.

public OpenTypeFont(string filePath, LineBreaker lineBreaker)
Public Sub New (filePath As String, lineBreaker As LineBreaker)

Parameters​

Physical file path of the opentype / true type font file.

Line breaker to use for the opentype font.

OpenTypeFont(String, LineBreaker, Boolean)​

Initializes a new instance of OpenTypeFont class.

public OpenTypeFont(string filePath, LineBreaker lineBreaker, bool useCharacterShaping)
Public Sub New (filePath As String, lineBreaker As LineBreaker, useCharacterShaping As Boolean)

Parameters​

Physical file path of the opentype / true type font file.

Line breaker to use for the opentype font.

Value indicating whether to use the advance typographic tables (GSUB, GPOS) when writing the text. Setting this property to true will turn on character shaping.

Examples​

This example shows how to use the open type font with character shaping.

using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.Text;

public class Example
{
public static void CreatePDF(string outputPath, string fontPath)
{
// Create a open type font. Setting true enables character shaping usage.
OpenTypeFont openTypefont = new OpenTypeFont(fontPath, LineBreaker.Latin, true);

// Create a PDF Document
Document document = new Document();

// Create a new Page
Page page = new Page();

// Add the page to the document
document.Pages.Add(page);

// Create a label
Label label = new Label("This text uses opentype font with character shaping", 0, 0, 300, 300);

// Assign opentype font to label
label.Font = openTypefont;

// Add label to the page
page.Elements.Add(label);

// Save the PDF document
document.Draw(outputPath);
}
}

Properties​

Ascender​

Gets the ascender for the font.

public short Ascender { get; }
Public Property Ascender As Int16

Property Value​

Int16

Descender​

Gets the descender for the font.

public short Descender { get; }
Public Property Descender As Int16

Property Value​

Int16

Embed​

Gets or sets a value indicating whether the font need to be embedded in to the pdf.

public bool Embed { get; set; }
Public Property Embed As Boolean

Property Value​

Boolean

Encoder​

Gets the encoder for the font. (Inherited from Font)

public Encoder Encoder { get; }
Public Property Encoder As Encoder

Property Value​

Encoder

FormFontName​

Gets the four character name of the font. (Inherited from Font)

public string FormFontName { get; }
Public Property FormFontName As String

Property Value​

String

LineBreaker​

Gets the instance of LineBreaker used for the font.

public LineBreaker LineBreaker { get; }
Public Property LineBreaker As LineBreaker

Property Value​

LineBreaker

LineGap​

Gets the line gap for the font.

public short LineGap { get; }
Public Property LineGap As Int16

Property Value​

Int16

Name​

Gets the font name for the file given.

public string Name { get; }
Public Property Name As String

Property Value​

String

OutLineType​

Gets the OutLineType of the opentype font.

public OutLineType OutLineType { get; }
Public Property OutLineType As OutLineType

Property Value​

OutLineType

RequiredPdfObjects​

Gets the required pdf objects.

public int RequiredPdfObjects { get; }
Public Property RequiredPdfObjects As Int32

Property Value​

Int32

ResourceType​

Gets the value of ResourceType .

public ResourceType ResourceType { get; }
Public Property ResourceType As ResourceType

Property Value​

ResourceType

Subset​

Gets or sets a value indicating whether the font need to subset while embedding.

public bool Subset { get; set; }
Public Property Subset As Boolean

Property Value​

Boolean

Uid​

Gets the unique ID of the resource. (Inherited from Resource)

public long Uid { get; }
Public Property Uid As Int64

Property Value​

Int64

UseCharacterShaping​

Gets a value indicating whether to use the advance typographic tables (GSUB, GPOS) when writing the text.

public bool UseCharacterShaping { get; }
Public Property UseCharacterShaping As Boolean

Property Value​

Boolean

Methods​

Dispose()​

Releases all resources used by the OpenTypeFont object.

public void Dispose()
Sub Dispose()

Draw(DocumentWriter)​

Draw the opentype font data to the DocumentWriter .

public void Draw(DocumentWriter writer)
Sub Draw(writer As DocumentWriter)

Parameters​

DocumentWriter object used to receive the opentype font output.

Equals(Object)​

Determines whether the specified Object is equal to the current Object . (Inherited from Object)

public bool Equals(Object obj)
Function Equals(obj As Object) As Boolean

Parameters​

The Object to compare with the current Object .

Returns​

true if the specified Object is equal to the current Object ; otherwise, false.

GetAscender(Single)​

Returns the ascender of the font in points for the given font size. (Inherited from Font)

public float GetAscender(float fontSize)
Function GetAscender(fontSize As Single) As Single

Parameters​

Font size to use for the calculation.

Returns​

The ascender in points.

GetBaseLine(Single, Single)​

Returns the baseline of the font in points for the given leading and font size. (Inherited from Font)

public float GetBaseLine(float fontSize, float leading)
Function GetBaseLine(fontSize As Single, leading As Single) As Single

Parameters​

Font size to use for the calculation.

Leading to use for the calculation.

Returns​

The baseline in points.

GetDefaultLeading(Single)​

Returns the default leading of the font in points for the given font size. (Inherited from Font)

public float GetDefaultLeading(float fontSize)
Function GetDefaultLeading(fontSize As Single) As Single

Parameters​

Font size to use for the calculation.

Returns​

The default leading in points.

GetDescender(Single)​

Returns the descender of the font in points for the given font size. (Inherited from Font)

public float GetDescender(float fontSize)
Function GetDescender(fontSize As Single) As Single

Parameters​

Font size to use for the calculation.

Returns​

The descender in points.

GetFontSubsetter()​

eturns a font subsetter for the opentype font.

public FontSubsetter GetFontSubsetter()
Function GetFontSubsetter() As FontSubsetter

Returns​

FontSubsetter object used for the font.

GetGlyphWidth(Char)​

Returns the mwidth of the given char.

public short GetGlyphWidth(char glyph)
Function GetGlyphWidth(glyph As Char) As Short

Parameters​

Glyph whose mwidth is required.

Returns​

mwdith of the given glyph.

GetHashCode()​

Serves as a hash function for a particular type. (Inherited from Object)

public int GetHashCode()
Function GetHashCode() As Integer

Returns​

A hash code for the current Object .

GetKernValue(Char, Char)​

Returns the kern value correspoding to the given glyph combination.

public float GetKernValue(char left, char right)
Function GetKernValue(left As Char, right As Char) As Single

Parameters​

Left glyph.

Right glyph.

Returns​

Kern value correponds to the combination given.

GetLineGap(Single)​

Returns the line gap of the font in points for the given font size. (Inherited from Font)

public float GetLineGap(float fontSize)
Function GetLineGap(fontSize As Single) As Single

Parameters​

Font size to use for the calculation.

Returns​

The line gap in points.

GetTextLines(Char[], Single, Single)​

Returns a TextLineList for the given character array. (Inherited from Font)

public TextLineList GetTextLines(Char[] text, float width, float fontSize)
Function GetTextLines(text As Char[], width As Single, fontSize As Single) As TextLineList

Parameters​

Character array containing the text.

Width to use when calculating the text lines.

Font size to use when calculating the text lines.

Returns​

A TextLineList containing the text.

GetTextLines(Char[], Single, Single, Single)​

Returns a TextLineList for the given character array. (Inherited from Font)

public TextLineList GetTextLines(Char[] text, float width, float height, float fontSize)
Function GetTextLines(text As Char[], width As Single, height As Single, fontSize As Single) As TextLineList

Parameters​

Character array containing the text.

Width to use when calculating the text lines.

Height to use when calculating the text lines.

Font size to use when calculating the text lines.

Returns​

A TextLineList containing the text.

GetTextWidth(Char[], Single)​

Returns the width of the given text. (Inherited from Font)

public float GetTextWidth(Char[] text, float fontSize)
Function GetTextWidth(text As Char[], fontSize As Single) As Single

Parameters​

Byte array or text whose width is returned.

Font size of text.

Returns​

Width of text in points.

GetTextWidth(String, Single)​

Returns the width of the given text. (Inherited from Font)

public float GetTextWidth(string text, float fontSize)
Function GetTextWidth(text As String, fontSize As Single) As Single

Parameters​

Text whose width is returned.

Font size of text.

Returns​

Width of text in points.

GetType()​

Gets the Type of the current instance. (Inherited from Object)

public Type GetType()
Function GetType() As Type

Returns​

The Type instance that represents the exact runtime type of the current instance.

HasKerning()​

Returns whether the font has inbuilt kerning pairs.

public bool HasKerning()
Function HasKerning() As Boolean

Returns​

true, if the font has inbuilt kerning pair.

ToString()​

Returns a String that represents the current Object . (Inherited from Object)

public string ToString()
Function ToString() As String

Returns​

A String that represents the current Object .

See Also​

ceTe.DynamicPDF.Text