Skip to content

Commit c13ae55

Browse files
feat: Export-Font ( Fixes #3 )
1 parent 8cdfcf3 commit c13ae55

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

Commands/Export-Font.ps1

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
function Export-Font {
2+
param(
3+
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
4+
[Alias('FullName')]
5+
[string]
6+
$FontPath,
7+
8+
[string]
9+
$DestinationPath
10+
)
11+
12+
13+
begin {
14+
$fontForgeCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand('fontforge','Application')
15+
16+
$progressId = Get-Random
17+
$outputQueue = [Collections.Queue]::new()
18+
filter showProgress {
19+
$output = $_
20+
Write-Progress -Id $progressId "$line " "$fontPath "
21+
$outputQueue.Enqueue($output)
22+
}
23+
}
24+
25+
process {
26+
$fontFile = Get-Item -Path $FontPath
27+
28+
if (-not $PSBoundParameters.DestinationPath) {
29+
$destinationPath = $PSBoundParameters.DestinationPath = "./$($($fontFile | Split-Path -Leaf))"
30+
}
31+
32+
if ($DestinationPath -like '*.*' -and
33+
$DestinationPath -notlike '*.zip'
34+
) {
35+
36+
$fontForgeArgs = @(
37+
'-lang=ff'
38+
39+
'-c'
40+
41+
@(
42+
'Open($1)'
43+
'SelectWorthOutputting()'
44+
'Generate($2)'
45+
) -join ';'
46+
47+
$FontPath
48+
49+
$DestinationPath
50+
)
51+
& $fontForgeCommand @fontForgeArgs *>&1 | showProgress
52+
53+
Get-Item -Path $DestinationPath
54+
} else {
55+
$exists = Get-Item -Path $DestinationPath -ErrorAction Ignore
56+
if (-not $exists) {
57+
$exists = New-Item -ItemType Directory -Path $DestinationPath -Force
58+
}
59+
if ($exists -is [IO.FileInfo]) {
60+
return
61+
}
62+
Push-Location $exists.FullName
63+
$fontForgeArgs = @(
64+
'-lang=ff'
65+
66+
'-c'
67+
68+
@(
69+
'Open($1)'
70+
'SelectWorthOutputting()'
71+
'foreach Export("svg")'
72+
'endloop'
73+
) -join ';'
74+
75+
$FontPath
76+
)
77+
& $fontForgeCommand @fontForgeArgs *>&1 | showProgress
78+
Get-Item -Path .
79+
Pop-Location
80+
}
81+
}
82+
end {
83+
Write-Progress -id $progressId -Completed
84+
}
85+
}

0 commit comments

Comments
 (0)