-
-
Notifications
You must be signed in to change notification settings - Fork 119
chore: add powershell script to generate custom icons fonts #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
44fbca5
916cec2
7f864b7
53226c8
c248a08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/usr/local/bin/fontforge | ||
| i=1 | ||
| while ( i<$argc ) | ||
| Open($argv[i]) | ||
| Generate($argv[i]:r + ".ttf","",0x10|0x80|0x8000|4) | ||
| i = i+1 | ||
| endloop | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| <# | ||||||||||||||||||||||||||||||||||||||||||||||||
| .SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||
| Generate TrueType (.ttf) fonts from UFO packages using FontForge. | ||||||||||||||||||||||||||||||||||||||||||||||||
| .DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||
| Lightweight wrapper that invokes `assets/fonts/fontforge-ufo-to-ttf.pe` | ||||||||||||||||||||||||||||||||||||||||||||||||
| to generate .ttf files. | ||||||||||||||||||||||||||||||||||||||||||||||||
| .PARAMETER Publish | ||||||||||||||||||||||||||||||||||||||||||||||||
| Specifies whether generated .ttf files should be moved from the | ||||||||||||||||||||||||||||||||||||||||||||||||
| source assets folder into the application assets folder. If not specified, | ||||||||||||||||||||||||||||||||||||||||||||||||
| generated .ttf files remain in the source assets folder. | ||||||||||||||||||||||||||||||||||||||||||||||||
| .EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||
| PS> .\scripts\Generate-Fonts.ps1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| .EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||
| PS> .\scripts\Generate-Fonts.ps1 -Publish | ||||||||||||||||||||||||||||||||||||||||||||||||
| .NOTES | ||||||||||||||||||||||||||||||||||||||||||||||||
| FontForge must be installed and included in the PATH environment variable. | ||||||||||||||||||||||||||||||||||||||||||||||||
| #> | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| [CmdletBinding()] | ||||||||||||||||||||||||||||||||||||||||||||||||
| param( | ||||||||||||||||||||||||||||||||||||||||||||||||
| [Parameter(Mandatory=$false)] | ||||||||||||||||||||||||||||||||||||||||||||||||
| [switch] | ||||||||||||||||||||||||||||||||||||||||||||||||
| $Publish | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| New-Variable -Name 'ScriptFileName' -Value 'fontforge-ufo-to-ttf.pe' -Option Constant | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| $repositoryPath = Split-Path -Parent $PSScriptRoot | ||||||||||||||||||||||||||||||||||||||||||||||||
| $fontsPath = Join-Path -Path $repositoryPath -ChildPath "assets\fonts" | ||||||||||||||||||||||||||||||||||||||||||||||||
| $publishPath = Join-Path -Path $repositoryPath -ChildPath "Screenbox\Assets\Fonts" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if (-not (Get-Command "fontforge" -ErrorAction SilentlyContinue)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Error "Install the latest version of FontForge.`nAfter FontForge is installed, make sure that the location of the 'fontforge.exe' is included in the PATH environment variable." -Category NotInstalled | ||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if (-not (Test-Path (Join-Path -Path $fontsPath -ChildPath $ScriptFileName))) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Error "The script file $ScriptFileName was not found." -Category ObjectNotFound | ||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| $ufoDirs = @(Get-ChildItem -Path $fontsPath -Filter '*.ufo' -Directory -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if ($ufoDirs.Count -gt 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Output "Found UFO packages:`n$($ufoDirs -join "`n")" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # Build argument list: -script <scriptFile> <ufo#1> <ufo#2> ... | ||||||||||||||||||||||||||||||||||||||||||||||||
| $cmdArgs = @('-script', (Join-Path -Path $fontsPath -ChildPath $ScriptFileName)) + $ufoDirs | ||||||||||||||||||||||||||||||||||||||||||||||||
| & "fontforge" @cmdArgs | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if ($Publish) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||
| $ttfFiles = @(Get-ChildItem -Path $fontsPath -Filter '*.ttf' -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if ($ttfFiles.Count -eq 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Error "No .ttf files found in the folder: $fontsPath" -Category ObjectNotFound | ||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+51
to
+59
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if ($Publish) { | |
| try { | |
| $ttfFiles = @(Get-ChildItem -Path $fontsPath -Filter '*.ttf' -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName) | |
| if ($ttfFiles.Count -eq 0) { | |
| Write-Error "No .ttf files found in the folder: $fontsPath" -Category ObjectNotFound | |
| exit 1 | |
| } | |
| $fontForgeExitCode = $LASTEXITCODE | |
| if ($fontForgeExitCode -ne 0) { | |
| Write-Error "FontForge failed with exit code $fontForgeExitCode." -Category InvalidOperation | |
| exit $fontForgeExitCode | |
| } | |
| $ttfFiles = @(Get-ChildItem -Path $fontsPath -Filter '*.ttf' -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName) | |
| if ($ttfFiles.Count -eq 0) { | |
| Write-Error "No .ttf files found in the folder: $fontsPath" -Category ObjectNotFound | |
| exit 1 | |
| } | |
| if ($Publish) { | |
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shebang hardcodes
/usr/local/bin/fontforge, which is not portable (and it’s unnecessary when this file is executed viafontforge -script). Consider removing the shebang entirely, or switching to an env-based shebang if you intend the script to be directly executable on Unix-like systems.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was taken straight from the FontForge scripting documentation, it does say "(or wherever fontforge happens to reside on your system)".
Either way, it's inconsequential for us. I think...