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:
So, the ideal method should be reading the postscript names from the installed fonts
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).
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.
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With