Esempio n. 1
0
        /// <summary>
        /// Method for starting the text formatting process. Each event handler
        /// will call this after the current fontrendering is updated.
        /// </summary>
        private void UpdateFormattedText(double pixelsPerDip)
        {
            // Make sure all UI is loaded
            if (!_UILoaded)
            {
                return;
            }

            // Initialize the text store.
            _textStore = new CustomTextSource(_pixelsPerDip);

            int textStorePosition = 0;                                          //Index into the text of the textsource

            System.Windows.Point linePosition = new System.Windows.Point(0, 0); //current line

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

            // Update the text store.
            _textStore.Text          = textToFormat.Text;
            _textStore.FontRendering = _currentRendering;

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

            // Format each line of text from the text store and draw it.
            while (textStorePosition < _textStore.Text.Length)
            {
                // Create a textline from the text store using the TextFormatter object.
                using (TextLine myTextLine = formatter.FormatLine(
                           _textStore,
                           textStorePosition,
                           96 * 6,
                           new GenericTextParagraphProperties(_currentRendering, _pixelsPerDip),
                           null))
                {
                    // Draw the formatted text into the drawing context.
                    myTextLine.Draw(dc, 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;
                }
            }

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

            // Display the formatted text in the DrawingGroup object.
            myDrawingBrush.Drawing = textDest;
        }
        /// <summary>
        /// Method for starting the text formatting process. Each event handler
        /// will call this after the current fontrendering is updated.
        /// </summary>
        private void UpdateFormattedText(double pixelsPerDip)
        {
            // Make sure all UI is loaded
            if (!_UILoaded)
                return;

            // Initialize the text store.
            _textStore = new CustomTextSource(_pixelsPerDip);

            int textStorePosition = 0;                //Index into the text of the textsource
            System.Windows.Point linePosition = new System.Windows.Point(0, 0);     //current line

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

            // Update the text store.
            _textStore.Text = textToFormat.Text;
            _textStore.FontRendering = _currentRendering;

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

            // Format each line of text from the text store and draw it.
            while (textStorePosition < _textStore.Text.Length)
            {
                // Create a textline from the text store using the TextFormatter object.
                using (TextLine myTextLine = formatter.FormatLine(
                    _textStore,
                    textStorePosition,
                    96 * 6,
                    new GenericTextParagraphProperties(_currentRendering, _pixelsPerDip),
                    null))
                {
                    // Draw the formatted text into the drawing context.
                    myTextLine.Draw(dc, 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;
                }
            }

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

            // Display the formatted text in the DrawingGroup object.
            myDrawingBrush.Drawing = textDest;
        }