windows 如何处理不在当前字体中的绘制字符 [英] how does windows deal with drawing chars not in the current font

查看:24
本文介绍了windows 如何处理不在当前字体中的绘制字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序试图显示 U+23CE ().这是一个终端应用程序,所以我们使用Consolas"/Cascadia"/Courier".据我所知,这些字体都没有这个字符.然而,在 Visual Studio 中,当我调试这个应用程序时,它实际上在调试器中正确显示了它.此外,当由新的 Windows 终端显示时,它显示正确.但是当我使用我正在使用的应用程序(实际上是 Putty)时,它会显示我不知道这个字符".字形.

Putty 是一个经典的 Win32 应用程序,它使用 ExtTextOutW() 来绘制文本.我已经检查过 HDC 是否绑定了正确的字体.

我假设 Visual Studio 和 Windows 终端正在使用 DirectWrite 或其他更现代的文本输出逻辑,但最终它们必须从某个地方获取这些未知字形.

更新:

我找到了一种带有该字符的字体(Segue UI 符号"),如果我将 Putty 设置为使用该字体,它会显示缺少的字符(woohoo).遗憾的是,这是一个比例字体,所以看起来很糟糕,这不是解决方案.

@dvix 将我指向了一个讨论这个确切主题的 Microsoft 页面,但不清楚哪些事情是由 Windows 完成的,哪些是由应用程序开发人员完成的.我尝试链接Courier New"(Putty 的默认值)为Segoe Symbol",但没有区别.Putty 代码是否需要自己完成所有工作?检测一个未知字符,读取注册表,然后用字体替换那个字符?这当然是可行的,但很痛苦.

解决方案

Windows 可以被定向到借用"使用

BabelMap 的另一个功能是可以选择动态创建临时的用户定义的复合字体,而不是静态"创建的字体.在注册表中定义.这大概是使用 MLangIMLangFontLink 接口,更多关于 Raymond Chen 的How显示一个没有那些丑陋盒子的字符串 和 Michael Kaplan 的 字体替换和链接#2.

I have an app that is trying to display U+23CE (). This is a terminal app, so we are using "Consolas"/"Cascadia"/"Courier". As far as I can see, none of these fonts have this character. And yet, in Visual Studio, when I am debugging this app, it actually displays it correctly in the debugger. Also, when displayed by the new Windows Terminal, it displays correctly. But when I use the app I am working with (actually Putty), it displays the "I don't know this character" glyph.

Putty is a classic Win32 app using ExtTextOutW() to draw that text. I have checked that the correct font is bound to the HDC.

I am assuming that Visual Studio and Windows Terminal are using DirectWrite or other more modern text output logic, but ultimately they have to be getting these unknown glyphs from somewhere.

UPDATE:

I found a font with that character ("Segue UI Symbol"), and if I set Putty to use that font, it displays the missing character (woohoo). Sadly, this is a proportional font, so it looks terrible, and this is not the solution.

@dvix pointed me at a Microsoft page discussing this exact topic, but its not clear which things are done by Windows and which by an app developer. I tried linking "Courier New" (Putty's default) to "Segoe Symbol"", but it made no difference. Does the Putty code need to do all the work itself? Detect an unknown character, read the Registry, and substitute the font for that one char? That is certainly doable, but a pain.

解决方案

Windows can be directed to "borrow" missing glyphs in a font from another font that carries them using font linking. This applies to both consoles and GUI apps that use GDI (DrawText, ExtTextOut) to render text in Windows 2000 and later.

For example, the following registry entry will link the Consolas font to Segoe UI Symbol (the following can be saved as a .reg file and merged into the registry, will take effect at the next logon).

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
"Consolas"=hex(7):53,45,47,55,49,53,59,4d,2e,54,54,46,2c,53,65,\
                  67,6f,65,20,55,49,20,53,79,6d,62,6f,6c,00,00
; "Consolas"=REG_MULTI_SZ:"SEGUISYM.TTF,Segoe UI Symbol"

One handy tool to explore coverage of the different fonts is BabelMap. For example this is the list of fonts that carry U+23CE (⏎) on a fairly clean Win10 system.

Another feature of BabelMap is the option to create temporary user-defined composite fonts on the fly, as opposed to the ones "statically" defined in the registry. This is presumably done using the MLang IMLangFontLink interface, more about that in Raymond Chen's How to display a string without those ugly boxes and Michael Kaplan's Font substitution and linking #2.

这篇关于windows 如何处理不在当前字体中的绘制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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