using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; namespace FCC_Uber_MDX_Configurator { public partial class AddFontForm : Form { private List _RotateColours = new List(new Color[] { Color.Black, Color.White, Color.Blue, Color.Red, Color.Yellow }); private int _RotateColours_i = 0; FusionFont _CurrentFont = new FusionFont(); private int _CurrentCharacterIndex = -1; private void SetMeUpz() { InitializeComponent(); UpdateCharacterArea(); } public AddFontForm() { SetMeUpz(); } public AddFontForm(FusionFont _inputFont) { SetMeUpz(); _CurrentFont = _inputFont; } public AddFontForm(GlobalStaticClass.PseudoFusionFont _inputFont) { SetMeUpz(); OpenFontFile(_inputFont.font_path_XML); } private void BTN_COLOUR_Click(object sender, EventArgs e) { _RotateColours_i++; _RotateColours_i %= _RotateColours.Count; UpdateCharacterArea(); } private void UpdateCharacterArea() { bool enabledBool = true; if (_CurrentCharacterIndex < 0 || _CurrentCharacterIndex >= _CurrentFont._charList.Count || _CurrentFont._Image_image == null) { enabledBool = false; } TXT_BOTTOMRIGHT_X.Enabled = enabledBool; TXT_BOTTOMRIGHT_Y.Enabled = enabledBool; TXT_OFF_BOTTOM.Enabled = enabledBool; TXT_OFF_LEFT.Enabled = enabledBool; TXT_OFF_RIGHT.Enabled = enabledBool; TXT_OFF_TOP.Enabled = enabledBool; TXT_TOPLEFT_X.Enabled = enabledBool; TXT_TOPLEFT_Y.Enabled = enabledBool; TXT_VALUE.Enabled = enabledBool; if (!enabledBool) { TXT_BOTTOMRIGHT_X.Text = ""; TXT_BOTTOMRIGHT_Y.Text = ""; TXT_OFF_BOTTOM.Text = ""; TXT_OFF_LEFT.Text = ""; TXT_OFF_RIGHT.Text = ""; TXT_OFF_TOP.Text = ""; TXT_TOPLEFT_X.Text = ""; TXT_TOPLEFT_Y.Text = ""; TXT_VALUE.Text = ""; TXT_VALUE_INT.Text = ""; } else { _CurrentFont.DisplayCharacter = new Bitmap(_CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_x - _CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_x, _CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_y - _CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_y); _CurrentFont.DisplayCharacterGraphics = Graphics.FromImage(_CurrentFont.DisplayCharacter); _CurrentFont.DisplayCharacterGraphics.Clear(_RotateColours[_RotateColours_i]); _CurrentFont.DisplayCharacterGraphics.DrawImage(_CurrentFont._Image_image, new RectangleF(0, 0, ((float)(_CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_x)), ((float)(_CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_y))), new RectangleF((float)_CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_x, (float)_CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_y, (float)_CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_x, (float)_CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_y), GraphicsUnit.Pixel); TXT_TOPLEFT_X.Text = _CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_x.ToString(); TXT_BOTTOMRIGHT_X.Text = _CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_x.ToString(); TXT_TOPLEFT_Y.Text = _CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_y.ToString(); TXT_BOTTOMRIGHT_Y.Text = _CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_y.ToString(); TXT_TOPLEFT_X.Update(); TXT_BOTTOMRIGHT_X.Update(); TXT_TOPLEFT_Y.Update(); TXT_BOTTOMRIGHT_Y.Update(); if (_CurrentFont._charList[_CurrentCharacterIndex]._value < 0) { TXT_VALUE.Text = ""; } else { TXT_VALUE.Text = ((char)_CurrentFont._charList[_CurrentCharacterIndex]._value).ToString(); TXT_VALUE_INT.Text = _CurrentFont._charList[_CurrentCharacterIndex]._value.ToString(); } TXT_OFF_LEFT.Text = _CurrentFont._charList[_CurrentCharacterIndex]._offset_left.ToString(); TXT_OFF_RIGHT.Text = _CurrentFont._charList[_CurrentCharacterIndex]._offset_right.ToString(); TXT_OFF_BOTTOM.Text = _CurrentFont._charList[_CurrentCharacterIndex]._offset_bottom.ToString(); TXT_OFF_TOP.Text = _CurrentFont._charList[_CurrentCharacterIndex]._offset_top.ToString(); TXT_OFF_LEFT.Update(); TXT_OFF_RIGHT.Update(); TXT_OFF_BOTTOM.Update(); TXT_OFF_TOP.Update(); PICT_CHARACTER.BackColor = _RotateColours[_RotateColours_i]; PICT_CHARACTER.BackgroundImage = _CurrentFont.DisplayCharacter; PICT_CHARACTER.Update(); string _xml = ParseXML(); TXT_FONT.Text = _xml; TXT_FONT.Update(); _CurrentFont.DisplayCharacterGraphics.Dispose(); } } private void BTN_OPEN_Click(object sender, EventArgs e) { if (OpenFontImageDialog.ShowDialog() == DialogResult.OK) { _CurrentFont._Image_path = OpenFontImageDialog.FileName; _CurrentFont._Image_image = new Bitmap(Image.FromFile(OpenFontImageDialog.FileName)); _CurrentFont.FontBitmapCopy = (System.Drawing.Bitmap)_CurrentFont._Image_image.Clone(); char[] split_params = { '\\', '/' }; string[] splitsss = OpenFontImageDialog.FileName.Split(split_params); _CurrentFont._name = splitsss[splitsss.Length - 1]; if (_CurrentFont._name.Contains(".")) { _CurrentFont._name = _CurrentFont._name.Substring(0, _CurrentFont._name.LastIndexOf('.')); } TXT_Name.Text = _CurrentFont._name; PICT_FULLFONT.BackgroundImage = _CurrentFont._Image_image; UpdateCharacterArea(); this.DialogResult = DialogResult.None; AddFontForm_SubFontHeightChooserForm _subH = new AddFontForm_SubFontHeightChooserForm(_CurrentFont._Image_image.Height, _CurrentFont._Image_image); if (_subH.ShowDialog() == DialogResult.OK) { if (_subH._myHeight <= _CurrentFont._Image_image.Height && _subH._myHeight > 0) { _CurrentFont._originalSize = (float)_subH._myHeight; TXT_HEIGHT.Text = _CurrentFont._originalSize.ToString(); } } this.DialogResult = DialogResult.None; } } private void GoToNewIndex(int i) { try { SaveCurrentInfo(); if (i < _CurrentFont._charList.Count && i >= 0) { _CurrentCharacterIndex = i; } else { _CurrentCharacterIndex = -1; } UpdateCharacterArea(); } catch (Exception) { return; } } private void TXT_VALUE_TextChanged(object sender, EventArgs e) { try { string value = ((TextBox)sender).Text; char[] valueArray = value.ToCharArray(); if (valueArray.Length == 1) { TXT_VALUE_INT.Text = ((int)valueArray[0]).ToString(); } } catch (Exception) { return; } } private bool SaveCurrentInfo() { if (_CurrentCharacterIndex >= 0 && _CurrentCharacterIndex < _CurrentFont._charList.Count && TXT_VALUE.Text != "") { bool _ret = (int.TryParse(TXT_BOTTOMRIGHT_X.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_x) && int.TryParse(TXT_BOTTOMRIGHT_Y.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._loc_BottomRight_y) && int.TryParse(TXT_OFF_BOTTOM.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._offset_bottom) && int.TryParse(TXT_OFF_LEFT.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._offset_left) && int.TryParse(TXT_OFF_RIGHT.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._offset_right) && int.TryParse(TXT_OFF_TOP.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._offset_top) && int.TryParse(TXT_TOPLEFT_X.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_x) && int.TryParse(TXT_TOPLEFT_Y.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._loc_TopLeft_y) && int.TryParse(TXT_VALUE_INT.Text, out _CurrentFont._charList[_CurrentCharacterIndex]._value)); UpdateListView(); return _ret; } return false; } private void AnalizeFontImage() { if (_CurrentFont._Image_image == null) { (new ErrorForm("No Image", "There is no image loaded")).ShowDialog(); this.DialogResult = DialogResult.None; return; } if (!float.TryParse(TXT_HEIGHT.Text, out _CurrentFont._originalSize)) { (new ErrorForm("Font Parse Error", "Unable to parse the original font size")).ShowDialog(); this.DialogResult = DialogResult.None; return; } if (_CurrentFont._originalSize > _CurrentFont._Image_image.Height) { (new ErrorForm("Hieght Error", "The Character Height you have entered is larger than the height of the entire Font Image. Please correct this.")).ShowDialog(); this.DialogResult = DialogResult.None; return; } if (_CurrentFont._Image_image.Height % _CurrentFont._originalSize != 0) { (new ErrorForm("Hieght Error", "The Character Height you have entered is not a multiple of the Font Image total height. Please correct this.")).ShowDialog(); this.DialogResult = DialogResult.None; return; } BusyDoingCrapForm _Busy = new BusyDoingCrapForm(global::FCC_Uber_MDX_Configurator.Properties.Resources.LoadingSwirlySmaller, (int)(_CurrentFont._Image_image.Width * ((int)(_CurrentFont._Image_image.Height / _CurrentFont._originalSize))), false); try { _CurrentFont._charList.Clear(); UpdateListView(); _Busy.Show(); _Busy.TopMost = true; _CurrentFont.MyFastBitmap = new FastBitmap(_CurrentFont.FontBitmapCopy); int x1 = 0; int x2 = 0; int y1 = 0; int y2 = 0; float minSpaceBetweenCharacters = _CurrentFont._originalSize / 5.0f; Color readColour; Color CompareColour = Color.FromArgb(0, 0, 0, 0); CompareColour = _CurrentFont.MyFastBitmap.GetPixel(0, 0); CURR_TOTAL.Text = "Characters Found: 0"; CURR_TOTAL.Update(); for (int row = 0; row < (_CurrentFont._Image_image.Height); row += (int)_CurrentFont._originalSize) { bool lastColumnWasEmpty = true; bool thisColumnIsEmpty = true; for (int i = 0; i < _CurrentFont._Image_image.Width; i++) { if (_Busy != null) { _Busy.UpdateBar((int)(i * (row / _CurrentFont._originalSize + 1))); } for (int j = row; j < row + _CurrentFont._originalSize; j++) { LBL_ANALYZING.Text = "Analyzing: [" + i + "," + j + "]"; LBL_ANALYZING.Update(); //readColour = _CurrentFont._Image_image.GetPixel(i, j); readColour = _CurrentFont.MyFastBitmap.GetPixel(i, j); if (readColour != CompareColour) { thisColumnIsEmpty = false; break; } } if (lastColumnWasEmpty && !thisColumnIsEmpty) { //Beginning of a character x1 = i; y1 = row; y2 = row + (int)_CurrentFont._originalSize; } else if (!lastColumnWasEmpty && thisColumnIsEmpty) { //end of character x2 = i; _CurrentFont._charList.Add(new Character(x1, y1, x2, y2)); CURR_TOTAL.Text = "Characters Found: " + _CurrentFont._charList.Count; CURR_TOTAL.Update(); _CurrentCharacterIndex = _CurrentFont._charList.Count - 1; UpdateCharacterArea(); x1 = 0; x2 = 0; y1 = 0; y2 = 0; } lastColumnWasEmpty = thisColumnIsEmpty; thisColumnIsEmpty = true; } } _CurrentFont.MyFastBitmap.Release(); if (_CurrentFont._charList.Count == 0) { (new ErrorForm("No Characters Found", "There have been no characters parsed. Please try with a different image")).ShowDialog(); this.DialogResult = DialogResult.None; UpdateCharacterArea(); KillDaBusyForm(_Busy); return; } _CurrentCharacterIndex = 0; UpdateListView(); KillDaBusyForm(_Busy); UpdateCharacterArea(); } catch (Exception e) { (new ErrorForm("Analytical Error", "There was an unknown error parsing this Font. Please try again...")).ShowDialog(); this.DialogResult = DialogResult.None; KillDaBusyForm(_Busy); return; } } private void KillDaBusyForm(BusyDoingCrapForm _b) { if (_b != null) { _b.Close(); } return; } private bool SaveFont() { if (!SaveCurrentInfo()) { return false; } for (int i = 0; i < _CurrentFont._charList.Count; i++) { if (_CurrentFont._charList[i]._value < 0) { (new ErrorForm("Character Error", "Not All Characters have a value associated with them. (" + (i + 1) + ")")).ShowDialog(); return false; } } TextInputForm _TIF = new TextInputForm("Font Title", _CurrentFont._name, false); if (_TIF.ShowDialog() == DialogResult.OK) { string _imageFileNameOnly = _CurrentFont._Image_path; if (_imageFileNameOnly.Contains("\\")) { _imageFileNameOnly = ((string[])_imageFileNameOnly.Split(new char[] { '\\' }))[((string[])_imageFileNameOnly.Split(new char[] { '\\' })).Length - 1]; } if (!File.Exists(_CurrentFont._Image_path)) { return false; } if (!Directory.Exists(GlobalStaticClass.FONT_DIRECTORY)) { Directory.CreateDirectory(GlobalStaticClass.FONT_DIRECTORY); } File.Copy(_CurrentFont._Image_path, GlobalStaticClass.FONT_DIRECTORY + "\\" + _imageFileNameOnly, true); string totalString = ParseXML(); FileStream FSUno = new FileStream(GlobalStaticClass.FONT_DIRECTORY + "\\" + _TIF._returnText + ".xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter SW_Font = new StreamWriter(FSUno); SW_Font.Write(totalString); SW_Font.Close(); FSUno.Close(); return true; } return false; } public string ParseXML() { string _imageFileNameOnly = _CurrentFont._Image_path; if (_imageFileNameOnly.Contains("\\")) { _imageFileNameOnly = ((string[])_imageFileNameOnly.Split(new char[] { '\\' }))[((string[])_imageFileNameOnly.Split(new char[] { '\\' })).Length - 1]; } if (!File.Exists(_CurrentFont._Image_path)) { return ""; } string totalString = "\r\n"; totalString += "\r\n"; foreach (Character CurrentFusionCharacter in _CurrentFont._charList) { string val = CurrentFusionCharacter._value.ToString(); if (CurrentFusionCharacter._value < 0) { val = "???"; } totalString += " \r\n"; } totalString += ""; return totalString; } #region Verify Text Field is Valid private void Leave_VerifyTXTIsNotEmpty(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; if (_senderBox.Text == "") { ErrorForm _tempErrorForm = new ErrorForm(_senderBox.Name, "The value you entered is not valid"); _tempErrorForm.ShowDialog(); _senderBox.Focus(); } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Unknown Error", "There was an unexpected untraceable error caught in the application. If you can reproduce this error, please let me know at FusionControlCentre@gmail.com"); _tempErrorForm.ShowDialog(); } } #endregion #region Verify a Number is entered in TextBox public void Leave_VerifyTXTIsValid(object sender, EventArgs e) { try { TextBox _senderBox = (TextBox)sender; int _tempInt; if (!int.TryParse(_senderBox.Text, out _tempInt)) { ErrorForm _tempErrorForm = new ErrorForm(_senderBox.Name, "The value you entered is not valid"); _tempErrorForm.ShowDialog(); _senderBox.Focus(); } } catch (Exception) { ErrorForm _tempErrorForm = new ErrorForm("Unknown Error", "There was an unexpected untraceable error caught in the application. If you can reproduce this error, please let me know at FusionControlCentre@gmail.com"); _tempErrorForm.ShowDialog(); } } #endregion #region Verify Textboxes Only get Number Inputs private void KeyDown_IsANumber(object sender, KeyEventArgs e) { if (!char.IsDigit((char)e.KeyValue) && e.KeyData != Keys.Back && e.KeyData != Keys.Left && e.KeyData != Keys.Right && e.KeyData != Keys.Decimal && e.KeyValue != 190 && !e.KeyCode.Equals(Keys.NumPad0) && !e.KeyCode.Equals(Keys.NumPad1) && !e.KeyCode.Equals(Keys.NumPad2) && !e.KeyCode.Equals(Keys.NumPad3) && !e.KeyCode.Equals(Keys.NumPad4) && !e.KeyCode.Equals(Keys.NumPad5) && !e.KeyCode.Equals(Keys.NumPad6) && !e.KeyCode.Equals(Keys.NumPad7) && !e.KeyCode.Equals(Keys.NumPad8) && !e.KeyCode.Equals(Keys.NumPad9)) { e.SuppressKeyPress = true; } return; } #endregion private void BTN_SAVE_Click(object sender, EventArgs e) { if (_CurrentFont != null && _CurrentFont._Image_image != null && _CurrentFont._charList.Count > 0) { for (int i = 0; i < _CurrentFont._charList.Count; i++) { if (_CurrentFont._charList[i]._value < 0) { this.DialogResult = DialogResult.None; (new ErrorForm("Incomplete", "This font does not have values defined for all characters. Cannot complete the save")).ShowDialog(); return; } } bool suc = SaveFont(); if (suc) { (new FinishedSavingForm()).Show(); } } else { this.DialogResult = DialogResult.None; (new ErrorForm("Incomplete", "This font does not have values defined for all characters. Cannot complete the save")).ShowDialog(); return; } } private void BTN_ANALYZE_Click(object sender, EventArgs e) { AnalizeFontImage(); UpdateCharacterArea(); this.DialogResult = DialogResult.None; } private void TSB_NINJA_Click(object sender, EventArgs e) { } private void BTN_PREVIOUS_Click(object sender, EventArgs e) { SaveCurrentInfo(); _CurrentCharacterIndex--; if (_CurrentCharacterIndex < 0) { _CurrentCharacterIndex = 0; } UpdateListView(); UpdateCharacterArea(); } private void UpdateListView() { /* if (_CurrentFont._charList.Count == LIST_CHARACTERS.Items.Count) { for (int i = 0; i < _CurrentFont._charList.Count; i++) { LIST_CHARACTERS.Items[0] = ((char)_CurrentFont._charList[i]._value).ToString(); } } else { */ LIST_CHARACTERS.Items.Clear(); for (int i = 0; i < _CurrentFont._charList.Count; i++) { if (_CurrentFont._charList[i]._value < 0) { LIST_CHARACTERS.Items.Add((i + 1).ToString() + "???"); } else { LIST_CHARACTERS.Items.Add(((char)_CurrentFont._charList[i]._value).ToString()); } } //} } private void BTN_DELETE_Click(object sender, EventArgs e) { if (_CurrentFont._charList.Count > _CurrentCharacterIndex) { _CurrentFont._charList.RemoveAt(_CurrentCharacterIndex); _CurrentCharacterIndex--; if (_CurrentCharacterIndex < 0) { _CurrentCharacterIndex = 0; } UpdateListView(); UpdateCharacterArea(); } } private void BTN_NEXT_Click(object sender, EventArgs e) { SaveCurrentInfo(); _CurrentCharacterIndex++; if (_CurrentCharacterIndex >= _CurrentFont._charList.Count) { _CurrentCharacterIndex = _CurrentFont._charList.Count - 1; } UpdateListView(); UpdateCharacterArea(); } private void LIST_CHARACTERS_SelectedIndexChanged(object sender, EventArgs e) { int i = ((ListBox)sender).SelectedIndex; Console.WriteLine(i.ToString()); GoToNewIndex(i); TXT_VALUE.Focus(); } private void TXT_VALUE_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter || e.KeyData == Keys.Return) { if (SaveCurrentInfo()) { if (_CurrentCharacterIndex >= 0) { _CurrentCharacterIndex++; if (_CurrentCharacterIndex >= _CurrentFont._charList.Count) { _CurrentCharacterIndex = _CurrentFont._charList.Count - 1; } } UpdateListView(); UpdateCharacterArea(); } } } private void TSB_OPENFOLDER_Click(object sender, EventArgs e) { if (OpenTextConfigDialog.ShowDialog() == DialogResult.OK) { OpenFontFile(OpenTextConfigDialog.FileName); } } private void OpenFontFile(string _fileName) { _RotateColours = new List(new Color[] { Color.Black, Color.White, Color.Blue, Color.Red, Color.Yellow }); _RotateColours_i = 0; _CurrentFont = new FusionFont(); _CurrentCharacterIndex = -1; if (File.Exists(_fileName)) { if (_fileName.Contains("\\")) { FileStream _fs1 = new FileStream(_fileName, FileMode.Open, FileAccess.Read); StreamReader _sr = new StreamReader(_fs1); string readInXML = _sr.ReadToEnd(); _sr.Close(); _fs1.Close(); try { System.Xml.XmlDocument _doc = new System.Xml.XmlDocument(); _doc.LoadXml(readInXML); System.Xml.XmlNode _rootFont = _doc.SelectSingleNode("font"); if (_rootFont != null) { foreach (XmlAttribute _a in _rootFont.Attributes) { if (_a.Name.ToLower() == "fontimage") { string _base = _fileName.Substring(0, _fileName.LastIndexOf('\\')); _CurrentFont._Image_path = _base + "\\" + _a.Value; } } if (File.Exists(_CurrentFont._Image_path)) { _CurrentFont._Image_image = new Bitmap(Image.FromFile(_CurrentFont._Image_path)); _CurrentFont.FontBitmapCopy = (System.Drawing.Bitmap)_CurrentFont._Image_image.Clone(); char[] split_params = { '\\', '/' }; string[] splitsss = _CurrentFont._Image_path.Split(split_params); _CurrentFont._name = splitsss[splitsss.Length - 1]; if (_CurrentFont._name.Contains(".")) { _CurrentFont._name = _CurrentFont._name.Substring(0, _CurrentFont._name.LastIndexOf('.')); } TXT_Name.Text = _CurrentFont._name; PICT_FULLFONT.BackgroundImage = _CurrentFont._Image_image; UpdateCharacterArea(); float _origH = 0; foreach (XmlNode FontCharNode in _rootFont.ChildNodes) { if (FontCharNode.Name.ToLower() == "char") { int x1 = -1, x2 = -1, y1 = -1, y2 = -1; int FF_value = -1; int FF_Offset_left = 0, FF_Offset_right = 0, FF_Offset_top = 0, FF_Offset_bottom = 0; foreach (XmlAttribute FF_CharAttribute in FontCharNode.Attributes) { switch (FF_CharAttribute.Name.ToLower()) { case "location_topleft": { char[] rect_splitter = { ',' }; string[] rect_parse = FF_CharAttribute.Value.Split(rect_splitter); int.TryParse(rect_parse[0], out x1); int.TryParse(rect_parse[1], out y1); } break; case "location_bottomright": { char[] rect_splitter = { ',' }; string[] rect_parse = FF_CharAttribute.Value.Split(rect_splitter); int.TryParse(rect_parse[0], out x2); int.TryParse(rect_parse[1], out y2); } break; case "value": { int.TryParse(FF_CharAttribute.Value, out FF_value); } break; case "offsets": { char[] rect_splitter = { ',' }; string[] rect_parse = FF_CharAttribute.Value.Split(rect_splitter); float FFx1 = 0.0f, FFx2 = 0.0f, FFy1 = 0.0f, FFy2 = 0.0f; float.TryParse(rect_parse[0], out FFx1); float.TryParse(rect_parse[1], out FFx2); float.TryParse(rect_parse[2], out FFy1); float.TryParse(rect_parse[3], out FFy2); FF_Offset_left = (int)FFx1; FF_Offset_right = (int)FFx2; FF_Offset_top = (int)FFy1; FF_Offset_bottom = (int)FFy2; } break; default: //Error Or Unknown break; } } if (x1 >= 0 && y1 >= 0 && x2 - x1 > 0 && y2 - y1 > 0 && FF_value > 0) { Character _c = new Character(x1, y1, x2, y2); _c._offset_left = FF_Offset_left; _c._offset_right = FF_Offset_right; _c._offset_top = FF_Offset_top; _c._offset_bottom = FF_Offset_bottom; _c._value = FF_value; _origH += (y2 - y1); _CurrentFont._charList.Add(_c); } } } if (_CurrentFont._charList.Count > 0) { _origH /= (float)_CurrentFont._charList.Count; _CurrentFont._originalSize = _origH; TXT_HEIGHT.Text = _origH.ToString(); _CurrentCharacterIndex = 0; UpdateListView(); this.DialogResult = DialogResult.None; } } else { (new ErrorForm("Opening Error", "Error Opening Font File Image. File does not exist")).ShowDialog(); return; } } } catch (Exception) { } } } else { (new ErrorForm("Opening Error", "Error Opening Font File. File does not exist")).ShowDialog(); return; } UpdateCharacterArea(); } } public class FusionFont { public List _charList = new List(); public string _name = ""; public float _originalSize = 12.0f; public string _Image_path = ""; public Bitmap _Image_image = null; public Bitmap FontBitmapCopy = null; public Bitmap DisplayCharacter = new Bitmap(240, 180); public Graphics DisplayCharacterGraphics = null; public FastBitmap MyFastBitmap = null; } public class Character { public int _loc_TopLeft_x, _loc_TopLeft_y, _loc_BottomRight_x, _loc_BottomRight_y; public int _offset_left, _offset_right, _offset_top, _offset_bottom; public int _value = -1; public Character(int IN_loc_TopLeft_x, int IN_loc_TopLeft_y, int IN__loc_BottomRight_x, int IN__loc_BottomRight_y) { _loc_TopLeft_x = IN_loc_TopLeft_x; _loc_TopLeft_y = IN_loc_TopLeft_y; _loc_BottomRight_x = IN__loc_BottomRight_x; _loc_BottomRight_y = IN__loc_BottomRight_y; } } public unsafe class FastBitmap { public struct PixelData { public byte alpha; public byte blue; public byte green; public byte red; } Bitmap Subject; int SubjectWidth; BitmapData bitmapData = null; Byte* pBase = null; public FastBitmap(Bitmap SubjectBitmap) { this.Subject = SubjectBitmap; try { LockBitmap(); } catch (Exception ex) { throw ex; } } public void Release() { try { UnlockBitmap(); } catch (Exception ex) { throw ex; } } public Bitmap Bitmap { get { return Subject; } } public void SetPixel(int X, int Y, Color Colour) { try { PixelData* p = PixelAt(X, Y); p->red = Colour.R; p->green = Colour.G; p->blue = Colour.B; p->alpha = Colour.A; } catch (AccessViolationException ave) { throw (ave); } catch (Exception ex) { throw ex; } } public Color GetPixel(int X, int Y) { try { PixelData* p = PixelAt(X, Y); return Color.FromArgb((int)p->alpha, (int)p->red, (int)p->green, (int)p->blue); } catch (AccessViolationException ave) { throw (ave); } catch (Exception ex) { throw ex; } } private void LockBitmap() { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF boundsF = Subject.GetBounds(ref unit); Rectangle bounds = new Rectangle((int)boundsF.X, (int)boundsF.Y, (int)boundsF.Width, (int)boundsF.Height); SubjectWidth = (int)boundsF.Width * sizeof(PixelData); if (SubjectWidth % 4 != 0) { SubjectWidth = 4 * (SubjectWidth / 4 + 1); } bitmapData = Subject.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); pBase = (Byte*)bitmapData.Scan0.ToPointer(); } private PixelData* PixelAt(int x, int y) { return (PixelData*)(pBase + y * SubjectWidth + x * sizeof(PixelData)); } private void UnlockBitmap() { Subject.UnlockBits(bitmapData); bitmapData = null; pBase = null; } } }