public static void AddFont(bool isExternal, string customName, string fontNameOrFile, byte[] byteArray = null) { FontData data = new FontData(); // Here lies the soult of the font data :3 data.IsExternal = isExternal; // True if it's an external file else False for system fonts data.CustomName = customName; // a custom name for the font string keyName = fontNameOrFile; if (isExternal) { // Load font and add its raw data to ExternalFontsRaw list if (!fontNameOrFile.Equals(LOAD_FROM_BYTES_FLAG)) { data.fontRawBytes = File.ReadAllBytes(fontNameOrFile); } else { data.fontRawBytes = byteArray; } // ASSIGN MEMORY AND COPY BYTE[] ON THAT MEMORY ADDRESS IntPtr ptrData = Marshal.AllocCoTaskMem(data.fontRawBytes.Length); Marshal.Copy(data.fontRawBytes, 0, ptrData, data.fontRawBytes.Length); // Read the font file data.pfc = new PrivateFontCollection(); data.pfc.AddMemoryFont(ptrData, data.fontRawBytes.Length); // FREE THE "UNSAFE" MEMORY Marshal.FreeCoTaskMem(ptrData); // Check if we already added the same font earlier keyName = data.pfc.Families[0].Name; } if (fontList.ContainsKey(keyName)) { Funcs.Information("This font already exist in the list !"); } else { fontList.Add(keyName, data); } }
private void Btn_remove_lang_Click(object sender, EventArgs e) { if (languagesTable.SelectedCells.Count > 0) { int langID = Funcs.ToInt(languagesTable[grid_id.Index, languagesTable.SelectedCells[0].RowIndex].Value); if (langID == 0) { Funcs.Information("You can't delete the default entry, it is the default text value used when no languages are avaible."); return; } if (Funcs.Question("Are you sure you want to delete this language code ?\nNote that all label objects will lose this language code text value ! ") == DialogResult.Yes) { Objects.RemoveLanguage(Languages.UsedLanguages[langID]); Languages.UsedLanguages.Remove(Languages.UsedLanguages[langID]); LoadLanguages(); } } }
private void Btn_add_lang_Click(object sender, EventArgs e) { StringEditor stringEditor = new StringEditor("Insert a language code :"); if (stringEditor.ShowDialog() == DialogResult.OK) { foreach (string l in Languages.UsedLanguages) { if (l == stringEditor.textBox.Text) { Funcs.Information("You can't add a language twice!"); return; } } } Languages.UsedLanguages.Add(stringEditor.textBox.Text); Objects.AddLanguage(stringEditor.textBox.Text); LoadLanguages(); }
private void Btn_delete_Click(object sender, EventArgs e) { if (fontsTable.SelectedCells.Count > 0) { string fontID = fontsTable[grid_id.Index, fontsTable.SelectedCells[0].RowIndex].Value.ToString(); if (fontID == Config.DEFAULT_FONT) { Funcs.Information("You can't delete the default font, it is used when a font is missing or corrupted."); } else { if (Funcs.Question("Are you sure you want to delete this font ?") == DialogResult.Yes) { Fonts.fontList.Remove(fontID); Objects.DeletedFont(fontID); LoadFonts(); Objects.RenderAll(); } } } }