private void btnOpenFont_Click(object sender, EventArgs e) { var res = ofd.ShowDialog(); if (res == DialogResult.OK) { ziFont = ZiFont.FromFile(ofd.FileName); numChar.Maximum = ziFont.CodePage.CharacterCount - 1; charEditor1.CharImage = ziFont.CharBitmaps.Skip(1).First(); numChar.Value = 1; } }
private void CreateCharacterPreview(ZiFont font) { flowPanel.Controls.Clear(); foreach (var b in font.CharBitmaps.Take(300)) { var p = new PictureBox() { Width = font.CharacterWidth + 2, Height = font.CharacterHeight + 2, Image = b, BorderStyle = BorderStyle.FixedSingle, BackColor = Color.White }; flowPanel.Controls.Add(p); } }
private void btnOpen_Click(object sender, EventArgs e) { var res = ofd.ShowDialog(); if (res == DialogResult.OK) { var zifont = ZiFont.FromFile(ofd.FileName); CreateCharacterPreview(zifont); lblFile.Text = Path.GetFileName(ofd.FileName); lblFontName.Text = zifont.Name; lblCodePage.Text = zifont.CodePage.CodePageIdentifier.ToString(); lblWidth.Text = zifont.CharacterWidth.ToString(); lblHeight.Text = zifont.CharacterHeight.ToString(); lblCharacters.Text = zifont.CodePage.CharacterCount.ToString(); lblFileSize.Text = zifont.FileSize.ToString(); lblFileVersion.Text = zifont.Version.ToString(); //lblBytesPerChar.Text = zifont.BytesPerChar.ToString(); } }
private void CreatePreview() { var codePage = CodePages.GetCodePage(CodePageIdentifier.ISO_8859_1); var fontName = lstFonts.SelectedItem?.ToString() ?? ""; var fontSize = (int)numFontSize.Value; var size = int.Parse(cmbNextionFontSize.Text); var width = size / 2; var height = size; var font = new Font(fontName, fontSize, GraphicsUnit.Pixel); var pPreviews = new List <Bitmap>(); var bLightCoral = new SolidBrush(Color.LightCoral); var bLightGreen = new SolidBrush(Color.LightGreen); var bWhite = new SolidBrush(Color.White); var bBlack = new SolidBrush(Color.Black); foreach (var c in codePage.Characters) { var bPreview = new Bitmap(width, height); using (var gPreview = CreateGraphics(bPreview)) { var sChar = gPreview.MeasureString(c.ToString(), font, new PointF(0, 0), StringFormat.GenericTypographic).ToSize(); if (sChar.Width == 0) { sChar.Width = 1; } var bChar = new Bitmap(sChar.Width, sChar.Height); using (var gChar = CreateGraphics(bChar)) { var sb = PreviewTest.Checked ? bChar.Width > bPreview.Width ? bLightCoral : bLightGreen : PreviewBW.Checked ? bWhite : bBlack; gChar.FillRectangle(sb, 0, 0, sChar.Width, sChar.Height); gChar.DrawString(c.ToString(), font, PreviewWB.Checked ? bWhite : bBlack, (float)numCharOffsetX.Value, (float)numCharOffsetY.Value, StringFormat.GenericTypographic ); } gPreview.FillRectangle(PreviewTest.Checked ? bChar.Width > bPreview.Width ? bLightCoral : bLightGreen : PreviewBW.Checked ? bWhite : bBlack, 0, 0, width, height); if (bChar.Width > bPreview.Width) { gPreview.DrawImage(bChar, 0, 0, width, height); } else { gPreview.DrawImage(bChar, (width / 2) - (bChar.Width / 2), 0, bChar.Width, height); } } pPreviews.Add(bPreview); } panelPreview.SuspendLayout(); panelPreview.Controls.Clear(); panelPreview.BackColor = PreviewTest.Checked ? Color.Transparent : PreviewBW.Checked ? Color.White : Color.Black; panelPreview.Controls.AddRange( pPreviews.Select(x => new PictureBox() { Width = width, Height = height, Image = x, Margin = new Padding(3) }).ToArray()); panelPreview.ResumeLayout(); ziFont = ZiFont.FromCharacterBitmaps(fontName + " " + cmbNextionFontSize.Text, (byte)width, (byte)height, codePage, pPreviews, PreviewWB.Checked); }