为什么Tahoma字体在WPF中的呈现速度比Arial快?

bfrts1fy  于 2022-11-18  发布在  其他
关注(0)|答案(2)|浏览(192)

I encountered this phenomenon in a mature application that I work on where the Tahoma font in WPF is much faster than Arial.
I built a test application to verify what I was seeing.
The test application has a TabControl with several TabItems. Each tab contains a DataGrid control and is populated with 18 columns. The grids/columns are all databound to the same viewmodel. The only difference whatsoever between the tabs are the fonts used. There are 1000 rows. The TextBlock sizes are fixed to the same sizes across the board.
When I attempt to drag the vertical scrollbar handle and vertically scroll, the performance varies dramatically between the Tahoma and Arial tabs. You know how a scrollbar handle lags behind where your mouse is while the drawing catches up, and each time it finishes drawing a screen, it immediately realizes you have already scrolled an entire screen or more futher, so it completely has to redraw again? With Tahoma, this happens pretty fast, "tick tick tick tick tick". It's not smooth scrolling by any means, but it is usable. With Arial, it's more like, "tick..........tick..........tick..........tick". Very noticable difference. I'd say it takes about 2-3 times as long per "tick".
I've played around with TextOptions.TextFormattingMode, TextOptions.TextRenderingMode, and Typography.NumeralAlignment, but the difference in performance remains.
Any ideas why this might be happening, and more importantly, if there are any pertinent settings that might alleviate the difference?

eh57zj3b

eh57zj3b1#

我不是字体或WPFMaven,但我发现了一个加快字体速度的方法,可能会给别人带来更好的答案。这种速度的减慢是由于字体构造和WPF渲染之间的交互作用,这超出了我的深度。我的猜测是微软没有为所有字体构造优化WPF,但也可能是一些字体创建软件没有优化它生成的字体。
我发现一些使用OpenType样式表的字体速度很慢,而这些使用TrueType样式表的字体速度很快。注意,OpenType容器(.otf)和TrueType容器(.ttf)的文件扩展名并不能告诉你里面是什么样的表,因为这两个容器都支持这两种表样式(读FontForge documentation中的“什么是OpenType?”)。
慢速字体可以通过在字体编辑工具中打开它们并将它们与TrueType表一起导出来“修复”。乍一看,它看起来非常适合Open Sans,但却破坏了Roboto的字距调整。我得到的错误信息似乎表明所需的表大小大于TrueType表支持的大小。
如果你想使用免费的FontForge应用程序复制我的结果,我的步骤是:
1.打开慢速字体(例如Arial、Roboto、Open Sans)
1.元素〉字体信息〉重命名字体以与慢速字体区分
1.文件〉生成字体〉选择TrueType格式,选项〉取消选择“OpenType”
1.测试'fixed'字体。我发现快/慢的区别在任何情况下都是可重复的:使用DrawText或TextBlock等多种不同方法测量渲染时间。this question中给出了一种测量渲染时间的方法。

ffscu2ro

ffscu2ro2#

我这里有一个例子......似乎追踪到测量而不是普通渲染...... Bad Font-Measuring Performance under Windows 8.1

相关问题