Example #1
0
 private void importToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog a = new OpenFileDialog()
     {
         DefaultExt = "txt",
         Filter = "Font data|fontdata.txt|All Files|*.*",
         Multiselect = false
     })
     {
         if (a.ShowDialog(this) == DialogResult.OK)
         {
             FontINI ini = new FontINI();
             ini   = IniSerializer.Deserialize <FontINI>(a.FileName);
             files = new List <FontItem>();
             listBox1.Items.Clear();
             listBox1.BeginUpdate();
             for (int i = 0; i < (ini.chars.Count) / 256 + Math.Min(1 * (ini.chars.Count) % 256, 1); i++)
             {
                 if (!File.Exists(Path.GetDirectoryName(a.FileName) + "\\fontsheet" + i.ToString() + ".png"))
                 {
                     break;
                 }
                 Bitmap sheetbmp = new Bitmap(Image.FromFile(Path.GetDirectoryName(a.FileName) + "\\fontsheet" + i.ToString() + ".png"));
                 for (int u = 0; u < 256; u++)
                 {
                     if (i * 256 + u >= ini.chars.Count)
                     {
                         break;
                     }
                     FontItem item    = new FontItem();
                     Bitmap   charbmp = new Bitmap(24, 24);
                     using (var canvas = Graphics.FromImage(charbmp))
                     {
                         Text = "Importing character " + u.ToString() + " of " + ini.chars.Count.ToString();
                         canvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                         canvas.DrawImage(sheetbmp, new Rectangle(0, 0, 24, 24), new Rectangle((u % 16) * 24, (u / 16) * 24, 24, 24), GraphicsUnit.Pixel);
                         canvas.Save();
                         item.bits      = new BitmapBits(charbmp.Clone(new Rectangle(0, 0, 24, 24), PixelFormat.Format1bppIndexed));
                         item.ID        = ushort.Parse(ini.chars[i * 256 + u].id, System.Globalization.NumberStyles.HexNumber);
                         item.miscdata  = StrToByteArray(ini.chars[i * 256 + u].md);
                         item.character = ini.chars[i * 256 + u].ch;
                         files.Add(item);
                     }
                 }
             }
             for (int z = 0; z < files.Count; z++)
             {
                 listBox1.Items.Add(files[z].ID.ToString("X4") + ' ' + files[z].character);
             }
             listBox1.EndUpdate();
             listBox1.SelectedIndex = 0;
             Text = "SADXFontEdit - " + a.FileName + " / Total characters: " + files.Count.ToString();
             extractAllToolStripMenuItem.Enabled = saveAsToolStripMenuItem.Enabled = exportIndividualCharactersToolStripMenuItem.Enabled = true;
         }
     }
 }
Example #2
0
 private void extractAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (SaveFileDialog dlg = new SaveFileDialog()
     {
         DefaultExt = "", Filter = "", FileName = "font"
     })
     {
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             Directory.CreateDirectory(dlg.FileName);
             string  dir = Path.Combine(Path.GetDirectoryName(dlg.FileName), Path.GetFileName(dlg.FileName));
             FontINI ini = new FontINI();
             ini.chars = new List <FontCharacter>();
             for (int i = 0; i < (files.Count) / 256 + Math.Min(1 * (files.Count) % 256, 1); i++)
             {
                 var bitmap = new Bitmap(384, 384);
                 using (var canvas = Graphics.FromImage(bitmap))
                 {
                     canvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                     for (int u = 0; u < 256; u++)
                     {
                         if ((256 * i + u) >= files.Count)
                         {
                             break;
                         }
                         FontCharacter newitem = new FontCharacter();
                         newitem.id = (files[256 * i + u].ID.ToString("X"));
                         newitem.md = BitConverter.ToString(files[256 * i + u].miscdata).Replace("-", "");
                         newitem.ch = files[256 * i + u].character;
                         ini.chars.Add(newitem);
                         canvas.DrawImage(files[256 * i + u].bits.ToBitmap(), new Rectangle(24 * (u % 16), 24 * (u / 16), 24, 24), new Rectangle(0, 0, 24, 24), GraphicsUnit.Pixel);
                         canvas.Save();
                     }
                     bitmap.Save(System.IO.Path.Combine(dir, "fontsheet" + i.ToString() + ".png"));
                 }
             }
             IniSerializer.Serialize(ini, System.IO.Path.Combine(dir, "fontdata.txt"));
         }
     }
 }