为什么Tahoma字体在WPF中比Arial渲染速度快? [英] Why does the Tahoma font render faster than Arial in WPF?

查看:423
本文介绍了为什么Tahoma字体在WPF中比Arial渲染速度快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个成熟的应用程序中遇到了这种现象,我在WPF中的Tahoma字体比Arial快得多。

我建立了一个测试应用程序来验证我所看到的。

测试应用程序有一个带有多个TabItem的TabControl。每个选项卡包含一个DataGrid控件,并填充18列。网格/列都是数据绑定到相同的视图模型。标签之间唯一的区别就是使用的字体。有1000行。当我尝试拖动垂直滚动条手柄并垂直滚动时,Tahoma和Arial之间的性能差别很大标签。你知道一个滚动条把手如何滞后于你的鼠标的位置,而这个图形会在绘图结束的时候出现,每当它完成一个画面的绘制时,它立即意识到你已经滚动了整个屏幕或者更多的画面,所以它必须重新绘制。与Tahoma,这发生相当快,打勾滴答滴答滴答滴答。它不是以任何方式平滑滚动,而是可用。用宋体,更像是打勾..........打勾..........打勾..........打勾。非常明显的差异。我认为这大概是每个打勾的2-3倍。



我玩过TextOptions.TextFormattingMode,TextOptions.TextRenderingMode和Typography。数字排列,但性能上的差异依然存在。



任何想法为什么会发生这种情况,更重要的是,如果有任何相关的设置可以减轻差异?



我发现<使用OpenType样式表的一些字体很慢,而使用TrueType样式表的相同字体速度很快。请注意,OpenType容器(.otf)和TrueType容器(.ttf)的文件扩展名不会告诉你内部是什么样的表,因为两个容器都支持两种表格样式(请阅读 FontForge文档)。



字体可以通过在字体编辑工具中打开并用TrueType表格导出来固定。这并不总是完美的工作;一目了然,它看起来非常适合Open Sans,但打破了Roboto。我得到的错误消息似乎表明,所需的表大小比TrueType表支持大。



如果您要使用免费的FontForge应用程序复制我的结果,我的程序是:
$ b 1)打开慢字体(例如Arial,Roboto,Open Sans)

2)元素>字体信息>重命名字体与慢字体区分

<3>文件>生成字体>选择TrueType格式,选项>取消选择OpenType



4)测试'fixed'字体。我发现在任何情况下,快速/慢速差异都是可重复的:使用DrawText或TextBlock等方法测量渲染时间。
测量渲染时间的一种方法在

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?

解决方案

I'm no font or WPF expert, but I found a hack-a-round that speeds up fonts and might lead somebody to a better answer. The slowdown is due an interaction between font construction and WPF rendering which is beyond my depth. My guess is that Microsoft hasn't optimized WPF for all font constructions, but alternatively maybe some font creation software doesn't optimize the fonts it generates.

I discovered that some fonts using OpenType-style tables are slow, while these same fonts using TrueType-style tables are fast. Note that file extension of the OpenType container (.otf) and TrueType container (.ttf) doesn't tell you what kind of table is inside, as both containers support both table styles (read "What's OpenType?" in FontForge documentation).

Slow fonts can be "fixed" by opening them in a font editing tool and exporting them with a TrueType table. This doesn't always work perfectly; at a glance it looks perfect for Open Sans, but broke kerning for Roboto. The error message I got seems to indicate that the required table size was larger than the TrueType table supports.

If you want to replicate my results using the free FontForge application, my procedure is:

1) Open the slow font (e.g. Arial, Roboto, Open Sans)

2) Element > Font Info > rename font to differentiate with slow font

3) File > Generate Font > select TrueType format, Options > deselect the "OpenType"

4) Test the 'fixed' font. I've found the fast/slow difference to be repeatable under any conditions: measuring rendering time several different ways, using DrawText or TextBlock, etc. One method of measuring the rendering time is given in this question.

这篇关于为什么Tahoma字体在WPF中比Arial渲染速度快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆