Skip to content

Commit cdfe48d

Browse files
docs: Export-Font Help ( Fixes #3 )
1 parent 9d53409 commit cdfe48d

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

Commands/Export-Font.ps1

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,82 @@
11
function Export-Font {
2-
param(
2+
<#
3+
.SYNOPSIS
4+
Exports Fonts
5+
.DESCRIPTION
6+
Exports a font in any format supported by FontForge.
7+
#>
8+
param(
9+
# The path to a font file.
310
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
411
[Alias('FullName')]
512
[string]
613
$FontPath,
714

15+
# The destination path.
16+
# If this is not provided, all glyphs will be extracted to a local directory with the same name as the font.
17+
[Alias('Destination')]
818
[string]
919
$DestinationPath
1020
)
1121

1222

1323
begin {
24+
# Find FontForge
1425
$fontForgeCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand('fontforge','Application')
1526

27+
# and prepare to write progress
1628
$progressId = Get-Random
1729
$outputQueue = [Collections.Queue]::new()
1830
filter showProgress {
1931
$output = $_
2032
Write-Progress -Id $progressId "$line " "$fontPath "
21-
$outputQueue.Enqueue($output)
33+
Write-Verbose $output
34+
$outputQueue.Enqueue($output)
2235
}
2336
}
2437

2538
process {
39+
# If there's no font forge, there's not exporting or importing
40+
if (-not $fontForgeCommand) {
41+
Write-Error "FontForge is not installed or in the Path"
42+
return
43+
}
44+
2645
$fontFile = Get-Item -Path $FontPath
2746

2847
if (-not $PSBoundParameters.DestinationPath) {
2948
$destinationPath = $PSBoundParameters.DestinationPath = "./$($($fontFile | Split-Path -Leaf))"
3049
}
3150

51+
# If we are outputting to a file, and it is not a .zip
3252
if ($DestinationPath -like '*.*' -and
3353
$DestinationPath -notlike '*.zip'
3454
) {
35-
36-
$fontForgeArgs = @(
37-
'-lang=ff'
38-
55+
# we will try to trust that it is a file FontForge can generate
56+
$fontForgeArgs = @(
57+
'-lang=ff'
3958
'-c'
40-
4159
@(
4260
'Open($1)'
4361
'SelectWorthOutputting()'
4462
'Generate($2)'
4563
) -join ';'
46-
4764
$FontPath
48-
4965
$DestinationPath
5066
)
5167
& $fontForgeCommand @fontForgeArgs *>&1 | showProgress
5268

53-
Get-Item -Path $DestinationPath
69+
$exportedFontFile = Get-Item -Path $DestinationPath
70+
if ($exportedFontFile.Extension -eq '.svg') {
71+
$exportedFontFile.pstypenames.add('Font.svg')
72+
}
73+
$exportedFontFile.pstypenames.add('Font.File')
74+
$exportedFontFile
5475
} else {
76+
$isZip = $DestinationPath -like '*.zip'
77+
if ($isZip) {
78+
$DestinationPath = $DestinationPath -replace '\.zip$'
79+
}
5580
$exists = Get-Item -Path $DestinationPath -ErrorAction Ignore
5681
if (-not $exists) {
5782
$exists = New-Item -ItemType Directory -Path $DestinationPath -Force
@@ -61,10 +86,8 @@ function Export-Font {
6186
}
6287
Push-Location $exists.FullName
6388
$fontForgeArgs = @(
64-
'-lang=ff'
65-
89+
'-lang=ff'
6690
'-c'
67-
6891
@(
6992
'Open($1)'
7093
'SelectWorthOutputting()'
@@ -74,8 +97,16 @@ function Export-Font {
7497

7598
$FontPath
7699
)
100+
77101
& $fontForgeCommand @fontForgeArgs *>&1 | showProgress
78-
Get-Item -Path .
102+
103+
if ($isZip) {
104+
Compress-Archive -Path . -DestinationPath ($DestinationPath + '.zip')
105+
Get-Item -LiteralPath ($DestinationPath + '.zip')
106+
} else {
107+
Get-Item -Path .
108+
}
109+
79110
Pop-Location
80111
}
81112
}

0 commit comments

Comments
 (0)