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, run.FontSize, tf.Style, tf.Weight),
            };


            run._formattedText = formattedText;

            var size = formattedText.Measure();

            run._formattedTextSize = size;

            run.Width = size.Width;

            run.SetGlyphWidths();

            return(run);
        }
Exemple #2
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);
        }
        private static TextLineRun CreateRunForTab(TextRun textRun)
        {
            var spaceRun    = new TextCharacters(" ", textRun.Properties);
            var stringRange = spaceRun.StringRange;
            var run         = new TextLineRun(1, spaceRun)
            {
                IsTab       = true,
                StringRange = stringRange,
                // TODO: get from para props
                Width = 40
            };

            run.SetGlyphWidths();

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

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

            run._formattedText = formattedText;

            var size = formattedText.Measure();

            run._formattedTextSize = size;

            run.Width = (int)size.Width;

            run.SetGlyphWidths();

            return(run);
        }