# OfficeTrueTypeFont

Small managed reader for sfnt fonts that use TrueType glyf outlines, used for dependency-free text rasterization.

Class 

`OfficeIMO.Drawing`

**Namespace**

`OfficeIMO.Drawing`

**Assembly**

`OfficeIMO.Core`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[OfficeTrueTypeFont.cs:164](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L164)

**Implements**

`IOfficeBoundedFontProgram` `IOfficeFontProgram` `IOfficeFontBaselineMetrics` `IOfficeVariableFontProgram` `IOfficeColorFontProgram` `IOfficeMathFontProgram` `IOfficeMathGlyphProgram`

**Modifiers**

sealed

Small managed reader for sfnt fonts that use TrueType glyf outlines, used for dependency-free text rasterization.

## Inheritance

- object
- OfficeTrueTypeFont

## Remarks

This type reads font files directly and does not call operating-system graphics or font APIs. It supports the simple glyf/cmap/hmtx path needed by OfficeIMO renderers and falls back cleanly when no suitable platform font file is available.

## Usage

Explore 6 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

### Returned or exposed by 5

- Property [OfficeRasterTextOptions.Font](/api/core/officeimo-drawing-officerastertextoptions/#property-font)
- Method [OfficeTrueTypeFont.TryLoad](/api/core/officeimo-drawing-officetruetypefont/#method-tryload-string)
- Method [OfficeTrueTypeFont.TryLoadDefault](/api/core/officeimo-drawing-officetruetypefont/#method-tryloaddefault)
- Method [OfficeTrueTypeFont.TryLoadFontFamily](/api/core/officeimo-drawing-officetruetypefont/#method-tryloadfontfamily-string)
- Method [OfficeTrueTypeFont.TryLoadFontFamilyForText](/api/core/officeimo-drawing-officetruetypefont/#method-tryloadfontfamilyfortext-string-officeimo-drawing-officefontfacedescriptor-string-officeimo-drawing-officefontstyle)

### Accepted by parameters 1

- Constructor [OfficeRasterCanvas.OfficeRasterCanvas](/api/core/officeimo-drawing-officerastercanvas/#constructor-ctor-officeimo-drawing-officerasterimage-officeimo-drawing-officetruetypefont-officeimo-drawing-officefontfacecollection) parameter `font`

Filter members 

Show inherited

## Methods

`public double BaselineOffset(double fontSize)` [#](#method-baselineoffset-double)

[OfficeTrueTypeFont.cs:462](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L462)

Returns the distance from the top of the face line box to its baseline.

Parameters

**fontSize double required**

Returns

`double`

`public List<List<OfficePoint>> GetTextContours(string text, double x, double y, double fontSize)` [#](#method-gettextcontours-string-double-double-double)

[OfficeTrueTypeFont.cs:471](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L471)

Reads flattened fill contours for the supplied text at a top-left baseline box.

Parameters

**text string required**

**x double required**

**y double required**

**fontSize double required**

Returns

`List<List<OfficePoint>>`

`public List<List<OfficePoint>> GetTextContoursBounded(string text, double x, double y, double fontSize, int maximumPointCount, CancellationToken cancellationToken)` [#](#method-gettextcontoursbounded-string-double-double-double-int32-threading-cancellationtoken)

[OfficeTrueTypeFont.cs:482](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L482)

Returns contours while enforcing the maximum total point count.

Parameters

**text string required**

**x double required**

**y double required**

**fontSize double required**

**maximumPointCount int required**

**cancellationToken System.Threading.CancellationToken required**

Returns

`List<List<OfficePoint>>`

`public double LineHeight(double fontSize)` [#](#method-lineheight-double)

[OfficeTrueTypeFont.cs:458](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L458)

Returns the line height at the requested font size.

Parameters

**fontSize double required**

Returns

`double`

`public double Measure(string text, double fontSize)` [#](#method-measure-string-double)

[OfficeTrueTypeFont.cs:380](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L380)

Measures text at the requested font size.

Parameters

**text string required**

**fontSize double required**

Returns

`double`

TryLoad 6 overloads

`public static OfficeTrueTypeFont? TryLoad(string? path)` [#](#method-tryload-string)

[OfficeTrueTypeFont.cs:215](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L215)

Attempts to load a standalone font or the first suitable face in a font collection.

Parameters

**path string? required**

Path to a TrueType font file, including an OpenType file that uses TrueType glyf outlines.

Returns

`OfficeTrueTypeFont?` The loaded font, or null when the path or font data is invalid or inaccessible.

`public static OfficeTrueTypeFont? TryLoad(string? path, int? collectionIndex)` [#](#method-tryload-string-nullable-system-int32)

[OfficeTrueTypeFont.cs:221](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L221)

Attempts to load a specific face from a font collection.

Parameters

**path string? required**

Path to a TrueType font file or collection, including OpenType fonts that use TrueType glyf outlines.

**collectionIndex int? required**

Zero-based collection face index, or null to select the first suitable face.

Returns

`OfficeTrueTypeFont?` The loaded font, or null when the path, index, or font data is invalid or inaccessible.

`public static OfficeTrueTypeFont? TryLoad(string? path, int? collectionIndex, string? faceName)` [#](#method-tryload-string-nullable-system-int32-string)

[OfficeTrueTypeFont.cs:229](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L229)

Attempts to load a font face that matches an optional collection index and face name.

Parameters

**path string? required**

Path to a TrueType font file or collection, including OpenType fonts that use TrueType glyf outlines.

**collectionIndex int? required**

Zero-based collection face index, or null to search the collection.

**faceName string? required**

Preferred family, full, or PostScript face name; null accepts any suitable face.

Returns

`OfficeTrueTypeFont?` The matching font, or null when the file cannot be read or no matching supported face exists.

`public static OfficeTrueTypeFont? TryLoad(byte[] data)` [#](#method-tryload-byte)

[OfficeTrueTypeFont.cs:257](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L257)

Attempts to decode a standalone font or the first suitable face in a font collection.

Parameters

**data byte[] required**

Complete TrueType font data, including OpenType data that uses TrueType glyf outlines.

Returns

`OfficeTrueTypeFont?` The decoded font, or null when the data is unsupported or malformed.

`public static OfficeTrueTypeFont? TryLoad(byte[] data, int? collectionIndex)` [#](#method-tryload-byte-nullable-system-int32)

[OfficeTrueTypeFont.cs:263](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L263)

Attempts to decode a specific face from in-memory font data.

Parameters

**data byte[] required**

Complete TrueType font or collection data, including OpenType fonts that use TrueType glyf outlines.

**collectionIndex int? required**

Zero-based collection face index, or null to select the first suitable face.

Returns

`OfficeTrueTypeFont?` The decoded font, or null when the data or requested index is invalid.

`public static OfficeTrueTypeFont? TryLoad(byte[] data, int? collectionIndex, string? faceName)` [#](#method-tryload-byte-nullable-system-int32-string)

[OfficeTrueTypeFont.cs:271](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L271)

Attempts to decode a font face matching an optional collection index and face name.

Parameters

**data byte[] required**

Complete TrueType font or collection data, including OpenType fonts that use TrueType glyf outlines.

**collectionIndex int? required**

Zero-based collection face index, or null to search the collection.

**faceName string? required**

Preferred family, full, or PostScript face name; null accepts any suitable face.

Returns

`OfficeTrueTypeFont?` The matching font, or null when the data is malformed, unsupported, or contains no matching face.

TryLoadDefault 2 overloads

`public static OfficeTrueTypeFont? TryLoadDefault()` [#](#method-tryloaddefault)

[OfficeTrueTypeFont.cs:164](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L164)

Attempts to load a common platform font without using operating-system font APIs.

Returns

`OfficeTrueTypeFont?` The first suitable font found, or null when none can be loaded.

`public static OfficeTrueTypeFont? TryLoadDefault(out string? resolvedPath)` [#](#method-tryloaddefault-string)

[OfficeTrueTypeFont.cs:171](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L171)

Attempts to load a common platform font file without using platform font APIs.

Parameters

**resolvedPath string? required**

Returns

`OfficeTrueTypeFont?`

TryLoadFontFamily 2 overloads

`public static OfficeTrueTypeFont? TryLoadFontFamily(string? fontFamily)` [#](#method-tryloadfontfamily-string)

[OfficeTrueTypeFont.cs:187](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L187)

Attempts to load the first resolvable font from a CSS/Office-style font-family fallback list.

Parameters

**fontFamily string? required**

Returns

`OfficeTrueTypeFont?`

`public static OfficeTrueTypeFont? TryLoadFontFamily(string? fontFamily, out string? resolvedPath)` [#](#method-tryloadfontfamily-string-string)

[OfficeTrueTypeFont.cs:194](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L194)

Attempts to load the first resolvable font from a CSS/Office-style font-family fallback list.

Parameters

**fontFamily string? required**

**resolvedPath string? required**

Returns

`OfficeTrueTypeFont?`

`public static OfficeTrueTypeFont? TryLoadFontFamilyForText(string? families, OfficeFontFaceDescriptor descriptor, string? text, out OfficeFontStyle resolvedStyle)` [#](#method-tryloadfontfamilyfortext-string-officeimo-drawing-officefontfacedescriptor-string-officeimo-drawing-officefontstyle)

[OfficeTrueTypeFont.NumericFamilies.cs:12](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.NumericFamilies.cs#L12)

Resolves an installed family using the same numeric face ordering as document-scoped fonts.

Parameters

**families string? required**

**descriptor OfficeIMO.Drawing.OfficeFontFaceDescriptor required**

**text string? required**

**resolvedStyle OfficeIMO.Drawing.OfficeFontStyle required**

Returns

`OfficeTrueTypeFont?`

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

## Properties

`public OfficeMathFontConstants? MathConstants { get; }` [#](#property-mathconstants)

[OfficeTrueTypeFont.cs:52](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L52)

Static font math design metrics, when the selected face supplies a valid MATH table.

`public string Fingerprint { get; }` [#](#property-fingerprint)

[OfficeTrueTypeFont.cs:134](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L134)

Stable provider-defined identity for the decoded program and selected instance. The value must change when rendering-relevant configuration, such as variable-font axes, changes.

`public string? DisplayName { get; }` [#](#property-displayname)

[OfficeTrueTypeFont.cs:541](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L541)

Best-effort display name read from the font name table.

`public int? CollectionIndex { get; }` [#](#property-collectionindex)

[OfficeTrueTypeFont.cs:544](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.cs#L544)

Collection index when the font was loaded from a TrueType collection.

`public OfficeFontFaceDescriptor FaceDescriptor { get; }` [#](#property-facedescriptor)

[OfficeTrueTypeFont.NumericFamilies.cs:8](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.NumericFamilies.cs#L8)

Face attributes declared by the font's OS/2 and head tables.

`public bool IsOpenTypeCff { get; }` [#](#property-isopentypecff)

[OfficeTrueTypeFont.Shaping.cs:98](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.Shaping.cs#L98)

Whether the source uses CFF or CFF2 outlines.

`public bool ProvidesComplexTextLayout { get; }` [#](#property-providescomplextextlayout)

[OfficeTrueTypeFont.Shaping.cs:101](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/OfficeTrueTypeFont.Shaping.cs#L101)

Whether measurement and contours already apply complete script shaping and bidirectional layout.

<!-- PowerForge markdown artifact sha256:9ECC67A339EFD64112F2B84CE02DC392F229A7C4EE2FF790FBBC0D17C0B73F7F -->
