/// <summary> /// Client to ask for the possible smallest and largest paragraph width that can fully contain the passing text content /// </summary> /// <param name="textSource">an object representing text layout clients text source for TextFormatter.</param> /// <param name="firstCharIndex">character index to specify where in the source text the line starts</param> /// <param name="paragraphProperties">properties that can change from one paragraph to the next, such as text flow direction, text alignment, or indentation.</param> /// <param name="textRunCache">an object representing content cache of the client.</param> /// <returns>min max paragraph width</returns> public override MinMaxParagraphWidth FormatMinMaxParagraphWidth( TextSource textSource, int firstCharIndex, TextParagraphProperties paragraphProperties, TextRunCache textRunCache ) { // prepare formatting settings FormatSettings settings = PrepareFormatSettings( textSource, firstCharIndex, 0, // infinite paragraphWidth paragraphProperties, null, // always format the whole paragraph - no previousLineBreak textRunCache, false, // optimalBreak true, // isSingleLineFormatting _textFormattingMode ); // create specialized line specifically for min/max calculation TextMetrics.FullTextLine line = new TextMetrics.FullTextLine( settings, firstCharIndex, 0, // lineLength 0, // paragraph width has no significant meaning in min/max calculation (LineFlags.KeepState | LineFlags.MinMax) ); // line width in this case is the width of a line when the entire paragraph is laid out // as a single long line. MinMaxParagraphWidth minMax = new MinMaxParagraphWidth(line.MinWidth, line.Width); line.Dispose(); return minMax; }
/// <summary> /// Client to collapse the line to fit for display /// </summary> /// <param name="collapsingPropertiesList">a list of collapsing properties</param> public override TextLine Collapse( params TextCollapsingProperties[] collapsingPropertiesList ) { if (!HasOverflowed) return this; Invariant.Assert(_settings != null); // instantiate a collapsible full text line, collapse it and return the collapsed line TextMetrics.FullTextLine textLine = new TextMetrics.FullTextLine( _settings, _cpFirst, 0, // lineLength TextFormatterImp.RealToIdeal(_paragraphWidth), LineFlags.None ); // When in TextFormattingMode.Display the math processing performed by SimpleTextLine // involves some rounding operations because of which the decision to collapse the text may // not be unanimous amongst SimpleTextLine and FullTextLine. There are several watson // crash reports that are testament to this theory. See Win8 PS bug# 643676. Hence we // now allow the case where FullTextLine concludes that it doesnt need to collapse the // text even though SimpleTextLine thought it should. if (textLine.HasOverflowed) { TextLine collapsedTextLine = textLine.Collapse(collapsingPropertiesList); if (collapsedTextLine != textLine) { // if collapsed line is genuinely new, // Dispose its maker as we no longer need it around, dispose it explicitly // to reduce unnecessary finalization of this intermediate line. textLine.Dispose(); } return collapsedTextLine; } return textLine; }
/// <summary> /// Client to collapse the line to fit for display /// </summary> /// <param name="collapsingPropertiesList">a list of collapsing properties</param> public override TextLine Collapse( params TextCollapsingProperties[] collapsingPropertiesList ) { if (!HasOverflowed) return this; Invariant.Assert(_settings != null); // instantiate a collapsible full text line, collapse it and return the collapsed line TextMetrics.FullTextLine textLine = new TextMetrics.FullTextLine( _settings, _cpFirst, 0, // lineLength TextFormatterImp.RealToIdeal(_paragraphWidth), LineFlags.None ); Invariant.Assert(textLine.HasOverflowed); TextLine collapsedTextLine = textLine.Collapse(collapsingPropertiesList); if (collapsedTextLine != textLine) { // if collapsed line is genuinely new, // Dispose its maker as we no longer need it around, dispose it explicitly // to reduce unnecessary finalization of this intermediate line. textLine.Dispose(); } return collapsedTextLine; }