6

Fonts (in Windows but not just) don't usually contain glyphs for all languages. Actually, most of them only have glyphs for one language, or rather, one alphabet.

I want to list all fonts on my system (or at least, all font families) which have glyphs for a specific alphabet. I know some applications do this internally (e.g. Adobe Photoshop) and others sort-of-do it (e.g. Microsoft Word's Latin vs Complex distinction). How can I do this myself?

Notes:

  • I'm specifically interested in Hebrew, but my question is for the general case.
  • If it helps, assume I have Cygwin installed.
1

1 Answer 1

2

Based on this StackOverflow answer, I wrote this PowerShell script:

$charId = [Int32][char]$args[0]
[System.Reflection.Assembly]::LoadWithPartialName("PresentationCore") | Out-Null
[System.Windows.Media.Fonts]::GetFontFamilies("C:\Windows\Fonts") | ForEach-Object {
 foreach ($face in $_.GetTypefaces()) {
  $glyph = $null
  $face.TryGetGlyphTypeface([ref]$glyph) | Out-Null
  if ($glyph -and $glyph.CharacterToGlyphMap.TryGetValue($charId, [ref]0)) {
   $_.Source.Split("#")[1]
   break
  }
 }
}

Save it as a file with a ps1 extension; I called it fonttest.ps1.

Before PowerShell will let you run scripts, you'll need to do Set-ExecutionPolicy Unrestricted -Scope CurrentUser. Then you can run it like so:

.\fonttest.ps1 你

The .\ is important, and you'll need to be in the same directory as where you saved the script. That last character is the one you want to test all fonts for. You'll get a printout of all font families that have a glyph for that character. On my computer, the above command produced this:

Microsoft JhengHei
Microsoft JhengHei UI
Microsoft YaHei
Microsoft YaHei UI
Yu Gothic
MS Mincho
MS PMincho
DFKai-SB
SimHei
KaiTi
SimSun
NSimSun
Meiryo
Meiryo UI
MS Gothic
MS UI Gothic
MS PGothic
FangSong
Yu Mincho
MingLiU
PMingLiU
MingLiU_HKSCS
Arial Unicode MS
Adobe Fangsong Std
Adobe Fan Heiti Std
Adobe Heiti Std
Adobe Kaiti Std
Kozuka Gothic Pro
Kozuka Mincho Pro
Adobe Ming Std
Adobe Song Std
Kozuka Gothic Pr6N
Kozuka Mincho Pr6N
DengXian
Microsoft MHei
2
  • 1. Thanks for going to this trouble! 2. (Un?)fortunately, I don't use Windows these days, so - I can't test this script. 3. What do you mean by "Set-ExecutionPolicy Unrestricted -Scope CurrentUser"? Does that involve the policy editor utility? Can you link to somewhere explaining how to do so?
    – einpoklum
    Jan 11, 2016 at 20:15
  • 1
    @einpoklum It's just a command you need to type in the PowerShell prompt. (I'm sure there's an equivalent Group Policy setting too, but it's easier to just type the command.)
    – Ben N
    Jan 11, 2016 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .