183 lines
6.5 KiB
C#
183 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace McBitFont {
|
|
public partial class New : Form {
|
|
|
|
public class EncodingItem {
|
|
public string Text { get; set; }
|
|
public int Code { get; set; }
|
|
|
|
public EncodingItem(int code, string text) {
|
|
Code = code;
|
|
Text = text;
|
|
}
|
|
|
|
public override string ToString() {
|
|
return Text;
|
|
}
|
|
}
|
|
|
|
private MainForm mainForm;
|
|
|
|
|
|
public New(MainForm form) {
|
|
InitializeComponent();
|
|
mainForm = form;
|
|
this.Width = 300; this.Height = 250;
|
|
}
|
|
|
|
private void cbSingle_CheckedChanged(object sender, EventArgs e) {
|
|
bool c = !cbSingle.Checked;
|
|
bool f = cbFontBased.Checked;
|
|
cbNotPrintable.Enabled = c;
|
|
cbLatin.Enabled = c;
|
|
cbExtended.Enabled = c;
|
|
cbFontBased.Enabled = c;
|
|
rbMono.Enabled = c;
|
|
rbVar.Enabled = c;
|
|
pnlFont.Visible = c && f;
|
|
this.Width = c && f ? 500 : 300;
|
|
}
|
|
|
|
private void New_Load(object sender, EventArgs e) {
|
|
toolTip1.SetToolTip(nudNewX, "Frame Width;\nCharacter width;\nDefault character width for Variable width fonts");
|
|
toolTip1.SetToolTip(nudNewY, "Frame Height;\nCharacter height");
|
|
toolTip1.SetToolTip(rbMono, "Monospaced font");
|
|
toolTip1.SetToolTip(rbVar, "Variable width font");
|
|
toolTip1.SetToolTip(cbSingle, "Create one single frame");
|
|
toolTip1.SetToolTip(cbNotPrintable, "Add not printable characters with codes 0 - 31");
|
|
toolTip1.SetToolTip(cbLatin, "Add Latin characters with codes 32 - 127");
|
|
toolTip1.SetToolTip(cbExtended, "Add Extended characters with codes 128 - 255");
|
|
|
|
cbEncoding.Items.Clear();
|
|
cbEncoding.Items.Add(new EncodingItem(1250, "Central European"));
|
|
cbEncoding.Items.Add(new EncodingItem(1251, "Cyrillic"));
|
|
cbEncoding.Items.Add(new EncodingItem(1252, "Western European"));
|
|
cbEncoding.Items.Add(new EncodingItem(1253, "Greek"));
|
|
cbEncoding.Items.Add(new EncodingItem(1254, "Turkish"));
|
|
cbEncoding.Items.Add(new EncodingItem(1255, "Hebrew"));
|
|
cbEncoding.Items.Add(new EncodingItem(1256, "Arabic"));
|
|
cbEncoding.Items.Add(new EncodingItem(1257, "Baltic"));
|
|
cbEncoding.SelectedIndex = 1;
|
|
|
|
lblFont.Text = dlgFont.Font.Name + " " + dlgFont.Font.Size.ToString();
|
|
updateChars();
|
|
}
|
|
|
|
private void updateChars() {
|
|
int neww, newh;
|
|
const int pbw = 100;
|
|
const int pbh = 124;
|
|
int w = (int)nudNewX.Value;
|
|
int h = (int)nudNewY.Value;
|
|
int difw = pbw - w;
|
|
int difh = pbh - h;
|
|
string[] chars = { "A", "a" };
|
|
PictureBox[] pbs = { pbChar1, pbChar2 };
|
|
|
|
if (difw > 0) {
|
|
if (difh > 0) {
|
|
//not wider, not taller
|
|
if (difw < difh) {
|
|
neww = pbw;
|
|
newh = h * pbw / w;
|
|
} else {
|
|
newh = pbh;
|
|
neww = w * pbh / h;
|
|
}
|
|
} else {
|
|
// not wider, taller
|
|
newh = pbh;
|
|
neww = w * pbh / h;
|
|
}
|
|
} else {
|
|
if (difh > 0) {
|
|
//wider, not taller
|
|
neww = pbw;
|
|
newh = h * pbw / w;
|
|
} else {
|
|
// wider, taller
|
|
if (difw > difh) {
|
|
neww = pbw;
|
|
newh = h * pbw / w;
|
|
} else {
|
|
newh = pbh;
|
|
neww = w * pbh / h;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Bitmap bmp, result;
|
|
Graphics g;
|
|
chars[0] = mainForm.decodeSymbol((int)nudChar1.Value);
|
|
chars[1] = mainForm.decodeSymbol((int)nudChar2.Value);
|
|
for (int i = 0; i < 2; i++) {
|
|
bmp = new Bitmap((int)nudNewX.Value, (int)nudNewY.Value);
|
|
g = Graphics.FromImage(bmp);
|
|
g.Clear(Color.White);
|
|
g.SmoothingMode = SmoothingMode.None;
|
|
g.InterpolationMode = InterpolationMode.NearestNeighbor;
|
|
g.PixelOffsetMode = PixelOffsetMode.Half;
|
|
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
|
|
g.DrawString(chars[i], dlgFont.Font, Brushes.Black, (int)nudShiftX.Value, (int)nudShiftY.Value);
|
|
g.Flush();
|
|
|
|
result = new Bitmap(neww, newh);
|
|
using (Graphics gr = Graphics.FromImage(result)) {
|
|
gr.InterpolationMode = InterpolationMode.NearestNeighbor;
|
|
gr.PixelOffsetMode = PixelOffsetMode.Half;
|
|
gr.DrawImage(bmp, 0, 0, neww, newh);
|
|
}
|
|
pbs[i].Image = result;
|
|
}
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e) {
|
|
DialogResult = DialogResult.Cancel;
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e) {
|
|
DialogResult= DialogResult.OK;
|
|
}
|
|
|
|
private void nudFocus(object sender, EventArgs e) {
|
|
NumericUpDown nud = (NumericUpDown)sender;
|
|
|
|
nud.Select(0, nud.Text.Length);
|
|
}
|
|
|
|
private void cbExtended_CheckedChanged(object sender, EventArgs e) {
|
|
cbEncoding.Enabled = cbExtended.Checked;
|
|
}
|
|
|
|
private void cbFontBased_CheckedChanged(object sender, EventArgs e) {
|
|
bool c = !cbSingle.Checked;
|
|
bool f = cbFontBased.Checked;
|
|
pnlFont.Visible = c && f;
|
|
this.Width = c && f ? 500 : 300;
|
|
}
|
|
|
|
private void btnFont_Click(object sender, EventArgs e) {
|
|
if (dlgFont.ShowDialog() == DialogResult.OK) {
|
|
lblFont.Text = dlgFont.Font.Name + " " + dlgFont.Font.Size.ToString();
|
|
updateChars();
|
|
}
|
|
}
|
|
|
|
private void nudNewX_ValueChanged(object sender, EventArgs e) {
|
|
updateChars();
|
|
}
|
|
}
|
|
}
|