private void opnFont_FileOk(object sender, System.ComponentModel.CancelEventArgs e) { FileStream fs = null; try { fs = File.OpenRead(opnFont.FileName); LfdReader.Font newFont = new LfdReader.Font(fs, 0); if (newFont.Name != _fnt.Name) { throw new InvalidDataException(); } _fnt.DecodeResource(newFont.RawData, false); } catch (InvalidDataException) { MessageBox.Show("FONT Resource names must match to ensure compatability and prevent accidental overwrites.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception x) { MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (fs != null) { fs.Close(); } } }
void displayString(string text, short left, short top) { // in-game there's a shadow at (+1, +1) that I'm ignoring here LfdReader.Font font8 = (LfdReader.Font)_empire.Resources[_fontID]; char[] chars = text.ToCharArray(); int offset = left; byte glyph; Graphics g = Graphics.FromImage(_preview); for (int i = 0; i < chars.Length; i++) { if (chars[i] == '[') { font8.SetColor(_highlight); continue; } else if (chars[i] == ']') { font8.SetColor(_normalText); continue; } glyph = Convert.ToByte(chars[i] - font8.StartingChar); g.DrawImageUnscaled(font8.Glyphs[glyph], offset, top); offset += font8.Glyphs[glyph].Width + 1; } g.Dispose(); }
private void lstFONT_SelectedIndexChanged(object sender, EventArgs e) { if (lstFONT.SelectedIndex == -1) { return; } cmdImport.Enabled = true; cmdCopy.Enabled = false; pctImport.BackgroundImage = null; for (int i = 0; i < _lfd.Rmap.NumberOfHeaders; i++) { if (_lfd.Rmap.SubHeaders[i].Name == lstFONT.Items[lstFONT.SelectedIndex].ToString()) { _fnt = (LfdReader.Font)_lfd.Resources[i]; Text = "LFD Font Reader - " + _lfd.FileName + ":" + _fnt.Name; cmdNext.Enabled = true; cmdPrev.Enabled = true; cmdExport.Enabled = true; cmdLoad.Enabled = true; _index = 0; UpdateGlyph(); lblRules.Text = "Height must be same. Width must be " + _fnt.BitsPerScanLine + "px or less. Auto-converts to black and white."; int numRows = (int)Math.Ceiling((double)_fnt.TotalChars / pnlImages.Width * (_fnt.BitsPerScanLine + 1)); // rows of glyphs in pnlImages vsbImages.Enabled = (numRows * (_fnt.Height + 1) > pnlImages.Height); vsbImages.Value = 0; if (vsbImages.Enabled) { vsbImages.Maximum = numRows * (_fnt.Height + 2) - pnlImages.Height; } PaintGlyphs(); } } }