public int MeasureStringInFont(GenericCharMap charMap, string s, PatcherLib.Datatypes.FFTFont font) { var widths = MeasureEachLineInFont(charMap, s, font); int width = int.MinValue; widths.ForEach(w => width = Math.Max(width, w)); return(width); }
/// <summary> /// Binds this editor to a list of strings. /// </summary> public void BindTo(IList <string> names, IFile file, int section) { ignoreChanges = true; SuspendLayout(); int count = file.SectionLengths[section]; List <string> ourNames = new List <string>(names); for (int i = names.Count; i < count; i++) { ourNames.Add(string.Empty); } IList <int> disallowed = (file is ISerializableFile) ? ((ISerializableFile)file).Layout.DisallowedEntries[section] : null; DataGridViewRow[] rows = new DataGridViewRow[count]; dataGridView.SuspendLayout(); #if MEASURESTRINGS font = file.Context == PatcherLib.Datatypes.Context.US_PSP ? PSPResources.PSPFont : PSXResources.PSXFont; #endif boundFile = file; for (int i = 0; i < count; i++) { DataGridViewRow row = new DataGridViewRow(); #if MEASURESTRINGS row.CreateCells(dataGridView, i, ourNames[i], GetWidthColumnString(file[section, i] ?? string.Empty), file[section, i]); #else row.CreateCells(dataGridView, i, ourNames[i], file[section, i]); #endif row.ReadOnly = disallowed != null && disallowed.Count > 0 && disallowed.Contains(i); rows[i] = row; } dataGridView.Rows.Clear(); dataGridView.Rows.AddRange(rows); dataGridView.ResumeLayout(); bool showSeparatorChoices = file is ISerializableFile && (file as ISerializableFile).Layout.AllowedTerminators.Count > 1; separatorComboBox.Visible = showSeparatorChoices; separatorComboBox.Enabled = showSeparatorChoices; separatorLabel.Visible = showSeparatorChoices; if (showSeparatorChoices) { PatcherLib.Datatypes.Set <byte> seps = (file as ISerializableFile).Layout.AllowedTerminators; separatorComboBox.BeginUpdate(); separatorComboBox.Items.Clear(); separatorComboBox.FormatString = "X2"; seps.ForEach(b => separatorComboBox.Items.Add(b)); separatorComboBox.SelectedItem = file.SelectedTerminator; separatorComboBox.EndUpdate(); } boundSection = section; ignoreChanges = false; ResumeLayout(); }
private int MeasureSingleLineInFont(GenericCharMap charMap, string s, PatcherLib.Datatypes.FFTFont font) { IList <UInt32> everyChar = charMap.GetEachEncodedCharacter(s); int sum = 0; foreach (UInt32 c in everyChar) { sum += GetWidthForEncodedCharacter(c, font); } return(sum); }
public IList <int> MeasureEachLineInFont(GenericCharMap charMap, string s, PatcherLib.Datatypes.FFTFont font) { string[] strings = s.Split(new string[] { "{Newline}", "{Close}" }, StringSplitOptions.RemoveEmptyEntries); int[] result = new int[strings.Length]; for (int i = 0; i < strings.Length; i++) { result[i] = strings[i].Length == 0 ? 0 : MeasureSingleLineInFont(charMap, strings[i], font); } return(result.AsReadOnly()); }
private int GetWidthForEncodedCharacter(UInt32 c, PatcherLib.Datatypes.FFTFont font) { if (c == 0xFA) { return(4); } else if (c <= 0xCF) { return(font.Glyphs[(int)c].Width); } else if ((c & 0xFF00) >= 0xD100 && (c & 0xFF00) <= 0xDA00 && (c & 0x00FF) <= 0xCF && ((c & 0xFF00) != 0xDA00 || (c & 0x00FF) <= 0x77)) { return(font.Glyphs[(int)((((c & 0xFF00) >> 8) - 0xD0) * 0xD0 + (c & 0x00FF))].Width); } else { return(0); } }