-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFontViewMax.ps1
More file actions
83 lines (68 loc) · 3.01 KB
/
FontViewMax.ps1
File metadata and controls
83 lines (68 loc) · 3.01 KB
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
Set-Variable -Option Constant -Name SCRIPT_TITEL -Value "FontViewMax"
Set-Variable -Option Constant -Name SCRIPT_VERSION -Value 0.1.0
$ScriptRoot = if (-not $PSScriptRoot) {
Split-Path -Parent (Convert-Path ([Environment]::GetCommandLineArgs()[0]))
}
else {
$PSScriptRoot # Use the automatic variable.
}
function Get-UserFontNames {
$result = @()
$font_path = Get-ChildItem (Join-Path $env:LOCALAPPDATA Microsoft\Windows\Fonts\)
$font_path | ForEach-Object {
$fo = New-Object System.Drawing.Text.PrivateFontCollection
$fo.AddFontFile($_.FullName)
$normalName = $fo.Families.Name
$usName = $fo.Families[0].GetName([System.Globalization.CultureInfo]::GetCultureInfo("en-us").LCID)
$result += ,@($_.FullName; $normalName; $usName)
}
return $result
}
function Get-SystemFontNames {
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
return (
(New-Object System.Drawing.Text.InstalledFontCollection).Families |
ForEach-Object {
$normalName = $_.Name
$usName = $_.GetName([System.Globalization.CultureInfo]::GetCultureInfo("en-us").LCID)
,@($normalName; $usName)
}
)
}
Remove-Item (Join-Path $ScriptRoot "lib\*.dll") -Stream Zone.Identifier -ErrorAction SilentlyContinue
Add-Type -AssemblyName System.Drawing # フォント操作用
Add-Type -AssemblyName PresentationFramework # WPF 用
Add-Type -AssemblyName System.Windows.Forms # Timer 用
$libWebView2Wpf = (Join-Path $ScriptRoot "lib\Microsoft.Web.WebView2.Wpf.dll")
$libWebView2Core = (Join-Path $ScriptRoot "lib\Microsoft.Web.WebView2.Core.dll")
$libWebview2Loader = (Join-Path $ScriptRoot "lib\WebView2Loader.dll")
<# WebView2 用アセンブリロード #>
[void][reflection.assembly]::LoadFile($libWebView2Wpf)
[void][reflection.assembly]::LoadFile($libWebView2Core)
<# XAML にて Window 構築 #>
[xml]$xaml = (Get-Content (Join-Path $ScriptRoot "etc\ui.xaml"))
$nodeReader = (New-Object System.XML.XmlNodeReader $xaml)
$window = [Windows.Markup.XamlReader]::Load($nodeReader)
$webview = $window.findName("webView")
<# WebView2 の設定 #>
$webview.CreationProperties = New-Object 'Microsoft.Web.WebView2.Wpf.CoreWebView2CreationProperties'
$webview.CreationProperties.UserDataFolder = (Join-Path $ScriptRoot "data")
$webview.Source = "file:///" + (Join-Path $ScriptRoot "webview/FontViewMax.html")
<# Set EventListener #>
<# WebView2 Messaging #>
$webview.add_WebMessageReceived({
param($webview, $message)
$json = ($message.WebMessageAsJson | ConvertFrom-Json)
if ($json.status -eq "ready") {
$webview.CoreWebView2.PostWebMessageAsJSON((@{
system_fonts = Get-SystemFontNames
user_fonts = Get-UserFontNames
} | ConvertTo-Json))
}
})
<# Window の表示 #>
$window.Title = ("{0} v{1}" -f ($SCRIPT_TITEL,$SCRIPT_VERSION))
[void]$window.ShowDialog()
$webview.Dispose()
$window.Close()