【问题标题】:FormattedText Width property does not take trailing spaces into accountFormattedText Width 属性不考虑尾随空格
【发布时间】:2010-01-08 15:55:32
【问题描述】:

我正在使用System.Windows.Media.FormattedText 进行一些低级渲染(具体来说,尝试以一种令人愉悦的方式渲染数学方程式)。为此,我使用的文本块的精确指标至关重要。

我正在创建几个FormattedText 对象并在最低级别的渲染中使用这些对象。问题是,如果其中任何一个包含尾随空格,则在计算 FormattedText.Width 属性时不会考虑该空格。例如,如果我写:

double w1 = new FormattedText ("Hello", ...).Width;
double w2 = new FormattedText ("Hello    ", ...).Width;

w1 和 w2 结果是一样的。前导空格 测量正确。如何强制FormattedText 也测量这些尾随空格?

【问题讨论】:

    标签: c# wpf text formatting formatted-text


    【解决方案1】:

    从使用Width 属性更改为使用WidthIncludingTrailingWhitespace 属性。

    double w1 = new FormattedText ("Hello", ...).WidthIncludingTrailingWhitespace;
    double w2 = new FormattedText ("Hello    ", ...).WidthIncludingTrailingWhitespace;
    

    使用此代码,您应该会看到两个不同的宽度值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 2015-07-06
      • 1970-01-01
      • 2015-12-16
      相关资源
      最近更新 更多