找到所有已安装字体的postscript名称

use*_*959 6 c# fonts gdi+ gdi

我需要枚举所有已安装字体的postript名称.

例如:

        foreach (FontFamily item in FontFamily.Families)
        {
            listBox1.Items.Add(item.Name);
        }
Run Code Online (Sandbox Code Playgroud)

这将只给出实际的字体名称.但我需要找到附言名称.

例如:对于字体"Arial Black" - 1.实际字体名称为"Arial Black"2.PostScript名称为"Arial-Black"

詹姆斯,先谢谢你


编辑:

  1. @plinth实际上,我从PDF中读取了字体名称并加载了相应的系统字体.在这种情况下,PDF有一个字体名称"Arial-Black"(后期脚本名称)..如何从系统(Arial Black)加载字体相应的....想法?

因此,理想的方法应该是从已安装的字体中读取postscript名称

  1. 用''代替''是不合适的解决方案,因为有其他字体名称的可能性,如"Arial-Bold","Time New Roman - PSMT"等.

Ric*_*lde 5

您可以直接在 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
Run Code Online (Sandbox Code Playgroud)

我已经能够使用此代码找出打印机的可用字体。

我希望我帮助了你。


pli*_*nth 1

我也做过类似的事情。您应该知道 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();
    }
Run Code Online (Sandbox Code Playgroud)