OfficeTextLayoutEngine
OfficeIMO.Drawing
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, bool alreadyClipped = false) #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>
- Measured text lines to clip.
- fontSize double
- Resolved font size used for measurement.
- lineHeight double
- Resolved line height.
- maxWidth double
- Maximum line width used for ellipsis trimming.
- maxHeight double
- Maximum block height.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- alreadyClipped bool = false
- Whether an earlier layout stage already clipped or ellipsized the text.
public static OfficeTextBlockLayout ClipTextBlockToHeight(IReadOnlyList<OfficeTextLine> lines, double fontSize, double lineHeight, double maxWidth, double maxHeight, Func<string?, double, double> measure, bool alreadyClipped, OfficeTextOverflowBehavior overflowBehavior) #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>
- Measured text lines to clip.
- fontSize double
- Resolved font size used for measurement.
- lineHeight double
- Resolved line height.
- maxWidth double
- Maximum line width used for ellipsis trimming.
- maxHeight double
- Maximum block height.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- alreadyClipped bool
- 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.
public static double FitSingleLineFontSize(string? text, double fontSize, double maxWidth, double minimumFontSize, Func<string?, double, double> measure, int iterations = 10) #Finds the largest single-line font size that fits within the requested width.
Parameters
- text string?
- Text to measure.
- fontSize double
- Initial font size passed to measure.
- maxWidth double
- Maximum accepted line width.
- minimumFontSize double
- Minimum font size when fitting is required.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- iterations int = 10
- Number of binary-search iterations used between the minimum and initial font size.
Returns
double 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, OfficeTextParagraphIndent? paragraphIndent = null) #Wraps and measures a text block, reducing font size when the measured block does not fit the requested bounds.
Parameters
- text string?
- Text to wrap and measure.
- fontSize double
- Initial font size passed to measure.
- maxWidth double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used to derive line height from font size.
- minimumFontSize double
- Minimum font size when scaling down to fit.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- paragraphIndent OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while fitting wrapped text.
Returns
OfficeTextBlockLayout 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, bool wrap, bool shrinkToFit = false, double minimumFontSize = 1, OfficeTextParagraphIndent? paragraphIndent = null) #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>
- Styled text runs.
- maxWidth double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- wrap bool
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit bool = false
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize double = 1
- Minimum font size for any run when shrinkToFit is enabled.
- paragraphIndent OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while laying out wrapped rich text.
public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, double maxWidth, double maxHeight, double lineHeightFactor, Func<string?, double, double> measure, bool wrap, bool shrinkToFit, double minimumFontSize, OfficeTextOverflowBehavior overflowBehavior, OfficeTextParagraphIndent? paragraphIndent = null) #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>
- Styled text runs.
- maxWidth double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- wrap bool
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit bool
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize 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 OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while laying out wrapped rich text.
public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, double maxWidth, double maxHeight, double lineHeightFactor, Func<string?, double, string?, double> measure, bool wrap, bool shrinkToFit = false, double minimumFontSize = 1, OfficeTextParagraphIndent? paragraphIndent = null) #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>
- Styled text runs.
- maxWidth double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func<string?, double, string?, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- wrap bool
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit bool = false
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize double = 1
- Minimum font size for any run when shrinkToFit is enabled.
- paragraphIndent OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while laying out wrapped rich text.
public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, double maxWidth, double maxHeight, double lineHeightFactor, Func<string?, double, string?, double> measure, bool wrap, bool shrinkToFit, double minimumFontSize, OfficeTextOverflowBehavior overflowBehavior, OfficeTextParagraphIndent? paragraphIndent = null) #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>
- Styled text runs.
- maxWidth double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func<string?, double, string?, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- wrap bool
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit bool
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize 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 OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while laying out wrapped rich text.
public static OfficeRichTextBlockLayout LayoutRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, double maxWidth, double maxHeight, double lineHeightFactor, Func<string?, double, string?, double> measure, bool wrap, bool shrinkToFit, double minimumFontSize, OfficeTextOverflowBehavior overflowBehavior, OfficeTextParagraphIndent? paragraphIndent, CancellationToken cancellationToken) #Lays 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 double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func<string?, double, string?, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- wrap bool
- Whether soft wrapping is enabled. Hard line breaks are always honored.
- shrinkToFit bool
- Whether non-wrapped rich text should proportionally shrink run font sizes to fit the requested width.
- minimumFontSize 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 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.
public static OfficeRichTextBlockLayout LayoutStackedRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, double maxWidth, double maxHeight, double lineHeightFactor, Func<string?, double, double> measure, bool shrinkToFit = true, double minimumFontSize = 1) #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>
- Styled text runs.
- maxWidth double
- Maximum stacked block width.
- maxHeight double
- Maximum stacked block height.
- lineHeightFactor double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- shrinkToFit bool = true
- Whether the stacked block should reduce font sizes to fit both width and height.
- minimumFontSize double = 1
- Minimum font size when scaling down to fit.
public static OfficeRichTextBlockLayout LayoutStackedRichTextBlock(IReadOnlyList<OfficeRichTextRun> runs, double maxWidth, double maxHeight, double lineHeightFactor, Func<string?, double, string?, double> measure, bool shrinkToFit = true, double minimumFontSize = 1) #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>
- Styled text runs.
- maxWidth double
- Maximum stacked block width.
- maxHeight double
- Maximum stacked block height.
- lineHeightFactor double
- Multiplier used with the largest run font size to derive line height.
- measure System.Func<string?, double, string?, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- shrinkToFit bool = true
- Whether the stacked block should reduce font sizes to fit both width and height.
- minimumFontSize double = 1
- Minimum font size when scaling down to fit.
public static OfficeTextBlockLayout LayoutStackedTextBlock(string? text, double fontSize, double maxWidth, double maxHeight, double lineHeightFactor, double minimumFontSize, Func<string?, double, double> measure, bool shrinkToFit = true) #Lays out text as upright stacked text elements for vertical cell and shape renderers.
Parameters
- text string?
- Text to stack. CR/LF breaks are ignored because each text element becomes its own line.
- fontSize double
- Initial font size passed to measure.
- maxWidth double
- Maximum stacked block width.
- maxHeight double
- Maximum stacked block height.
- lineHeightFactor double
- Multiplier used to derive line height from font size.
- minimumFontSize double
- Minimum font size when scaling down to fit.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- shrinkToFit bool = true
- Whether the stacked block should reduce font size to fit both width and height.
public static OfficeTextBlockLayout LayoutTextBlock(string? text, double fontSize, double maxWidth, double maxHeight, double lineHeightFactor, double minimumFontSize, Func<string?, double, double> measure, bool wrap, bool forceSingleLine = false, bool shrinkToFit = false, OfficeTextParagraphIndent? paragraphIndent = null) #Lays out a bounded text block with optional wrapping, single-line normalization, shrink-to-fit, and height clipping.
Parameters
- text string?
- Text to lay out.
- fontSize double
- Initial font size passed to measure.
- maxWidth double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used to derive line height from font size.
- minimumFontSize double
- Minimum font size when single-line shrink-to-fit is enabled.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- wrap bool
- Whether soft wrapping is enabled.
- forceSingleLine bool = false
- Whether line breaks should be normalized to spaces and wrapping disabled.
- shrinkToFit bool = false
- Whether single-line text should reduce font size to fit the requested width.
- paragraphIndent OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while laying out wrapped text.
Returns
OfficeTextBlockLayout 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, bool wrap, bool forceSingleLine, bool shrinkToFit, OfficeTextOverflowBehavior overflowBehavior, OfficeTextParagraphIndent? paragraphIndent = null) #Lays out a bounded text block with optional wrapping, single-line normalization, shrink-to-fit, overflow policy, and height clipping.
Parameters
- text string?
- Text to lay out.
- fontSize double
- Initial font size passed to measure.
- maxWidth double
- Maximum block width.
- maxHeight double
- Maximum block height.
- lineHeightFactor double
- Multiplier used to derive line height from font size.
- minimumFontSize double
- Minimum font size when single-line shrink-to-fit is enabled.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- wrap bool
- Whether soft wrapping is enabled.
- forceSingleLine bool
- Whether line breaks should be normalized to spaces and wrapping disabled.
- shrinkToFit bool
- 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 OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while laying out wrapped text.
Returns
OfficeTextBlockLayout Measured text block with the resolved font size, line height, width, height, lines, and clipping state.public static double MeasureMaxLineWidth(IReadOnlyList<OfficeTextLine> lines) #Gets the widest measured line.
Parameters
- lines System.Collections.Generic.IReadOnlyList<OfficeIMO.Drawing.OfficeTextLine>
- Measured text lines.
public static IReadOnlyList<OfficeTextLine> MeasureUnwrappedLines(string? text, double fontSize, Func<string?, double, double> measure) #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 string?
- fontSize double
- measure System.Func<string?, double, double>
Returns
IReadOnlyList<OfficeTextLine>public static double ResolveRotatedTextWidthLimit(double availableWidth, double availableHeight, double lineHeight, double rotationDegrees) #Estimates the maximum unrotated single-line text width that can remain inside a rotated bounding rectangle.
Parameters
- availableWidth double
- Available unrotated rectangle width.
- availableHeight double
- Available unrotated rectangle height.
- lineHeight double
- Estimated rendered line height.
- rotationDegrees double
- Clockwise rotation in degrees.
Returns
double 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 bool clipped) #Measures a single line and trims the beginning with an ellipsis when it exceeds the requested width.
Parameters
- text string?
- Text to measure and trim.
- fontSize double
- Font size passed to measure.
- maxWidth double
- Maximum accepted line width.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- clipped bool
- Set to true when the returned line had to be shortened.
public static OfficeTextLine TrimLineToWidth(string? text, double fontSize, double maxWidth, Func<string?, double, double> measure, out bool clipped) #Measures a single line and trims it with an ellipsis when it exceeds the requested width.
Parameters
- text string?
- Text to measure and trim.
- fontSize double
- Font size passed to measure.
- maxWidth double
- Maximum accepted line width.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- clipped bool
- Set to true when the returned line had to be shortened.
public static IReadOnlyList<OfficeTextLine> WrapLines(string? text, double fontSize, double maxWidth, Func<string?, double, double> measure, OfficeTextParagraphIndent? paragraphIndent = null) #Wraps text into measured lines using the supplied measurement delegate.
Parameters
- text string?
- Text to wrap. CRLF and CR line breaks are normalized to LF.
- fontSize double
- Font size passed to measure.
- maxWidth double
- Maximum line width before wrapping or breaking long words.
- measure System.Func<string?, double, double>
- Measurement delegate matching OfficeRasterCanvas.MeasureText.
- paragraphIndent OfficeIMO.Drawing.OfficeTextParagraphIndent? = null
- Optional first-line and continuation-line offsets applied while wrapping.