首页 > 解决方案 > Node.js - 获取字体属性描述

问题描述

是否可以访问Description字体属性的一部分,如右键单击文件时显示的那样?

在此处输入图像描述

例如,在这里,我对Title属性感兴趣。

我已经使用了Node JS - read file propertiesget-file-properties中描述的包,但它似乎无法访问它(它在幕后使用,它也不会返回它)。例如不存在,返回wmicTitleDescriptionC:\\Windows\\Fonts\\Alegreya-Bold.ttf

还有其他方法可以访问此信息吗?

谢谢

标签: node.jswindowspowershellcmdfonts

解决方案


正如@RobinMackenzie 提到的,有 ttfinfo 包(https://github.com/trevordixon/ttfinfo),它将以这种形式为您提供有关特定字体的信息:

{
  tables: {
    name: {
      '0': 'Copyright 2011 The Alegreya Project Authors (https://github.com/huertatipografica/Alegreya)',
      '1': 'Alegreya',
      '2': 'Bold',
      '3': '2.003;HT  ;Alegreya-Bold',
      '4': 'Alegreya Bold',
      '5': 'Version 2.003; ttfautohint (v1.6)',
      '6': 'Alegreya-Bold',
      '8': 'Huerta Tipografica',
      '9': 'Juan Pablo del Peral',
      '11': 'http://www.huertatipografica.com',
      '12': 'http://www.huertatipografica.com',
      '13': 'This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is available with a FAQ at: http://scripts.sil.org/OFL',
      '14': 'http://scripts.sil.org/OFL',
      '256': 'Roman numerals',
      '257': 'Arrows, triangles and circles',
      '258': 'Foundry icon',
      '259': 'Dynamic arrows and triangles'
    },
    post: {
      format: 2,
      italicAngle: 0,
      underlinePosition: 0,
      underlineThickness: 0,
      minMemType42: 16734720,
      maxMemType42: 1509968640,
      minMemType1: 1258291200,
      maxMemType1: 0
    },
    'OS/2': { version: 4, weightClass: 700 }
  }
}

可以在此处找到完整的名称列表 ( 0, 1, ,...): https ://docs.microsoft.com/en-us/typography/opentype/spec/name#name-ids2

还有 node-system-fonts ( https://github.com/jgilsaa/node-system-fonts ),它需要一个构建步骤,因为它是一个 C++ 模块,但从好的方面来说,它为您提供了很多相同的信息, 对于每个安装的字体:

[
  {
    path: 'C:\\WINDOWS\\FONTS\\ARIAL.TTF',  
    postscriptName: 'ArialMT',
    family: 'Arial',
    style: 'Regular',
    weight: 400,
    width: 5,
    italic: false,
    monospace: false
  },
  {
    path: 'C:\\WINDOWS\\FONTS\\ARIALN.TTF', 
    postscriptName: 'ArialNarrow',
    family: 'Arial Narrow',
    style: 'Regular',
    weight: 400,
    width: 3,
    italic: false,
    monospace: false
  },
  {
    path: 'C:\\WINDOWS\\FONTS\\ARIALI.TTF', 
    postscriptName: 'Arial-ItalicMT',       
    family: 'Arial',
    style: 'Italic',
    weight: 400,
    width: 5,
    italic: true,
    monospace: false
  },
  ...
]

推荐阅读