我需要枚举所有已安装字体的postript名称。
例如:
foreach (FontFamily item in FontFamily.Families)
{
listBox1.Items.Add(item.Name);
}
这将仅提供实际的字体名称。但我需要找到附言名称。
例如:字体“Arial Black” - 1.实际字体名称为“Arial Black” 2. PostScript名称为“Arial-Black”
提前致谢, 詹姆斯
修改
因此,理想的方法应该是从已安装的字体中读取postscript名称
答案 0 :(得分:4)
您可以直接在PostScript中执行此操作。执行:
%!PS
/FS { findfont exch scalefont setfont } bind def
% gets page boundaries
clippath pathbbox newpath
/var_TopOfPage exch def
/var_RightOfPage exch def
/var_BottomOfPage exch def
/var_LeftOfPage exch def
% helvetica is almost always there
12 /Helvetica FS
0 setgray
% set start position
var_LeftOfPage var_TopOfPage 30 sub moveto
/pos var_TopOfPage 20 sub def
GlobalFontDirectory {
var_LeftOfPage pos moveto
/FontName get 70 string cvs show
/pos pos 20 sub def
pos 0 le {
showpage
/pos var_TopOfPage 20 sub def
} if
} forall
showpage
%%EOF
我已经能够使用此代码找出打印机的可用字体。
我希望我帮助过你。
答案 1 :(得分:0)
我做了类似的事情。您应该知道FontFamily.Families可能不是整套可用字体。
为什么不用' - '代替''?
在我的情况下,我需要转到PDF字体名称,其中大胆风格的Times New Roman必须是“TimesNewRoman,Bold”。
private static string ToPdfFontName(Font f)
{
StringBuilder sb = new StringBuilder();
StripSpaces(sb, f.Name);
if ((f.Style & FontStyle.Bold)!= 0 && (f.Style & FontStyle.Italic)!= 0)
{
sb.Append(",BoldItalic");
}
else if ((f.Style & FontStyle.Bold)!= 0)
{
sb.Append(",Bold");
}
else if ((f.Style & FontStyle.Italic)!= 0)
{
sb.Append(",Italic");
}
return sb.ToString();
}
答案 2 :(得分:0)
此代码输出系统中安装的所有字体的CSV文件,包括文件名,Windows名称和Postscript名称。
您需要安装Photoshop和Python才能运行它。在运行它之前,还要保持打开Photoshop窗口的状态,以便它可以从中获取字体列表。
Shortname函数来自此处-https://gist.github.com/pklaus/dce37521579513c574d0
# 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")):
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