[英]Get details of uninstalled Windows fonts via PowerShell
I'm using PowerShell and ImageMagick to create customized images of my font collection to determine which fonts I want to install into the system.我正在使用 PowerShell 和 ImageMagick 创建我的字体集合的自定义图像,以确定我想要安装到系统中的 fonts。 I'd like to have the image include some font information, but I am having a difficult time extracting that information.
我想让图像包含一些字体信息,但我很难提取这些信息。 I found some useful code at https://powershell.org/forums/topic/listing-font-details/#post-78006 , but I found that information is only accessible within the system's font directory.
我在https://powershell.org/forums/topic/listing-font-details/#post-78006找到了一些有用的代码,但我发现这些信息只能在系统的字体目录中访问。 My collection exists outside of
%SystemRoot%\Fonts
.我的收藏存在于
%SystemRoot%\Fonts
之外。
I'd like to access things like我想访问类似的东西
etc.等等
Is this possible?这可能吗?
Using the Shell.Application
COM object to get details of files is not limited to the %SystemRoot%\Fonts
folder.使用
Shell.Application
COM object 获取文件的详细信息不限于%SystemRoot%\Fonts
文件夹。
If you have a folder on disk where you keep your collection of fonts, you could use the below code to get information for each of the font files:如果您在磁盘上有一个文件夹来保存 fonts 的集合,则可以使用以下代码获取每个字体文件的信息:
function Get-FontInfo {
[CmdletBinding()]
[OutputType([Psobject])]
Param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string]$SourceFolder,
[switch]$Recurse
)
# using a lookup hashtable to avoid localized field names
$fontProperties = [ordered]@{
0 = 'Name'
1 = 'Size'
2 = 'Type'
20 = 'Author'
21 = 'Title'
25 = 'Copyright'
33 = 'Company'
34 = 'Description'
164 = 'Extension'
165 = 'FileName'
166 = 'Version'
194 = 'Path'
196 = 'FileType'
310 = 'Trademark'
}
$shell = New-Object -ComObject "Shell.Application"
$objDir = $shell.NameSpace($SourceFolder)
$files = Get-ChildItem -Path $SourceFolder -Filter '*.*' -File -Recurse:$Recurse
foreach($file in $files) {
$objFile = $objDir.ParseName($file.Name)
$mediaFile = $objDir.Items()
$output = [ordered]@{}
$fontProperties.GetEnumerator() | ForEach-Object {
$name = $objDir.GetDetailsOf($mediaFile, $_.Name)
if (![string]::IsNullOrWhiteSpace($name)) {
$output[$_.Value] = $objDir.GetDetailsOf($objFile, $_.Name)
}
}
[PsCustomObject]$output
}
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($objFile)
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($objDir)
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($shell)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
}
Get-FontInfo -SourceFolder 'D:\Test' # the path of the font folder
If you have subfolders inside the source folder, also add the -Recurse
switch.如果源文件夹中有子文件夹,还要添加
-Recurse
开关。
Output something like: Output 类似于:
Name : aparaj.ttf Size : 194 kB Type : TrueType-lettertypebestand Author : Title : Aparajita Copyright : Copyright (c) 2011, Modular Infotech, Pune, INDIA. - Licenced to Microsoft Company : Description : This font is primarily meant for use in displaying Hindi text in documents. It is an OpenType font, based on Unicode. Extension : .ttf FileName : aparaj.ttf Version : 6.00 Path : D:\Test\aparaj.ttf FileType : TrueType-lettertypebestand Trademark :
After reviewing Theo's answer, and doing some code modification, I made the discovery that there are different extended attributes depending on if the font is installed or not.在查看了 Theo 的答案并进行了一些代码修改后,我发现根据是否安装了字体,存在不同的扩展属性。 The top section of the following output is when the font is installed, versus the bottom section when it is not installed.
以下 output 的顶部是安装字体时,而底部是未安装时。 In short, if I want to embed the 'Font Style' and 'Designed For' into the image Im generating, I need to install the font first.
简而言之,如果我想将“字体样式”和“设计用于”嵌入到我生成的图像中,我需要先安装字体。
Value Attribute Index
----- --------- -----
Regular Font style 1
Show Show/hide 2
Arabic Designed for 3
Text Category 4
Microsoft Corporation Designer/foundry 5
Editable Font embeddability 6
OpenType Font type 7
Arabic Typesetting Family 8
2013-Aug-22 11:34 A Date modified 10
505 KB Size 11
C:\Windows\Fonts\ARABTYPE.TTF Font file names 13
6.00 Font version 14
------------------------------------------------------------------------------------
609 KB Size 1
TrueType font file Item type 2
2009-Jun-10 04:43 P Date modified 3
2019-Dec-16 01:50 P Date created 4
2019-Dec-16 01:50 P Date accessed 5
A Attributes 6
Available offline Availability 8
Unspecified Perceived type 9
Everyone Owner 10
Unrated Rating 19
Mamoun Sakkal, Paul C. Nelson and John Hudson Authors 20
Arabic Typesetting Title 21
© 2008 Microsoft Corporation. All Rights Res... Copyright 25
94.9 GB Total size 50
WINDOWS8.1 (this PC) Computer 53
.ttf File extension 156
arabtype.ttf Filename 157
5.91 File version 158
1.81 GB Space free 161
No Shared 178
Fonts Folder name 181
Y:\Documents\Fonts Folder path 182
Fonts (Y:\Documents) Folder 183
Y:\Documents\Fonts\arabtype.ttf Path 185
TrueType font file Type 187
Unresolved Link status 193
98% Space used 242
Not shared Sharing status 282
Available <unknown> 283
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.