private void btnAddCharacters_Click(object sender, EventArgs e)
 {
     using (var form = new FormAddCharacters())
     {
         var result = form.ShowDialog();
         if (result == DialogResult.OK)
         {
             for (ushort ch = 32; ch <= 127; ch++)
             {
                 if (ziFont.CodePage.CodePoints.Contains(ch))
                 {
                     if (ziFont.Characters.Exists(character => { return(character.CodePoint == ch); }))
                     {
                         if (true)
                         {
                             // replace existing char
                         }
                     }
                     else
                     {
                         var txt       = Char.ConvertFromUtf32((int)ch);
                         var bmp       = ZiLib.Extensions.BitmapExtensions.DrawString(txt, "", (byte)ziFont.CharacterHeight);
                         var bytes     = ZiLib.FileVersion.V5.BinaryTools.BitmapTo3BppData(bmp);
                         var character = ZiCharacter.FromBytes(ziFont, ch, bytes, (byte)bmp.Width, 0, 0);
                         ziFont.AddCharacter(ch, character);
                     }
                 }
             }
         }
     }
 }
        private void btnAddCharacters_Click(object sender, EventArgs e)
        {
            using (var form = new FormAddCharacters()) {
                var result = form.ShowDialog();
                if (result == DialogResult.OK)
                {
                    var font        = new System.Drawing.Font("Arial Unicode MS", 24);
                    var emheight    = font.FontFamily.GetEmHeight(System.Drawing.FontStyle.Regular);
                    var linespacing = font.FontFamily.GetLineSpacing(System.Drawing.FontStyle.Regular);
                    var fontsize    = (float)(ziFont.CharacterHeight * emheight / linespacing * 0.985);
                    font = new System.Drawing.Font(font.FontFamily, fontsize, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);

                    /* System.Windows.Media */
                    var           fontface = new Typeface("Arial Unicode MS");
                    var           ret      = false;
                    GlyphTypeface glyphFace;
                    ret = fontface.TryGetGlyphTypeface(out glyphFace);

                    //GlyphRun glyphRun = null;
                    //glyphRun = new GlyphRun(glyphFace, 0, false, 24, new ushort[] { 0 }, new Point(0, 0), new double[] { 0 },
                    //    null, null, null, null, null, null);

                    foreach (var item in ziFont.Characters)
                    {
                        //if (ziFont.CodePage.CodePoints.Contains(ch)) {
                        //var item = ziFont.Characters.Find(character => { return character.CodePoint == ch; });
                        if (item != null)
                        {
                            if (true)
                            {
                                var leftKern  = 0d;
                                var rightKern = 0d;
                                try {
                                    ushort glyphIndex = glyphFace.CharacterToGlyphMap[(int)item.CodePoint];

                                    //glyphRun = new GlyphRun(glyphFace, 0, false, 24, new ushort[] { (ushort)item.CodePoint }, new Point(0, 0), new double[] { glyphFace.AdvanceWidths[glyphIndex] },
                                    //        null, null, null, null, null, null);
                                    //glyphRun.GlyphTypeface = glyphFace;
                                    //glyphRun.FontRenderingEmSize = emheight;


                                    string txt = item.GetString();
                                    leftKern  = glyphFace.LeftSideBearings[glyphIndex] * fontsize;
                                    rightKern = glyphFace.RightSideBearings[glyphIndex] * fontsize;
                                    double charWidth = glyphFace.AdvanceWidths[glyphIndex] * fontsize;
                                    if (leftKern < -0.5 || rightKern < -0.5)
                                    {
                                        var a = 0;
                                    }
                                }
                                catch (Exception err) {
                                }

                                // replace existing char
                                item.SetString(font, new System.Drawing.PointF(0, 0), item.GetString());
                                if (leftKern < -0)
                                {
                                    item.KerningLeft = (byte)Math.Ceiling(-leftKern + 1);
                                }
                                else
                                {
                                    item.KerningLeft = 0;
                                }
                                if (rightKern < -0)
                                {
                                    item.KerningRight = (byte)Math.Ceiling(-rightKern + 1);
                                }
                                else
                                {
                                    item.KerningRight = 0;
                                }
                            }
                        }
                        else
                        {
                            var txt = Char.ConvertFromUtf32((int)item.CodePoint);
                            // var bmp = ZiLib.Extensions.BitmapExtensions.DrawString(txt, "", (byte)ziFont.CharacterHeight);
                            // var bytes = ZiLib.FileVersion.V5.BinaryTools.BitmapTo3BppData(bmp);
                            var character = ZiCharacter.FromString(ziFont, item.CodePoint, new System.Drawing.Font("Arial", 22), new System.Drawing.PointF(0, 0), txt);
                            ziFont.AddCharacter(item.CodePoint, character);
                        }
                        //}
                    }
                }
            }
        }