in silverlight 4 I need to know all the font names in my machines. Using....
...
var typefaces = System.Windows.Media.Fonts.SystemTypefaces;
foreach (System.Windows.Media.Typeface face in typefaces)
{
System.Windows.Media.GlyphTypeface a;
face.TryGetGlyphTypeface(out a);
FontSource fs = new FontSource(a);
var b = a.FontFileName;
...
I only can get FontFileName but actually we'd need the fontname for showing it....
How can get such info?
thanks you all!
WPF has the properties to do this, but Silverlight does not.
If you look at the System.Windows.Media.Typeface objects in the debugger the fonts do not contain anything except 2 version numbers and the FontUri (read filename).
You could generate a lookup dictionary by running code under WPF to extract all the filenames and matching fontnames, but you need to do that on a machine with every font installed that you want to cover.
The WPF code below extracts such a table (this one contains the font names in all languages, so you will probably want to add a filter to it e.g. by "en-us"):
foreach (var font in System.Windows.Media.Fonts.SystemTypefaces)
{
System.Windows.Media.GlyphTypeface glyphTypeface;
font.TryGetGlyphTypeface(out glyphTypeface);
var dictionary = font.FaceNames;
foreach (var language in dictionary.Keys)
{
Debug.WriteLine(string.Format("\"{0}\", \"{1}\", \"{2}\"", glyphTypeface.FontUri.Segments[glyphTypeface.FontUri.Segments.Count()-1], language, dictionary[language]));
}
}
Part of the output is shown below and could be easily formatted into a table or loaded as a dictionary in Silverlight:
"ARIAL.TTF", "ca-es", "Normal"
"ARIAL.TTF", "cs-cz", "obyčejné"
"ARIAL.TTF", "da-dk", "normal"
"ARIAL.TTF", "de-de", "Standard"
"ARIAL.TTF", "el-gr", "Κανονικά"
"ARIAL.TTF", "en-us", "Regular"
"ARIAL.TTF", "es-es", "Normal"
"ARIAL.TTF", "es-mx", "Normal"
"ARIAL.TTF", "eu-es", "Arrunta"
"ARIAL.TTF", "fi-fi", "Normaali"
"ARIAL.TTF", "fr-ca", "Normal"
"ARIAL.TTF", "fr-fr", "Normal"
"ARIAL.TTF", "hu-hu", "Normál"
"ARIAL.TTF", "it-it", "Normale"
"ARIAL.TTF", "nb-no", "Normal"
"ARIAL.TTF", "nl-nl", "Standaard"
"ARIAL.TTF", "pl-pl", "Normalny"
"ARIAL.TTF", "pt-br", "Normal"
"ARIAL.TTF", "pt-pt", "Normal"
"ARIAL.TTF", "ru-ru", "Обычный"
"ARIAL.TTF", "sk-sk", "Normálne"
"ARIAL.TTF", "sl-si", "Navadno"
"ARIAL.TTF", "sv-se", "Normal"
"ARIAL.TTF", "tr-tr", "Normal"
"ARIAL.TTF", "vi-vn", "thường"
"ARIALN.TTF", "en-us", "Narrow"
"ARIALI.TTF", "ca-es", "Cursiva"
"ARIALI.TTF", "cs-cz", "kurzíva"
"ARIALI.TTF", "da-dk", "kursiv"
"ARIALI.TTF", "de-de", "Kursiv"
"ARIALI.TTF", "el-gr", "Πλάγια"
"ARIALI.TTF", "en-us", "Italic"
"ARIALI.TTF", "es-es", "Cursiva"
"ARIALI.TTF", "es-mx", "Cursiva"
"ARIALI.TTF", "eu-es", "Etzana"
"ARIALI.TTF", "fi-fi", "Kursivoitu"
"ARIALI.TTF", "fr-ca", "Italique"
"ARIALI.TTF", "fr-fr", "Italique"
"ARIALI.TTF", "hu-hu", "Dőlt"
"ARIALI.TTF", "it-it", "Corsivo"
"ARIALI.TTF", "nb-no", "Kursiv"
"ARIALI.TTF", "nl-nl", "Cursief"
"ARIALI.TTF", "pl-pl", "Kursywa"
"ARIALI.TTF", "pt-br", "Itálico"
"ARIALI.TTF", "pt-pt", "Itálico"
"ARIALI.TTF", "ru-ru", "Курсив"
"ARIALI.TTF", "sk-sk", "Kurzíva"
"ARIALI.TTF", "sl-si", "Poševno"
"ARIALI.TTF", "sv-se", "Kursiv"
"ARIALI.TTF", "tr-tr", "İtalik"
"ARIALI.TTF", "vi-vn", "nghiêng"
"ARIALNI.TTF", "en-us", "Narrow"
"ARIALBD.TTF", "ca-es", "Negreta"
"ARIALBD.TTF", "cs-cz", "tučné"
"ARIALBD.TTF", "da-dk", "fed"
"ARIALBD.TTF", "de-de", "Fett"
"ARIALBD.TTF", "el-gr", "Έντονα"
"ARIALBD.TTF", "en-us", "Bold"
"ARIALBD.TTF", "es-es", "Negrita"
"ARIALBD.TTF", "es-mx", "Negrita"
"ARIALBD.TTF", "eu-es", "Lodia"
"ARIALBD.TTF", "fi-fi", "Lihavoitu"
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