Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the postscript names of all the installed fonts

Tags:

c#

fonts

gdi+

gdi

I need to enumerate the postsript names of all the installed fonts.

for example:

        foreach (FontFamily item in FontFamily.Families)
        {
            listBox1.Items.Add(item.Name);
        }

This will give only the actual font names. But I need to find the postscript names.

Eg: For the font "Arial Black" - 1. Actual font name is "Arial Black" 2. PostScript name is "Arial-Black"

Thanks in advance, James


EDIT:

  1. @ plinth Actually, I read the font name from the PDF and load the corresponding system font. In this case, the PDF has a font name "Arial-Black" (Post script name).. how can I load the font from the sytem (Arial Black) accordingly....ideas??

So, the ideal method should be reading the postscript names from the installed fonts

  1. Substituting '-' with '' is not a suitable solution because, there are possibilities of other font names such as "Arial-Bold", "Time New Roman - PSMT" etc..
like image 581
user438959 Avatar asked Apr 07 '11 10:04

user438959


People also ask

How do I find the title of a PostScript font?

Ideally, you would find this in the "name" table of the font. It would be nameId 0x0006, in a form useful for your platform. The format of the name table is a part of the TrueType and OpenType specifications. (You can find a copy here Microsoft Typography OpenType spec Name).

What is PostScript name in font?

Type 1 (also known as PostScript, PostScript Type 1, PS1, T1 or Adobe Type 1) is the font format for single-byte digital fonts for use with Adobe Type Manager software and with PostScript printers. It can support font hinting.

How do I find the PostScript font on a Mac?

What worked for me was to right click the font file and select "Get Info". The value in the "Full name" field under the General tab is what worked for me and appears to be the PostScript name.


2 Answers

You may do it directly in PostScript. Execute this:

%!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

I have been able to find out the available fonts of a printer with this code.

I hope I've helped you.

like image 149
Ricardo Nolde Avatar answered Oct 17 '22 21:10

Ricardo Nolde


I have done something very similar to that. You should be aware the FontFamily.Families may not be the entire set of available fonts.

Why not just substitute '-' for ' '?

In my case, I needed to go to the PDF font name, which for Times New Roman in bold style had to be "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();
    }
like image 25
plinth Avatar answered Oct 17 '22 22:10

plinth