-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathExport-FontSample.ps1
111 lines (100 loc) · 4.07 KB
/
Export-FontSample.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function Export-FontSample {
<#
.SYNOPSIS
Exports an HTML file containing sample text formatted in all the fonts installed on the current system.
.DESCRIPTION
Exports an HTML file containing sample text formatted in all the fonts installed on the current system.
.PARAMETER Path
The path to the file that you want the font sample exported to. If the file does not end in either '.htm', or '.html' then an extension of '.htm' will be added to the file.
Defaults to the filename FontSample.htm in the path specified by $env:TEMP
.PARAMETER Text
Sample text that you want to displayed in the HTML file. Defaults to the string array:
@( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz',
'1234567890',
'!@#$%^&*()[]{}-_=+ ¢£',
'γδθλξπσυψω'
)
.PARAMETER Quiet
Switch to produce no output to the PowerShell session
.PARAMETER Show
Switch to open the produced HTML file with the default browser
.EXAMPLE
Export-FontSample
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseBOMForUnicodeEncodedFile','')]
param(
[Alias('FileName')]
[string] $Path = (Join-Path -Path $env:TEMP -ChildPath 'FontSample.htm'),
[string[]] $Text = @(
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz',
'1234567890',
'!@#$%^&*()[]{}-_=+ ¢£',
'γδθλξπσυψω'
),
[switch] $Quiet,
[switch] $Show
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
if ($Path -notmatch '\.html?$') {
Write-Verbose -Message "[$Path] does not end with extension .htm or .html"
$Path = $Path + '.htm'
}
Write-Verbose -Message "Text specified was [$($Text -join ' ')]"
}
process {
$FontsInstalled = Get-Font -Verbose:$false
Write-Verbose -Message "There are [$($FontsInstalled.Count)] fonts installed."
$HtmlStart = @"
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>$Path</title>
</head>
<body>
<h1>Font Sample</h1>
<p>Font sample created from the list of installed fonts on this computer.
Font names are listed twice: </p>
<ul>
<li>Once in Arial</li>
<li>Once in that particular font.</li>
</ul>
<p>There will be a sample text that was either specified via the -Text parameter or
a sample set which includes upper case English
alphabet, lower case English alphabet, numbers 0-9, a small sample
of commonly used symbols, and several Greek letters.</p>
"@
$HtmlEnd = @'
</body>
</html>
'@
# create HTML
$Result = $FontsInstalled |
ForEach-Object -begin { $strHTML = New-Object -Type 'System.Collections.Arraylist' } -process {
$tmpString = "<p><font style=`"font-family: Helvetica,Arial,sans-serif;`" size=`"4`">[{0}] / </font><font size=`"4`" face=`"{0}`">[{0}]</font><br/>" -f ($_)
$null = $strHTML.Add( $tmpString )
#$tmpString = "<font size=`"4`" face=`"{0}`">[{0}]</font><br/>" -f ($_)
#$strHTML += $tmpString
$tmpString = "<font size=`"3`" face=`"{0}`"> {1}</font></p>" -f ($_), ($Text -join ' ')
$null = $strHTML.Add($tmpString)
} -end {$strHTML}
$HtmlFile = $HtmlStart + ($Result | Out-String -Width 1024) + $HtmlEnd
# write HTML
Set-Content -Path $Path -Value $HtmlFile
if (-not $Quiet) {
Write-Output -InputObject "HTML saved to [$Path]"
}
if ($Show) {
Invoke-Item -Path $Path
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
} # EndFunction Export-FontSample