title: Display glyph from font file
body: <p>Working on one windows application (.Net 4.0) which will accept font file name as input and will return images for each glyph in font. Tried all possible Google stuff but not getting all glyph s images. And if getting  images that also have some wrong out put. Please suggest me the ways to do this... Currently had following work out...</p>
  
  <pre><code>private void generateBitmaps(string strFontpath)
          {
              ////Generate font object
              GlyphTypeface font = new GlyphTypeface(new Uri(strFontpath));
              int fontSize = 22;
              int intGlyphcount = 0;
              //Collect geometry of all glyphs
              var Glyphs = from glyphIndex in font.CharacterToGlyphMap.Values
                           select font.GetGlyphOutline(glyphIndex, fontSize, 1d);
              // now create the visual we'll draw them to
              DrawingVisual viz = new DrawingVisual();
              System.Drawing.Size cellSize = new System.Drawing.Size(fontSize, Convert.ToInt32(fontSize * font.Height));
              int bitWidth = (int)Math.Ceiling(Convert.ToDecimal(cellSize.Width*10));
              int bitHeight = (int)Math.Ceiling(Convert.ToDecimal(cellSize.Height * 10));
  
              //using (DrawingContext dc = viz.RenderOpen())
              {
                  foreach (var g in Glyphs)
                  {
                      if (intGlyphcount &gt; font.GlyphCount)
                          break;
                      //if (g.IsEmpty())
                      //    continue; // don't draw the blank ones
                      DrawingContext dc = viz.RenderOpen();                   
                      dc.PushTransform(new TranslateTransform());
                      System.Windows.Media.Pen glyphPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Black, 1);
                      dc.DrawGeometry(System.Windows.Media.Brushes.Red, glyphPen, g);
                      //GeometryDrawing glyphDrawing = new GeometryDrawing(System.Windows.Media.Brushes.White, glyphPen, g);
                      //DrawingImage geometryImage = new DrawingImage(glyphDrawing);
                      //dc.DrawImage(geometryImage, new Rect(0, 0, 150, 150));
                      dc.Close();
                      //geometryImage.Freeze();
                      //dc.Pop(); // get rid of the transform
                      RenderTargetBitmap bmp = new RenderTargetBitmap(
                                                              200, 200,
                                                              96, 96,
                                                              PixelFormats.Pbgra32);
                      bmp.Render(viz);
                      PngBitmapEncoder encoder = new PngBitmapEncoder();
                      encoder.Frames.Add(BitmapFrame.Create(bmp));
                      using (FileStream file = new FileStream(@"GlyphList\Glyph" + intGlyphcount++ + ".png", FileMode.Create))
                          encoder.Save(file);
  
                      //dc.Pop();
                  }
  
              }
              MessageBox.Show("Done");
          }
  </code></pre>