C++ 获取字体';从字体';s附言名

C++ 获取字体';从字体';s附言名,c++,windows,macos,fonts,postscript,C++,Windows,Macos,Fonts,Postscript,我试图获取字体文件名,而我仅有的信息是字体的“postscript”名称。(强调:字体名称为postscript,而非字体)。 例如,我有以下postscript名称:TimesNewRomanPSMT。 保存在注册表中的真实名称是:Times New Roman(TrueType)。 有没有办法从给定的postscript名称中获取该名称 我在这里看到了一个类似的帖子,它没有电源: 我在C++中编码,所以我不受编码语言的限制。 目前我正在为Windows编写代码,但它应该兼容,或者至少有M

我试图获取字体文件名,而我仅有的信息是字体的“postscript”名称。(强调:字体名称为postscript,而非字体)。
例如,我有以下postscript名称:TimesNewRomanPSMT。
保存在注册表中的真实名称是:Times New Roman(TrueType)。
有没有办法从给定的postscript名称中获取该名称

我在这里看到了一个类似的帖子,它没有电源:

我在C++中编码,所以我不受编码语言的限制。
目前我正在为Windows编写代码,但它应该兼容,或者至少有MaOS

> P>的替代代码。我有C++代码,从给定的ftTobe文件中获取fNoTeNT检查头…然而,对于我测试过的一些字体(比如90%)来说,它失败了。我认为最简单的方法是用十六进制编辑器打开字体文件并在其中搜索字体名称。如果您担心注册表问题,可以重新注册字体名称,如下例所示:


reg添加“HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts”/v“Arial Bold”/t reg_SZ/d arialbd.ttf

我也有类似的问题,但对于Photoshop。所以我写了下面的代码。它输出系统中安装的所有字体及其文件名、Windows名称和Postscript名称的CSV

您需要安装Photoshop和Python才能运行它。在运行它之前,还要打开一个Photoshop窗口,以便从那里获取字体列表

Shortname函数从这里开始-


“Postscript名称”的来源是什么?您如何确定它与已安装的字体相关?我将解释。我是在使用Adobe的After Effects SDK时得到这个名字的。当我遍历文本时,我得到了这个名称,我知道它肯定是“Times New Roman(True Type)”,但是Adobe说他们公开的字体名称是该字体的post脚本名称,它是“Times NewRomanpsmt”。浏览了很多论坛,我发现上面提到的相关问题也有同样的困境。ps名称的来源是当我使用Adobe AfterEffects SDK时。我遍历一个文本对象(称为“文本层”),从sdk接收的字体是“TimesNewRomanPSMT”。Adobe在其文档中声明这是该字体的ps名称。字体是:“Times New Roman(True Type)”,我首先要尝试的是unix风格的工具,如
fc list | grep
fc list
fontconfig
的一部分。我尝试了您的建议,并在一种名为Norasi:fc list Norasi | grep Norasi的字体上执行了此操作,结果并不十分有趣:/usr/share/fonts/truetype/tlwg/Norasi-Bold斜交。ttf:Norasi:style=Bold斜交/usr/share/font/truetype/Norasi-Bold.ttf:Norasi:style=Bold/usr/share/fonts/truetype/tlwg/Norasi.ttf:Norasi:style=Regular/usr/share/fonts/truetype/tlwg/Norasi-deletalic.ttf:Norasi:style=deletalic/usr/share/Norasi-Italic.ttf:Norasi:style=Italic/usr/share/fonts/truetype/Norasi-BoldItalic.ttf:Norasi:style=BoldItalic
# This program lists all installed fonts on the computer with their font file name, Windows name and Postscript name.

import os
from fontTools import ttLib
from win32com.client import GetActiveObject
import pandas as pd

FONT_SPECIFIER_NAME_ID = 4
FONT_SPECIFIER_FAMILY_ID = 1
list = []
app = GetActiveObject("Photoshop.Application") # Get instance of open Photoshop window
df = pd.DataFrame(columns=['Font File Name', 'Windows Name', 'Postscript Name'])

def shortName(font):
    """Get the short name from the font's names table"""
    name = ""
    family = ""
    for record in font['name'].names:
        if b'\x00' in record.string:
            name_str = record.string.decode('utf-16-be')
        else:
            name_str = record.string.decode('utf-8')
        if record.nameID == FONT_SPECIFIER_NAME_ID and not name:
            name = name_str
        elif record.nameID == FONT_SPECIFIER_FAMILY_ID and not family:
            family = name_str
        if name and family: break
    return name, family

def getPostScriptName(winName):
    for i in range(0, len(app.fonts)):
        if(app.fonts[i].name == winName):
            return app.fonts[i].postScriptName

x = 0
for file in os.listdir(r'C:\Windows\Fonts'):
    if (file.endswith(".ttf") or file.endswith(".otf")):
        # list.append(file)
        try:
            fontfile = file
            file = "C:\\Windows\\Fonts\\" + file
            tt = ttLib.TTFont(file)
            psName = getPostScriptName(shortName(tt)[0])
            print(fontfile, shortName(tt)[0], psName)
            df.at[x, 'Font File Name'] = fontfile
            df.at[x, 'Windows Name'] = shortName(tt)[0]
            df.at[x, 'Postscript Name'] = psName
            x = x + 1
            df.to_csv("installed-fonts.csv",index=False)
        except Exception as e:
            print (e)
            continue