21 lines
863 B
PowerShell
21 lines
863 B
PowerShell
param([string]$InFile, [string]$OutFile, [double]$Size = 28, [string]$Font = "Microsoft YaHei")
|
|
# 用 WPF 的 FormattedText 量文字宽度(希沃白板也是 WPF,度量一致)
|
|
Add-Type -AssemblyName PresentationCore
|
|
Add-Type -AssemblyName WindowsBase
|
|
$tf = New-Object System.Windows.Media.Typeface($Font)
|
|
$items = Get-Content $InFile -Encoding UTF8 -Raw | ConvertFrom-Json
|
|
$res = @{}
|
|
foreach ($p in $items.PSObject.Properties) {
|
|
$ft = New-Object System.Windows.Media.FormattedText(
|
|
[string]$p.Value,
|
|
[System.Globalization.CultureInfo]::GetCultureInfo("zh-CN"),
|
|
[System.Windows.FlowDirection]::LeftToRight,
|
|
$tf,
|
|
$Size,
|
|
[System.Windows.Media.Brushes]::Black,
|
|
1.0)
|
|
$res[$p.Name] = $ft.WidthIncludingTrailingWhitespace
|
|
}
|
|
$res | ConvertTo-Json -Depth 3 | Set-Content $OutFile -Encoding UTF8
|
|
Write-Output "measured $($res.Count)"
|