如何检查哪些字符集(代码页)字体支持(带有字母)? [英] How to check which character sets (codepages) font supports (has letters for)?

查看:105
本文介绍了如何检查哪些字符集(代码页)字体支持(带有字母)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序,我需要显示系统字体列表,但过滤掉所有不支持20种预定义语言(该设置为硬编码)的字体,并仅显示支持这些字体的字体。

For my app I need to show a list of system fonts, but filter out all the fonts that do not support 20 predefined languages (the set is hardcoded) and show only those which do.

我可以通过调用 Vcl.Forms.Screen.Fonts 获得可用字体的列表。

只知道字体名称从该列表中,如何检查该字体支持哪些字符集(代码页)(有实际字母)?

I can have a list of available fonts by calling Vcl.Forms.Screen.Fonts.
Knowing just the font name from that list, how do I check which character sets (codepages) this font supports (has actual letters for) ?

例如,常见字体如Arial或Times New Roman具有几乎所有欧洲语言的字符,包括西里尔字母(以及中文等)。

For example, common fonts like Arial or Times New Roman have characters for almost all European languages, including Cyrillic (and also Chinese and such). Yet many less common fonts often have only English letters.

该应用程序仅供内部使用,因此具有一个可以简单地查询字体(如果它具有特定于特定字母的字体的功能)的应用程序。某些字符集/代码页(例如ФЎξ),并且不用其他通用字体(或某个占位符)的字母代替就足够了。

The app is for internal use, so having a function that simply queries the font if it has a certain letter specific to some character set / codepage (e.g. Ф or Ў or ξ) and that it is not substituted with letter from another generic font (or some placeholder) would suffice.

推荐答案

可以使用href = https://msdn.microsoft.com/en-us/library/windows/desktop/dd144890(v=vs.85).aspx rel = nofollow noreferrer> GetGlyphIndices 函数确定字体中是否存在字形。

The GetGlyphIndices function can be used to determine whether a glyph exists in a font.


DWORD GetGlyphIndices(
  _In_  HDC     hdc,
  _In_  LPCTSTR lpstr,
  _In_  int     c,
  _Out_ LPWORD  pgi,
  _In_  DWORD   fl
);

参数[...]

fl [输入]:指定不支持
的字形应如何处理。此参数可以是以下值。

fl [in]: Specifies how glyphs should be handled if they are not supported. This parameter can be the following value.

GGI_MARK_NONEXISTING_GLYPHS -用十六进制值0xffff标记不受支持的字形。 。

GGI_MARK_NONEXISTING_GLYPHS -- Marks unsupported glyphs with the hexadecimal value 0xffff.

注释部分再次链接到Uniscribe函数,例如 ScriptGetCMap

The Remarks sections links again to the Uniscribe functions, e.g. ScriptGetCMap


此函数尝试为lpstr指向的字符串中的每个字符标识单字形表示形式。尽管这对于某些低级用途(例如处理字体文件)很有用,但希望将字符串映射到字形的高级应用程序通常希望使用Uniscribe函数。

This function attempts to identify a single-glyph representation for each character in the string pointed to by lpstr. While this is useful for certain low-level purposes (such as manipulating font files), higher-level applications that wish to map a string to glyphs will typically wish to use the Uniscribe functions.

由于Win2k以后都支持这两个API,因此使用哪个API可能是一个问题。

As both APIs are supported from Win2k onwards, it is probably a matter of taste which one to use.

(编辑:刚注意到导入已在Windows.pas中)

( Just noticed that the import is already in Windows.pas)

procedure Test( dc : HDC);
var str : UnicodeString;
    buf : array of WORD;
    len,i : Integer;
    count : DWORD;
begin
  str := 'abc'+WideChar($0416)+'äöü';
  len := Length(str);
  SetLength( buf, len);
  count := GetGlyphIndicesW( dc, PWideChar(str), len, @buf[0], GGI_MARK_NONEXISTING_GLYPHS);
  if count > 0 then begin
    for i := 0 to count-1 do begin
      Write('index ',i,': ');
      if buf[i] = $FFFF
      then Writeln('glyph missing')
      else Writeln('ok');
    end;
  end;
end;

收益率

index 0: ok
index 1: ok
index 2: ok
index 3: glyph missing
index 4: ok
index 5: ok
index 6: ok

这篇关于如何检查哪些字符集(代码页)字体支持(带有字母)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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