private static TextLineRun CreateTextLineRun(StringRange stringRange, TextRun textRun, int length, TextParagraphProperties paragraphProperties)
        {
            var run = new TextLineRun
            {
                StringRange = stringRange,
                TextRun     = textRun,
                Length      = length
            };

            var tf            = run.Typeface;
            var formattedText = new FormattedText
            {
                Text     = stringRange.ToString(run.Length),
                Typeface = new Typeface(tf.FontFamily, tf.Style, tf.Weight),
                FontSize = run.FontSize
            };

            run._formattedText = formattedText;

            var size = formattedText.Bounds.Size;

            run._formattedTextSize = size;

            run.Width = size.Width;

            run._glyphWidths = new GlyphWidths(
                run.StringRange,
                run.Typeface.GlyphTypeface,
                run.FontSize,
                paragraphProperties.DefaultIncrementalTab);

            return(run);
        }
Example #2
0
        internal static TextLineRun CreateRunForText(StringRange stringRange, TextRun textRun, double widthLeft, bool emergencyWrap, bool breakOnTabs)
        {
            var run = new TextLineRun
            {
                StringRange = stringRange,
                TextRun     = textRun,
                Length      = textRun.Length
            };

            var tf            = run.Typeface;
            var formattedText = new FormattedText
            {
                Text     = stringRange.ToString(),
                Typeface = new Typeface(tf.FontFamily, tf.Style, tf.Weight),
                FontSize = run.FontSize
            };

            run._formattedText = formattedText;

            var size = formattedText.Bounds.Size;

            run._formattedTextSize = size;

            run.Width = size.Width;

            run._glyphWidths = new GlyphWidths(
                run.StringRange,
                run.Typeface.GlyphTypeface,
                run.FontSize);

            return(run);
        }
Example #3
0
        internal static TextLineRun CreateRunForText(StringRange stringRange, TextRun textRun, double widthLeft, bool emergencyWrap, bool breakOnTabs)
        {
            var run = new TextLineRun
            {
                StringRange = stringRange,
                TextRun     = textRun,
                Length      = textRun.Length
            };

            var formattedText = new FormattedText
            {
                Text     = stringRange.ToString(),
                Typeface = new Typeface(run.Typeface, run.FontSize)
            };


            run._formattedText = formattedText;

            var size = formattedText.Measure();

            run._formattedTextSize = size;

            run.Width = size.Width;

            run.SetGlyphWidths();

            return(run);
        }
Example #4
0
        internal static TextLineRun CreateRunForText(StringRange stringRange, TextRun textRun, double widthLeft, bool emergencyWrap, bool breakOnTabs)
        {
            var tf            = textRun.Properties.Typeface;
            var formattedText = new FormattedText
            {
                Text     = stringRange.ToString(),
                Typeface = new Typeface(tf.FontFamily, tf.Style, tf.Weight),
                FontSize = textRun.Properties.FontSize
            };

            double x      = 0;
            int    offset = 0;
            int    lastWhitespaceIndex = -1;

            //Measure the width of the text that would fit in the space left
            while (x <= widthLeft && offset < textRun.Length)
            {
                x += formattedText.HitTestTextPosition(offset).Width;

                if (x <= widthLeft)
                {
                    if (char.IsWhiteSpace(stringRange[offset]))
                    {
                        lastWhitespaceIndex = offset;
                    }

                    offset++;
                }
            }

            //Wrap at the last letter if there was no whitespace in the run
            if (lastWhitespaceIndex == -1 && x > widthLeft)
            {
                lastWhitespaceIndex = offset;
            }

            var run = new TextLineRun
            {
                StringRange         = stringRange,
                TextRun             = textRun,
                Length              = textRun.Length,
                LastWhitespaceIndex = lastWhitespaceIndex
            };

            run._formattedText = formattedText;

            var size = formattedText.Bounds.Size;

            run._formattedTextSize = size;

            run.Width = size.Width;

            run.SetGlyphWidths();

            return(run);
        }
Example #5
0
        public void TrimEnd(int trimLength)
        {
            Length         = Math.Max(Length - trimLength, 1);
            StringRange    = new StringRange(StringRange.ToString(), 0, Length);
            _formattedText = new FormattedText()
            {
                Text     = StringRange.ToString(),
                Typeface = _formattedText.Typeface,
                FontSize = _formattedText.FontSize
            };

            var size = _formattedText.Bounds.Size;

            _formattedTextSize = size;

            Width = size.Width;
        }