Skip to content

Instantly share code, notes, and snippets.

@GwyndolynMarchant
Last active April 27, 2021 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GwyndolynMarchant/c16c386fe352b968f8818a652091386a to your computer and use it in GitHub Desktop.
Save GwyndolynMarchant/c16c386fe352b968f8818a652091386a to your computer and use it in GitHub Desktop.
Powershell: Fix Font Family & Variant
# 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