WPF Lover
WPF Lover

Reputation: 309

Character Map in WPF

I like to build my own character map in WPF. Is there any easiest way to iterate through all unicode characters of a true type font?

I have tried something like this.

        FontFamily fontfamily = combo.SelectedItem as FontFamily;
        var typefaces = fontfamily.GetTypefaces();
        foreach (Typeface typeface in typefaces)
        {
            GlyphTypeface glyph;
            typeface.TryGetGlyphTypeface(out glyph);
            if (glyphs != null)
            {
                mylist.Items.Add(glyph);
            }              
        }

This just adding Glyphs namespace into my listbox. I am not sure how to define my data template in this case.

Regards,

Jawahar

Upvotes: 0

Views: 1049

Answers (1)

gliderkite
gliderkite

Reputation: 8928

As specified by MSDN:

A GlyphTypeface is font face that directly corresponds to a font file on the disk. A Typeface, however, is a representation of font face. Typeface is a single variation of a font within the same font family.

So if you want build your complete map, try to consider the Typeface class itself. Then, to iterate through all typefaces there's a very simple way:

foreach (FontFamily fontFamily in Fonts.SystemFontFamilies) {
   foreach (Typeface tFace in fontFamily.GetTypefaces) {
       //Get wat you want with tFace
   }
}

Upvotes: 1

Related Questions