API Reference
OfficeTextLayoutEngine
Shared dependency-free text layout helpers for OfficeIMO renderers.
Inheritance
- Object
- OfficeTextLayoutEngine
Methods
public static OfficeTextBlockLayout ClipTextBlockToHeight(IReadOnlyList<OfficeTextLine> lines, Double fontSize, Double lineHeight, Double maxWidth, Double maxHeight, Func<String, Double, Double> measure, Boolean alreadyClipped = false) #OfficeTextBlockLayoutClips 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}
- Measured text lines to clip.
- fontSize System.Double
- Resolved font size used for measurement.
- lineHeight System.Double
- Resolved line height.
- maxWidth System.Double
- Maximum line width used for ellipsis trimming.
- maxHeight System.Double
- Maximum block height.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- alreadyClipped System.Boolean = false
- 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) #OfficeTextBlockLayoutClips 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}
- Measured text lines to clip.
- fontSize System.Double
- Resolved font size used for measurement.
- lineHeight System.Double
- Resolved line height.
- maxWidth System.Double
- Maximum line width used for ellipsis trimming.
- maxHeight System.Double
- Maximum block height.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- alreadyClipped System.Boolean
- Whether an earlier layout stage already clipped or ellipsized the text.
- overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior
- 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) #DoubleFinds the largest single-line font size that fits within the requested width.
Parameters
- text System.String
- Text to measure.
- fontSize System.Double
- Initial font size passed to measure.
- maxWidth System.Double
- Maximum accepted line width.
- minimumFontSize System.Double
- Minimum font size when fitting is required.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- iterations System.Int32 = 10
- 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) #OfficeTextBlockLayoutWraps and measures a text block, reducing font size when the measured block does not fit the requested bounds.
Parameters
- text System.String
- Text to wrap and measure.
- fontSize System.Double
- Initial font size passed to measure.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used to derive line height from font size.
- minimumFontSize System.Double
- Minimum font size when scaling down to fit.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- 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.
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) #OfficeRichTextBlockLayoutLays 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}
- Styled text runs.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- wrap System.Boolean
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit System.Boolean = false
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize System.Double = 1
- Minimum font size for any run when shrinkToFit is enabled.
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- 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) #OfficeRichTextBlockLayoutLays 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}
- Styled text runs.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- wrap System.Boolean
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit System.Boolean
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize System.Double
- Minimum font size for any run when shrinkToFit is enabled.
- overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior
- How overflowing rich text should be represented in the returned layout.
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- 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) #OfficeRichTextBlockLayoutLays 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}
- Styled text runs.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func{System.String,System.Double,System.String,System.Double}
- Measurement delegate matching String).
- wrap System.Boolean
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit System.Boolean = false
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize System.Double = 1
- Minimum font size for any run when shrinkToFit is enabled.
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- 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) #OfficeRichTextBlockLayoutLays 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}
- Styled text runs.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func{System.String,System.Double,System.String,System.Double}
- Measurement delegate matching String).
- wrap System.Boolean
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit System.Boolean
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize System.Double
- Minimum font size for any run when shrinkToFit is enabled.
- overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior
- How overflowing rich text should be represented in the returned layout.
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- 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) #OfficeRichTextBlockLayoutLays out styled rich text runs into a bounded text block with cooperative cancellation.
Parameters
- runs System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeRichTextRun}
- Styled text runs.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func{System.String,System.Double,System.String,System.Double}
- Measurement delegate matching String).
- wrap System.Boolean
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit System.Boolean
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize System.Double
- Minimum font size for any run when shrinkToFit is enabled.
- overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior
- How overflowing rich text should be represented in the returned layout.
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent}
- Optional first-line and continuation-line offsets applied while laying out wrapped rich text.
- cancellationToken System.Threading.CancellationToken
- Token checked while normalizing, tokenizing, measuring, and wrapping rich text.
Returns
Measured rich text block with visible lines and clipping state.
public static OfficeRichTextBlockLayout LayoutStackedRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, Double maxWidth, Double maxHeight, Double lineHeightFactor, Func<String, Double, Double> measure, Boolean shrinkToFit = true, Double minimumFontSize = 1) #OfficeRichTextBlockLayoutLays 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}
- Styled text runs.
- maxWidth System.Double
- Maximum stacked block width.
- maxHeight System.Double
- Maximum stacked block height.
- lineHeightFactor System.Double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- shrinkToFit System.Boolean = true
- Whether the stacked block should reduce font sizes to fit both width and height.
- minimumFontSize System.Double = 1
- 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) #OfficeRichTextBlockLayoutLays 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}
- Styled text runs.
- maxWidth System.Double
- Maximum stacked block width.
- maxHeight System.Double
- Maximum stacked block height.
- lineHeightFactor System.Double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func{System.String,System.Double,System.String,System.Double}
- Measurement delegate matching String).
- shrinkToFit System.Boolean = true
- Whether the stacked block should reduce font sizes to fit both width and height.
- minimumFontSize System.Double = 1
- 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) #OfficeTextBlockLayoutLays out text as upright stacked text elements for vertical cell and shape renderers.
Parameters
- text System.String
- Text to stack. CR/LF breaks are ignored because each text element becomes its own line.
- fontSize System.Double
- Initial font size passed to measure.
- maxWidth System.Double
- Maximum stacked block width.
- maxHeight System.Double
- Maximum stacked block height.
- lineHeightFactor System.Double
- Multiplier used to derive line height from font size.
- minimumFontSize System.Double
- Minimum font size when scaling down to fit.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- shrinkToFit System.Boolean = true
- 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.
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) #OfficeTextBlockLayoutLays out a bounded text block with optional wrapping, single-line normalization, shrink-to-fit, and height clipping.
Parameters
- text System.String
- Text to lay out.
- fontSize System.Double
- Initial font size passed to measure.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used to derive line height from font size.
- minimumFontSize System.Double
- Minimum font size when single-line shrink-to-fit is enabled.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- wrap System.Boolean
- Whether soft wrapping is enabled.
- forceSingleLine System.Boolean = false
- Whether line breaks should be normalized to spaces and wrapping disabled.
- shrinkToFit System.Boolean = false
- Whether single-line text should reduce font size to fit the requested width.
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- 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) #OfficeTextBlockLayoutLays out a bounded text block with optional wrapping, single-line normalization, shrink-to-fit, overflow policy, and height clipping.
Parameters
- text System.String
- Text to lay out.
- fontSize System.Double
- Initial font size passed to measure.
- maxWidth System.Double
- Maximum block width.
- maxHeight System.Double
- Maximum block height.
- lineHeightFactor System.Double
- Multiplier used to derive line height from font size.
- minimumFontSize System.Double
- Minimum font size when single-line shrink-to-fit is enabled.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- wrap System.Boolean
- Whether soft wrapping is enabled.
- forceSingleLine System.Boolean
- Whether line breaks should be normalized to spaces and wrapping disabled.
- shrinkToFit System.Boolean
- Whether single-line text should reduce font size to fit the requested width.
- overflowBehavior OfficeIMO.Drawing.OfficeTextOverflowBehavior
- How overflowing text should be represented in the returned layout.
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- 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) #DoubleGets the widest measured line.
Parameters
- lines System.Collections.Generic.IReadOnlyList{OfficeIMO.Drawing.OfficeTextLine}
- 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) #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
- fontSize System.Double
- measure System.Func{System.String,System.Double,System.Double}
public static Double ResolveRotatedTextWidthLimit(Double availableWidth, Double availableHeight, Double lineHeight, Double rotationDegrees) #DoubleEstimates the maximum unrotated single-line text width that can remain inside a rotated bounding rectangle.
Parameters
- availableWidth System.Double
- Available unrotated rectangle width.
- availableHeight System.Double
- Available unrotated rectangle height.
- lineHeight System.Double
- Estimated rendered line height.
- rotationDegrees System.Double
- 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) #OfficeTextLineMeasures a single line and trims the beginning with an ellipsis when it exceeds the requested width.
Parameters
- text System.String
- Text to measure and trim.
- fontSize System.Double
- Font size passed to measure.
- maxWidth System.Double
- Maximum accepted line width.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- clipped System.Boolean@
- 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) #OfficeTextLineMeasures a single line and trims it with an ellipsis when it exceeds the requested width.
Parameters
- text System.String
- Text to measure and trim.
- fontSize System.Double
- Font size passed to measure.
- maxWidth System.Double
- Maximum accepted line width.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- clipped System.Boolean@
- 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) #IReadOnlyList<OfficeTextLine>Wraps text into measured lines using the supplied measurement delegate.
Parameters
- text System.String
- Text to wrap. CRLF and CR line breaks are normalized to LF.
- fontSize System.Double
- Font size passed to measure.
- maxWidth System.Double
- Maximum line width before wrapping or breaking long words.
- measure System.Func{System.String,System.Double,System.Double}
- Measurement delegate matching Double).
- paragraphIndent System.Nullable{OfficeIMO.Drawing.OfficeTextParagraphIndent} = null
- Optional first-line and continuation-line offsets applied while wrapping.
Returns
Measured wrapped lines. Empty input returns one empty line.
Inherited Methods
public override Boolean Equals(Object obj) #BooleanParameters
- obj Object