【问题标题】:Determine exact name of an OpenType font in PowerShell在 PowerShell 中确定 OpenType 字体的确切名称
【发布时间】:2018-11-01 21:53:25
【问题描述】:

我有一组 OpenType 字体文件,它们都是同一家族的不同风格:

  • “FreigSanLFProBol.otf”(FreightSansLFPro 粗体)
  • “FreigSanLFProBoo.otf” (FreightSansLFPro 常规)
  • "FreigSanLFProBooIta.otf" (FreightSansLFPro 斜体)

为了通过 PowerShell 安装这些字体并将它们正确添加到注册表,我需要知道它们的友好样式名称。

当我通过 Windows 资源管理器安装“FreigSanLFProBol.otf”时,注册表项包含以下数据:

{
  name: "FreightSansLFPro Bold (TrueType)",
  type: REG_SZ,
  data: "FreigSanLFProBol.otf"
}

问题是我不知道如何从字体文件本身以编程方式识别“名称”键中的值。

使用Name of font by powershell 中提供的信息,我能够到达那里的大部分路:

$path = "C:\Windows\Fonts\FreigSanLFProBol.otf"
Add-Type -AssemblyName System.Drawing
$fontCollection = New-Object System.Drawing.Text.PrivateFontCollection
$fontCollection.AddFontFile($(Get-Item $path).fullname)
$fontCollection.Families[-1].Name

这给了我“FreightSansLFPro”的结果 - 这与将其作为“FreightSansLFPro Bold”的 reg 键值不同。 (不要介意 reg 键仍然将类型列为“TrueType 字体”,即使它是 OpenType 字体)。

它从哪里获得“粗体”,我如何以编程方式从字体文件中获取该特定值/名称?

【问题讨论】:

    标签: powershell fonts powershell-4.0


    【解决方案1】:
    $folder = "C:\Windows\fonts\"
    
    $objShell = New-Object -ComObject Shell.Application 
    
    
    $fileList = @() 
    $attrList = @{} 
    $details = ( "Title",
                  "Font style",
                  "Show/hide", 
                  "Designed for",
                  "Category",
                  "Designer/foundry" ,
                   "Font Embeddability",
                   "Font type",
                   "Family",
                   "Date created",
                   "Date modified",
                   "Collection",
                   "Font file names",
                   "Font version"
                     ) 
    
     #figure out what the possible metadata is
    $objFolder = $objShell.namespace($folder) 
    for ($attr = 0 ; $attr  -le 500; $attr++) 
    { 
        $attrName = $objFolder.getDetailsOf($objFolder.items, $attr) 
        if ( $attrName -and ( -not $attrList.Contains($attrName) )) 
        {  
            $attrList.add( $attrName, $attr )  
        } 
    } 
    
     #$attrList
    
     #loop through all the fonts, and process
         $objFolder = $objShell.namespace($folder) 
        foreach($file in $objFolder.items()) 
        { 
            foreach( $attr in $details) 
            { 
    
                $attrValue = $objFolder.getDetailsOf($file, $attrList[$attr]) 
                if ( $attrValue )  
                {  
                    Add-Member -InputObject $file -MemberType NoteProperty -Name $attr -value $attrValue 
                }  
            } 
            $fileList += $file 
            write-verbose "Prcessing file number $($fileList.Count)"
        } 
    
    
    $fileList | select $details |  out-gridview
    

    来源:https://powershell.org/forums/topic/listing-font-details/

    【讨论】:

    • 知道如何在 Windows 上检索任何给定文件类型的元数据(即companyauthorcopyrightlegal trademark 等)字段吗??
    • @oldboy:不是为此而来的,但你来了:Add-Type -AssemblyName PresentationCore 然后New-Object -TypeName Windows.Media.GlyphTypeface -ArgumentList $toInstallAbsolutePath 这将为您提供您正在寻找的信息
    • @MaxouMask ooo 非常感谢
    猜你喜欢
    • 2014-04-03
    • 2013-08-17
    • 2017-02-19
    • 1970-01-01
    • 2022-06-14
    • 2013-08-09
    • 2013-08-07
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多