DirectWrite(CreateTextFormat)如何选择后备字体? [英] How does DirectWrite (CreateTextFormat) pick the fallback font(s)?

查看:107
本文介绍了DirectWrite(CreateTextFormat)如何选择后备字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以列出后备字体,但仅在Windows 8.1中可用(因为它在IDWriteFactory2中).我想他们已经注意到API在枚举后备字体方面的空白.因此,我猜测在Windows 8.1之前无法执行此操作,但是如果有人知道破解/解决方法...

Update2 .引用 MSFT员工:

DirectWrite具有无法从注册表中读取或无法以任何方式配置的后备数据.但是,在Windows 8.1中,引入了API,这些API允许应用程序指定其自己的后备.(它类似于用于创建复合字体定义的WPF API.)

仍然没有确切解释硬编码的算法/替换方案实际上是什么.

解决方案

IDWriteTextLayout 调用 IDWriteFontFallback :: MapCharacters 将每个Unicode字符映射到字体家族的有序列表,尝试直到该角色满意为止.考虑一个循环,一个一个地读取每个字符,将代码点值和语言标签映射到Unicode范围,然后从支持cmap表中字符的第一个字体停止.它有点类似于CSS [ http指定的字体回退算法://www.w3.org/TR/css3-fonts/#font-matching-algorithm] 和WPF/XAML/Silverlight使用的后备广告.有关使用的输入的信息,请参见用于构建自定义后备列表的 IDWriteFontFallbackBuilder :: AddMapping API(Win 8.1 +).

有关示例数据,请参见C:\ Windows \ Fonts \ GlobalUserInterface.CompositeFont(请注意,该文件实际上是用于WPF的,与DWrite使用的定义不太相同).

 < FontFamilyMapUnicode ="3000-30FF,31F0-31FF"语言="ja"目标="Meiryo UI,Meiryo,Microsoft YaHei UI,Microsoft YaHei,MS Gothic,MingLiu,Arial Unicode MS"比例="1.0"/> 

The documentation for CreateTextFormat says nothing about font fallback selection, but if the default (NULL = system) collection is chosen, then DirectWrite clearly implements font fallback. For example, if I add two glyphs not found in the Gabriola font to the test string used by the DirectWrite SDK demo app, then DirectWrite picks the missing glyphs from the Segoe UI Symbol font. This happens with the basic DrawText call and also with a custom renderer (that does nothing custom for font fallback) as shown below (the only modification is the test string):

The checkmark and wite star come from Segoe UI Symbol, not from Gabriola, even though only Gabriola is specified in the demo app. So, does anyone know how the fallback font(s) is/are selected by DirectWrite (CreateTextFormat)?

Update. I see there is a GetSystemFontFallback that can list the fallback fonts, but it's only available in Windows 8.1 (because it's in IDWriteFactory2). I guess they've noticed the gap in the API with respect to enumerating the fallback fonts. So I'm guessing there's no way to do this before Windows 8.1, but if anyone knows a hack/workaround...

Update2. Quoting a MSFT employee:

DirectWrite has fallback data that is not read from the registry or in any way configurable. In Windows 8.1, though, APIs have been introduced that allow an app to specify its own fallback. (It's similar to the WPF APIs for creating a composite font definition.)

Which still doesn't explain exactly what the hardcoded algorithm/replacement scheme actually is.

解决方案

IDWriteTextLayout calls IDWriteFontFallback::MapCharacters to map each Unicode character to an ordered list of font families that are tried until that character is satisfied. Think of a loop reading each character one-by-one, mapping the code point value and language tag to a Unicode range, and stopping at the first font which supports the character in the cmap table. It is somewhat similar to the font fallback algorithm specified by CSS [http://www.w3.org/TR/css3-fonts/#font-matching-algorithm] and fallback used by WPF/XAML/Silverlight. See the IDWriteFontFallbackBuilder::AddMapping API (Win 8.1+), used to build a custom fallback list, for an idea of the inputs used.

See C:\Windows\Fonts\GlobalUserInterface.CompositeFont for example data (note this file is actually for WPF, not quite the same definition which DWrite uses).

<FontFamilyMap
    Unicode  = "3000-30FF, 31F0-31FF"
    Language = "ja"
    Target   = "Meiryo UI, Meiryo, Microsoft YaHei UI, Microsoft YaHei, MS Gothic, MingLiu, Arial Unicode MS"
    Scale    = "1.0" />

这篇关于DirectWrite(CreateTextFormat)如何选择后备字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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