Monday, January 11, 2016

Looking for fonts on your computer that support a certain character

For a Super User answer, I wrote a PowerShell script that figures out which of the fonts you have installed that support a certain character.

$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
  }
 }
}

To use it, you'll need to save it as a PowerShell script (.ps1). Before PowerShell will let you run scripts, the script policy must be set to Unrestricted by typing this at the prompt:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

Then, the script can be invoked by typing .\ followed by its filename, then a space, then the character to search for. (Right-clicking anywhere in the PowerShell window pastes the contents of your clipboard onto the command line.)

.\fontcheck.ps1 你

No comments:

Post a Comment