FormattedText Width 属性不考虑尾随空格

发布于 2024-08-17 08:57:52 字数 446 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾其所爱 2024-08-24 08:57:52

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

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

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

Change from using the Width property to using the WidthIncludingTrailingWhitespace property.

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

With this code you should see two different width values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文