FormattedText Width 属性不考虑尾随空格
我正在使用 System.Windows.Media.FormattedText 进行一些低级渲染(具体来说,尝试以排版上令人愉悦的方式渲染数学方程)。为此,我正在使用的文本块的精确指标至关重要。
我正在创建几个 FormattedText
对象并在最低渲染级别使用它们。问题是,如果其中任何一个包含尾随空格,则在计算 FormattedText.Width 属性时不会考虑该空格。例如,如果我写:
double w1 = new FormattedText ("Hello", ...).Width;
double w2 = new FormattedText ("Hello ", ...).Width;
w1 和 w2 结果是相同的。前导空格测量正确。如何强制 FormattedText
也测量这些尾随空格?
I am using System.Windows.Media.FormattedText
to do some low level rendering (specifically, trying to render math equations in a typographically pleasing manner). For this, precise metrics on the text blocks I am using are critical.
I am creating several FormattedText
objects and using these at the lowest level of rendering. The problem is that if any of these contain trailing spaces, that space is not taken into account when computing the FormattedText.Width
property. For example, if I write:
double w1 = new FormattedText ("Hello", ...).Width;
double w2 = new FormattedText ("Hello ", ...).Width;
w1 and w2 turn out to be the same. Leading spaces are measured correctly. How do I force FormattedText
to measure these trailing spaces as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从使用
Width
属性更改为使用WidthInducingTrailingWhitespace
属性。使用此代码,您应该看到两个不同的宽度值。
Change from using the
Width
property to using theWidthIncludingTrailingWhitespace
property.With this code you should see two different width values.