public static double[] GetCharWidths(this FormattedText formattedText, RichTextBlock richTextBlock, RuleText rule)
        {
            richTextBlock.ValidateDefaultRule(rule);
            var text   = formattedText.Text;
            var result = new double[text.Length];

            for (int i = 0; i < text.Length; i++)
            {
                var ft = new FormattedText(text[i].ToString(), CultureInfo.CurrentUICulture, richTextBlock.FlowDirection, new Typeface(rule.FontFamily, rule.FontStyle, rule.FontWeight, rule.FontStretch), rule.FontSize, rule.Foreground);
                result[i] = ft.Width;
            }
            return(result);
        }
 public static FormattedText BuildFormattedText(this RichTextBlock richTextBlock, string value, RuleText currentRule = null)
 {
     if (currentRule == null)
     {
         currentRule = richTextBlock.BuildDefaultRule();
     }
     else
     {
         richTextBlock.ValidateDefaultRule(currentRule);
     }
     return(new FormattedText(value, CultureInfo.InvariantCulture,
                              richTextBlock.FlowDirection,
                              new Typeface(currentRule.FontFamily, currentRule.FontStyle,
                                           currentRule.FontWeight, currentRule.FontStretch),
                              currentRule.FontSize, currentRule.Foreground));
 }
 public static RuleText BuildDefaultRule(this RichTextBlock richTextBlock)
 {
     return(richTextBlock.ValidateDefaultRule(null));
 }