Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/

API Reference

Class

OfficeTextLayoutEngine

Namespace OfficeIMO.Drawing
Assembly OfficeIMO.Core
Modifiers static

Shared dependency-free text layout helpers for OfficeIMO renderers.

Inheritance

  • Object
  • OfficeTextLayoutEngine

Methods

ClipTextBlockToHeight 2 overloads
public static OfficeTextBlockLayout ClipTextBlockToHeight(IReadOnlyList<OfficeTextLine> lines, Double fontSize, Double lineHeight, Double maxWidth, Double maxHeight, Func<String, Double, Double> measure, Boolean alreadyClipped = false) #
Returns: OfficeTextBlockLayout

Clips measured text lines to the requested block height and ellipsizes the last visible line when lines are omitted.

Parameters

lines System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeTextLine} requiredposition: 0
Measured text lines to clip.
fontSize System.Double requiredposition: 1
Resolved font size used for measurement.
lineHeight System.Double requiredposition: 2
Resolved line height.
maxWidth System.Double requiredposition: 3
Maximum line width used for ellipsis trimming.
maxHeight System.Double requiredposition: 4
Maximum block height.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 5
Measurement delegate matching Double).
alreadyClipped System.Boolean = false optionalposition: 6
Whether an earlier layout stage already clipped or ellipsized the text.

Returns

A measured text block whose visible lines fit the requested height.

public static OfficeTextBlockLayout ClipTextBlockToHeight(IReadOnlyList<OfficeTextLine> lines, Double fontSize, Double lineHeight, Double maxWidth, Double maxHeight, Func<String, Double, Double> measure, Boolean alreadyClipped, OfficeTextOverflowBehavior overflowBehavior) #
Returns: OfficeTextBlockLayout

Clips measured text lines to the requested block height and applies the requested overflow policy to omitted lines.

Parameters

lines System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeTextLine} requiredposition: 0
Measured text lines to clip.
fontSize System.Double requiredposition: 1
Resolved font size used for measurement.
lineHeight System.Double requiredposition: 2
Resolved line height.
maxWidth System.Double requiredposition: 3
Maximum line width used for ellipsis trimming.
maxHeight System.Double requiredposition: 4
Maximum block height.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 5
Measurement delegate matching Double).
alreadyClipped System.Boolean requiredposition: 6
Whether an earlier layout stage already clipped or ellipsized the text.
overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior requiredposition: 7
How omitted or oversized text should be represented in the returned layout.

Returns

A measured text block whose visible lines fit the requested height.

public static Double FitSingleLineFontSize(String text, Double fontSize, Double maxWidth, Double minimumFontSize, Func<String, Double, Double> measure, Int32 iterations = 10) #
Returns: Double

Finds the largest single-line font size that fits within the requested width.

Parameters

text System.String requiredposition: 0
Text to measure.
fontSize System.Double requiredposition: 1
Initial font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum accepted line width.
minimumFontSize System.Double requiredposition: 3
Minimum font size when fitting is required.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 4
Measurement delegate matching Double).
iterations System.Int32 = 10 optionalposition: 5
Number of binary-search iterations used between the minimum and initial font size.

Returns

The initial font size when text already fits; otherwise the largest measured size above the minimum that fits.

public static OfficeTextBlockLayout FitWrappedText(String text, Double fontSize, Double maxWidth, Double maxHeight, Double lineHeightFactor, Double minimumFontSize, Func<String, Double, Double> measure, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: OfficeTextBlockLayout

Wraps and measures a text block, reducing font size when the measured block does not fit the requested bounds.

Parameters

text System.String requiredposition: 0
Text to wrap and measure.
fontSize System.Double requiredposition: 1
Initial font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum block width.
maxHeight System.Double requiredposition: 3
Maximum block height.
lineHeightFactor System.Double requiredposition: 4
Multiplier used to derive line height from font size.
minimumFontSize System.Double requiredposition: 5
Minimum font size when scaling down to fit.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 6
Measurement delegate matching Double).
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 7
Optional first-line and continuation-line offsets applied while fitting wrapped text.

Returns

Measured text block with the resolved font size, line height, width, height, and lines.

LayoutRichTextBlock 5 overloads
public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, Double> measure, Boolean wrap, Boolean shrinkToFit = false, Double minimumFontSize = 1, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: OfficeRichTextBlockLayout

Lays out styled rich text runs into a bounded text block with optional wrapping and height clipping.

Parameters

runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun} requiredposition: 0
Styled text runs.
maxWidth System.Double requiredposition: 1
Maximum block width.
maxHeight System.Double requiredposition: 2
Maximum block height.
lineHeightFactor System.Double requiredposition: 3
Multiplier used with the largest run font size to derive line height.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 4
Measurement delegate matching Double).
wrap System.Boolean requiredposition: 5
Whether soft wrapping is enabled. Hard line breaks are always honored.
shrinkToFit System.Boolean = false optionalposition: 6
Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
minimumFontSize System.Double = 1 optionalposition: 7
Minimum font size for any run when shrinkToFit is enabled.
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 8
Optional first-line and continuation-line offsets applied while laying out wrapped rich text.

Returns

Measured rich text block with visible lines and clipping state.

public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, Double> measure, Boolean wrap, Boolean shrinkToFit, Double minimumFontSize, OfficeTextOverflowBehavior overflowBehavior, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: OfficeRichTextBlockLayout

Lays out styled rich text runs into a bounded text block with optional wrapping, overflow policy, and height clipping.

Parameters

runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun} requiredposition: 0
Styled text runs.
maxWidth System.Double requiredposition: 1
Maximum block width.
maxHeight System.Double requiredposition: 2
Maximum block height.
lineHeightFactor System.Double requiredposition: 3
Multiplier used with the largest run font size to derive line height.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 4
Measurement delegate matching Double).
wrap System.Boolean requiredposition: 5
Whether soft wrapping is enabled. Hard line breaks are always honored.
shrinkToFit System.Boolean requiredposition: 6
Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
minimumFontSize System.Double requiredposition: 7
Minimum font size for any run when shrinkToFit is enabled.
overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior requiredposition: 8
How overflowing rich text should be represented in the returned layout.
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 9
Optional first-line and continuation-line offsets applied while laying out wrapped rich text.

Returns

Measured rich text block with visible lines and clipping state.

public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, String, Double> measure, Boolean wrap, Boolean shrinkToFit = false, Double minimumFontSize = 1, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: OfficeRichTextBlockLayout

Lays out styled rich text runs into a bounded text block with optional wrapping and height clipping.

Parameters

runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun} requiredposition: 0
Styled text runs.
maxWidth System.Double requiredposition: 1
Maximum block width.
maxHeight System.Double requiredposition: 2
Maximum block height.
lineHeightFactor System.Double requiredposition: 3
Multiplier used with the largest run font size to derive line height.
measure System.Func{System.String,System.Double,System.String,System.Double} requiredposition: 4
Measurement delegate matching String).
wrap System.Boolean requiredposition: 5
Whether soft wrapping is enabled. Hard line breaks are always honored.
shrinkToFit System.Boolean = false optionalposition: 6
Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
minimumFontSize System.Double = 1 optionalposition: 7
Minimum font size for any run when shrinkToFit is enabled.
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 8
Optional first-line and continuation-line offsets applied while laying out wrapped rich text.

Returns

Measured rich text block with visible lines and clipping state.

public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, String, Double> measure, Boolean wrap, Boolean shrinkToFit, Double minimumFontSize, OfficeTextOverflowBehavior overflowBehavior, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: OfficeRichTextBlockLayout

Lays out styled rich text runs into a bounded text block with optional wrapping, overflow policy, and height clipping.

Parameters

runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun} requiredposition: 0
Styled text runs.
maxWidth System.Double requiredposition: 1
Maximum block width.
maxHeight System.Double requiredposition: 2
Maximum block height.
lineHeightFactor System.Double requiredposition: 3
Multiplier used with the largest run font size to derive line height.
measure System.Func{System.String,System.Double,System.String,System.Double} requiredposition: 4
Measurement delegate matching String).
wrap System.Boolean requiredposition: 5
Whether soft wrapping is enabled. Hard line breaks are always honored.
shrinkToFit System.Boolean requiredposition: 6
Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
minimumFontSize System.Double requiredposition: 7
Minimum font size for any run when shrinkToFit is enabled.
overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior requiredposition: 8
How overflowing rich text should be represented in the returned layout.
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 9
Optional first-line and continuation-line offsets applied while laying out wrapped rich text.

Returns

Measured rich text block with visible lines and clipping state.

public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, String, Double> measure, Boolean wrap, Boolean shrinkToFit, Double minimumFontSize, OfficeTextOverflowBehavior overflowBehavior, Nullable<OfficeTextParagraphIndent> paragraphIndent, CancellationToken cancellationToken) #
Returns: OfficeRichTextBlockLayout

Lays out styled rich text runs into a bounded text block with cooperative cancellation.

Parameters

runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun} requiredposition: 0
Styled text runs.
maxWidth System.Double requiredposition: 1
Maximum block width.
maxHeight System.Double requiredposition: 2
Maximum block height.
lineHeightFactor System.Double requiredposition: 3
Multiplier used with the largest run font size to derive line height.
measure System.Func{System.String,System.Double,System.String,System.Double} requiredposition: 4
Measurement delegate matching String).
wrap System.Boolean requiredposition: 5
Whether soft wrapping is enabled. Hard line breaks are always honored.
shrinkToFit System.Boolean requiredposition: 6
Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
minimumFontSize System.Double requiredposition: 7
Minimum font size for any run when shrinkToFit is enabled.
overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior requiredposition: 8
How overflowing rich text should be represented in the returned layout.
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} requiredposition: 9
Optional first-line and continuation-line offsets applied while laying out wrapped rich text.
cancellationToken System.Threading.CancellationToken requiredposition: 10
Token checked while normalizing, tokenizing, measuring, and wrapping rich text.

Returns

Measured rich text block with visible lines and clipping state.

LayoutStackedRichTextBlock 2 overloads
public static OfficeRichTextBlockLayout LayoutStackedRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, Double> measure, Boolean shrinkToFit = true, Double minimumFontSize = 1) #
Returns: OfficeRichTextBlockLayout

Lays out styled rich text runs as upright stacked text elements for vertical cell and shape renderers.

Parameters

runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun} requiredposition: 0
Styled text runs.
maxWidth System.Double requiredposition: 1
Maximum stacked block width.
maxHeight System.Double requiredposition: 2
Maximum stacked block height.
lineHeightFactor System.Double requiredposition: 3
Multiplier used with the largest run font size to derive line height.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 4
Measurement delegate matching Double).
shrinkToFit System.Boolean = true optionalposition: 5
Whether the stacked block should reduce font sizes to fit both width and height.
minimumFontSize System.Double = 1 optionalposition: 6
Minimum font size when scaling down to fit.

Returns

A measured rich text block with one Unicode text element per line.

public static OfficeRichTextBlockLayout LayoutStackedRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, String, Double> measure, Boolean shrinkToFit = true, Double minimumFontSize = 1) #
Returns: OfficeRichTextBlockLayout

Lays out styled rich text runs as upright stacked text elements for vertical cell and shape renderers.

Parameters

runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun} requiredposition: 0
Styled text runs.
maxWidth System.Double requiredposition: 1
Maximum stacked block width.
maxHeight System.Double requiredposition: 2
Maximum stacked block height.
lineHeightFactor System.Double requiredposition: 3
Multiplier used with the largest run font size to derive line height.
measure System.Func{System.String,System.Double,System.String,System.Double} requiredposition: 4
Measurement delegate matching String).
shrinkToFit System.Boolean = true optionalposition: 5
Whether the stacked block should reduce font sizes to fit both width and height.
minimumFontSize System.Double = 1 optionalposition: 6
Minimum font size when scaling down to fit.

Returns

A measured rich text block with one Unicode text element per line.

public static OfficeTextBlockLayout LayoutStackedTextBlock(String text, Double fontSize, Double maxWidth, Double maxHeight, Double lineHeightFactor, Double minimumFontSize, Func<String, Double, Double> measure, Boolean shrinkToFit = true) #
Returns: OfficeTextBlockLayout

Lays out text as upright stacked text elements for vertical cell and shape renderers.

Parameters

text System.String requiredposition: 0
Text to stack. CR/LF breaks are ignored because each text element becomes its own line.
fontSize System.Double requiredposition: 1
Initial font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum stacked block width.
maxHeight System.Double requiredposition: 3
Maximum stacked block height.
lineHeightFactor System.Double requiredposition: 4
Multiplier used to derive line height from font size.
minimumFontSize System.Double requiredposition: 5
Minimum font size when scaling down to fit.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 6
Measurement delegate matching Double).
shrinkToFit System.Boolean = true optionalposition: 7
Whether the stacked block should reduce font size to fit both width and height.

Returns

A measured text block with one Unicode text element per line.

LayoutTextBlock 2 overloads
public static OfficeTextBlockLayout LayoutTextBlock(String text, Double fontSize, Double maxWidth, Double maxHeight, Double lineHeightFactor, Double minimumFontSize, Func<String, Double, Double> measure, Boolean wrap, Boolean forceSingleLine = false, Boolean shrinkToFit = false, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: OfficeTextBlockLayout

Lays out a bounded text block with optional wrapping, single-line normalization, shrink-to-fit, and height clipping.

Parameters

text System.String requiredposition: 0
Text to lay out.
fontSize System.Double requiredposition: 1
Initial font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum block width.
maxHeight System.Double requiredposition: 3
Maximum block height.
lineHeightFactor System.Double requiredposition: 4
Multiplier used to derive line height from font size.
minimumFontSize System.Double requiredposition: 5
Minimum font size when single-line shrink-to-fit is enabled.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 6
Measurement delegate matching Double).
wrap System.Boolean requiredposition: 7
Whether soft wrapping is enabled.
forceSingleLine System.Boolean = false optionalposition: 8
Whether line breaks should be normalized to spaces and wrapping disabled.
shrinkToFit System.Boolean = false optionalposition: 9
Whether single-line text should reduce font size to fit the requested width.
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 10
Optional first-line and continuation-line offsets applied while laying out wrapped text.

Returns

Measured text block with the resolved font size, line height, width, height, lines, and clipping state.

public static OfficeTextBlockLayout LayoutTextBlock(String text, Double fontSize, Double maxWidth, Double maxHeight, Double lineHeightFactor, Double minimumFontSize, Func<String, Double, Double> measure, Boolean wrap, Boolean forceSingleLine, Boolean shrinkToFit, OfficeTextOverflowBehavior overflowBehavior, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: OfficeTextBlockLayout

Lays out a bounded text block with optional wrapping, single-line normalization, shrink-to-fit, overflow policy, and height clipping.

Parameters

text System.String requiredposition: 0
Text to lay out.
fontSize System.Double requiredposition: 1
Initial font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum block width.
maxHeight System.Double requiredposition: 3
Maximum block height.
lineHeightFactor System.Double requiredposition: 4
Multiplier used to derive line height from font size.
minimumFontSize System.Double requiredposition: 5
Minimum font size when single-line shrink-to-fit is enabled.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 6
Measurement delegate matching Double).
wrap System.Boolean requiredposition: 7
Whether soft wrapping is enabled.
forceSingleLine System.Boolean requiredposition: 8
Whether line breaks should be normalized to spaces and wrapping disabled.
shrinkToFit System.Boolean requiredposition: 9
Whether single-line text should reduce font size to fit the requested width.
overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior requiredposition: 10
How overflowing text should be represented in the returned layout.
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 11
Optional first-line and continuation-line offsets applied while laying out wrapped text.

Returns

Measured text block with the resolved font size, line height, width, height, lines, and clipping state.

public static Double MeasureMaxLineWidth(IReadOnlyList<OfficeTextLine> lines) #
Returns: Double

Gets the widest measured line.

Parameters

lines System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeTextLine} requiredposition: 0
Measured text lines.

Returns

The maximum Width value, or zero for an empty set.

public static IReadOnlyList<OfficeTextLine> MeasureUnwrappedLines(String text, Double fontSize, Func<String, Double, Double> measure) #
Returns: IReadOnlyList<OfficeTextLine>

Measures authored lines without applying word wrapping or trimming authored whitespace. Tabs are expanded deterministically and line-count/text-size safety limits still apply.

Parameters

text System.String requiredposition: 0
fontSize System.Double requiredposition: 1
measure System.Func{System.String,System.Double,System.Double} requiredposition: 2
public static Double ResolveRotatedTextWidthLimit(Double availableWidth, Double availableHeight, Double lineHeight, Double rotationDegrees) #
Returns: Double

Estimates the maximum unrotated single-line text width that can remain inside a rotated bounding rectangle.

Parameters

availableWidth System.Double requiredposition: 0
Available unrotated rectangle width.
availableHeight System.Double requiredposition: 1
Available unrotated rectangle height.
lineHeight System.Double requiredposition: 2
Estimated rendered line height.
rotationDegrees System.Double requiredposition: 3
Clockwise rotation in degrees.

Returns

A positive width limit that callers can pass to single-line rotated text layout.

public static OfficeTextLine TrimLineStartToWidth(String text, Double fontSize, Double maxWidth, Func<String, Double, Double> measure, out Boolean clipped) #
Returns: OfficeTextLine

Measures a single line and trims the beginning with an ellipsis when it exceeds the requested width.

Parameters

text System.String requiredposition: 0
Text to measure and trim.
fontSize System.Double requiredposition: 1
Font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum accepted line width.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 3
Measurement delegate matching Double).
clipped System.Boolean@ requiredposition: 4
Set to true when the returned line had to be shortened.

Returns

The measured line, possibly shortened with a leading ellipsis.

public static OfficeTextLine TrimLineToWidth(String text, Double fontSize, Double maxWidth, Func<String, Double, Double> measure, out Boolean clipped) #
Returns: OfficeTextLine

Measures a single line and trims it with an ellipsis when it exceeds the requested width.

Parameters

text System.String requiredposition: 0
Text to measure and trim.
fontSize System.Double requiredposition: 1
Font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum accepted line width.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 3
Measurement delegate matching Double).
clipped System.Boolean@ requiredposition: 4
Set to true when the returned line had to be shortened.

Returns

The measured line, possibly shortened with an ellipsis.

public static IReadOnlyList<OfficeTextLine> WrapLines(String text, Double fontSize, Double maxWidth, Func<String, Double, Double> measure, Nullable<OfficeTextParagraphIndent> paragraphIndent = null) #
Returns: IReadOnlyList<OfficeTextLine>

Wraps text into measured lines using the supplied measurement delegate.

Parameters

text System.String requiredposition: 0
Text to wrap. CRLF and CR line breaks are normalized to LF.
fontSize System.Double requiredposition: 1
Font size passed to measure.
maxWidth System.Double requiredposition: 2
Maximum line width before wrapping or breaking long words.
measure System.Func{System.String,System.Double,System.Double} requiredposition: 3
Measurement delegate matching Double).
paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null optionalposition: 4
Optional first-line and continuation-line offsets applied while wrapping.

Returns

Measured wrapped lines. Empty input returns one empty line.