Last active
April 27, 2021 22:37
-
-
Save GwyndolynMarchant/c16c386fe352b968f8818a652091386a to your computer and use it in GitHub Desktop.
Powershell: Fix Font Family & Variant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requirements | |
# - fonttools : https://github.com/fonttools/fonttools | |
Param ( | |
[Parameter(Mandatory=$true)][string]$Path, | |
[Parameter(Mandatory=$true)][string]$OldFamily, | |
[Parameter(Mandatory=$true)][string]$NewFamily, | |
[string]$Variant | |
) | |
# Convert .TTF to .TTX | |
ttx $Path | |
# Manipulate .TTX XML | |
[string]$FontConfig = (Get-Item $Path).BaseName + ".ttx" | |
$xml = [xml](Get-Content $FontConfig) | |
foreach ($node in $xml.ttFont.name.namerecord) { | |
if (($Variant -ne "") -and ($node.nameID -eq 2)) { | |
$node.innerText = $Variant | |
} else { | |
$node.innerText = $node.innerText -replace $OldFamily, $NewFamily | |
} | |
} | |
# Save back to .TTX and convert back to .TTF | |
$xml.Save((Get-Item $FontConfig)) | |
ttx $FontConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment