/// <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);
        }
Esempio n. 2
0
        private void UpdateFormattedText03()
        {
            // Index into the text of the TextSource object.
            int textStorePosition = 0;

            // The position of the current line.
            Point linePosition = new Point(0, 0);

            // Create a DrawingGroup object for storing formatted text.
            myTextDisplay = new DrawingGroup();
            DrawingContext drawingContext = myTextDisplay.Open();

            // Update the text store.
            customTextSource.Text = textToFormat.Text;

            // Create a TextFormatter object.
            TextFormatter formatter = TextFormatter.Create();

            // Create common paragraph property settings.
            CustomTextParagraphProperties customTextParagraphProperties
                = new CustomTextParagraphProperties();

            // <SnippetTextFormattingSnippet3>
            MinMaxParagraphWidth minMaxParaWidth =
                formatter.FormatMinMaxParagraphWidth(customTextSource, 0, customTextParagraphProperties);

            // Format each line of text from the text store and draw it.
            while (textStorePosition < customTextSource.Text.Length)
            {
                // Create a textline from the text store using the TextFormatter object.
                using (TextLine myTextLine = formatter.FormatLine(
                           customTextSource,
                           textStorePosition,
                           minMaxParaWidth.MinWidth,
                           customTextParagraphProperties,
                           null))
                {
                    // Draw the formatted text into the drawing context.
                    myTextLine.Draw(drawingContext, linePosition, InvertAxes.None);

                    // Update the index position in the text store.
                    textStorePosition += myTextLine.Length;

                    // Update the line position coordinate for the displayed line.
                    linePosition.Y += myTextLine.Height;
                }
            }
            // </SnippetTextFormattingSnippet3>

            TextLine myTextLine2 = formatter.FormatLine(
                customTextSource,
                0,
                minMaxParaWidth.MaxWidth,
                customTextParagraphProperties,
                null);

            myTextLine2.Draw(drawingContext, linePosition, InvertAxes.None);

            // Persist the drawn text content.
            drawingContext.Close();

            // Display the formatted text in the DrawingGroup object.
            myDrawingBrush.Drawing = myTextDisplay;
        }
Esempio n. 3
0
        /// <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;
        }