private void saveAsBitmap(string filename) { int y = 0; Rectangle rect = new Rectangle(0, 0, fontSettings.BlockWidth, fontSettings.BlockHeight); using (Bitmap bmp = new Bitmap(fontSettings.BlockWidth, fontSettings.BlockHeight)) { using (Graphics g = Graphics.FromImage(bmp)) { using (Bitmap bmpOutput = new Bitmap(fontSettings.BlockWidth, fontSettings.BlockHeight * fontSettings.Chars.Length)) { using (Graphics grpOutput = Graphics.FromImage(bmpOutput)) { // output chars data one by one foreach (char c in fontSettings.Chars) { FontDrawExtend.DrawChar(g, fontSettings, c); grpOutput.DrawImage(bmp, 0, y, rect, GraphicsUnit.Pixel); y += fontSettings.BlockHeight; } } bmpOutput.Save(filename, ImageFormat.Bmp); } } } Misc.MsgInf(Properties.Resources.Inf_bmpExpdortComplete); }
/// <summary> /// Show Single Char's Zoomed Large Image /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pictureBoxPage_MouseClick(object sender, MouseEventArgs e) { // if the content never showed, do nothing if (fontSettings == null) { return; } // get index of char which current clicked int indexOfChar = FontDrawExtend.getCurrentCharIndex(e.X, e.Y, vScrollBar1.Value, fontSettings); // if index outof bound, do nothing if (indexOfChar == -1) { return; } // release previous image resource if (pictureBoxZoom.Image != null) { pictureBoxZoom.Image.Dispose(); } // redraw and show it using (Bitmap bmp = FontDrawExtend.DrawChar(fontSettings, indexOfChar)) { pictureBoxZoom.Image = FontDrawExtend.ZoomBmp(bmp, pictureBoxZoom.ClientSize, fontSettings); pictureBoxZoom.Refresh(); } // display char information labelCurrent.Text = "Char Unicode: 0x" + indexOfChar.ToString("X"); }
/// <summary> /// Show char bitmap list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButtonView_Click(object sender, EventArgs e) { // required check Control[] controls = new Control[] { listBoxSystemFont, listBoxSize, richTextBoxCharInput, textBoxForecolor, textBoxBackgroundColor }; string[] messages = new string[] { Properties.Resources.Err_font_required, Properties.Resources.Err_size_required, Properties.Resources.Err_char_required, Properties.Resources.Err_forecolor_required, Properties.Resources.Err_backcolor_required }; if (!Misc.isFilled(controls, messages)) { return; } // if invalidation do nothing if (!getSettings()) { return; } // set scrollbar parameters vScrollBar1.Maximum = FontDrawExtend.getScrollMaximum(pictureBoxPage.ClientSize.Height, fontSettings); vScrollBar1.LargeChange = FontDrawExtend.getScrollLargeChange(fontSettings, pictureBoxPage.ClientSize.Height); vScrollBar1.Tag = 1; // prevent redraw vScrollBar1.Value = 0; vScrollBar1.Tag = null; // draw char list vScrollBar1_Scroll(vScrollBar1, new ScrollEventArgs(ScrollEventType.First, 0)); }
/// <summary> /// Scroll content view(picturebox's image) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void vScrollBar1_Scroll(object sender, ScrollEventArgs e) { if (vScrollBar1.Tag != null) { return; // set tag values for prevent redraw } if (fontSettings == null) { return; } vScrollBar1.Tag = 1; FontDrawExtend.DrawContentImage(graphicsOfContent, pictureBoxPage.ClientSize.Height, fontSettings, e.NewValue); pictureBoxPage.Refresh(); vScrollBar1.Tag = null; }
/// <summary> /// Export Font Data /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonSave_Click(object sender, EventArgs e) { // check output settings COLOR_MODE colorMode = radioButton8.Checked ? COLOR_MODE.MONO : radioButton9.Checked ? COLOR_MODE.GRAY4BITS : radioButton10.Checked ? COLOR_MODE.RGB565 : radioButton11.Checked ? COLOR_MODE.RGB565P : COLOR_MODE.UNKONOWN; if (colorMode == COLOR_MODE.UNKONOWN) { Misc.MsgInf(Properties.Resources.Inf_colorMode_required); return; } SCAN_MODE scanMode = radioButtonRow1.Checked ? SCAN_MODE.ROW_SCAN : radioButtonColumn1.Checked ? SCAN_MODE.COLUMN_SCAN : SCAN_MODE.UNKOWN; if (scanMode == SCAN_MODE.UNKOWN) { Misc.MsgInf(Properties.Resources.Inf_scanMode_required); return; } string arrayName = textBoxArrayName.Text; if (arrayName.Length == 0) { Misc.MsgInf(Properties.Resources.Inf_arrayName_required); return; } // if content never showed, check input parameters, and show it if (fontSettings == null) { this.toolStripButtonView_Click(null, null); if (fontSettings == null) { return; } } // user canceled if (this.saveFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } if (radioButton13.Checked) { saveAsBitmap(saveFileDialog1.FileName); return; } // get stream for write font data List <byte> bytes; int iNewLinePosition = Properties.Settings.Default.NewLinePositionOfExport; int pos = 1; Size size = new Size(); StringBuilder sb = new StringBuilder(); using (Stream ss = this.saveFileDialog1.OpenFile()) { using (StreamWriter sw = new System.IO.StreamWriter(ss)) { if (!fontSettings.AutoFixWidth) { sw.WriteLine(string.Format(@"const unsigned char {0} = {{", arrayName)); } using (Bitmap bmp = new Bitmap(fontSettings.BlockWidth, fontSettings.BlockHeight)) { using (Graphics g = Graphics.FromImage(bmp)) { // output chars data one by one foreach (char c in fontSettings.Chars) { FontDrawExtend.DrawChar(g, fontSettings, c); bytes = FontDrawExtend.getCharFontData(bmp, colorMode, scanMode, fontSettings, out size); if (fontSettings.AutoFixWidth) { sw.WriteLine(@" // char ""{0}"" const unsigned char {1}_{2:X2}_dat[] = {{", c, arrayName, (int)c); pos = 1; } foreach (byte b in bytes) { sw.Write("0x{0:X2},", b); if (iNewLinePosition > 0 && pos == iNewLinePosition) { sw.Write(Environment.NewLine); pos = 0; } pos++; } if (fontSettings.AutoFixWidth) { sw.WriteLine("};"); sw.WriteLine(@"mos_font_data_t {0}_{1:X2} = {{ {2},{3}, &{4}_{5:X2}_dat[0]}};", arrayName, (int)c, size.Width, size.Height, arrayName, (int)c); sb.Append(String.Format("&{0}_{1:X2},", arrayName, (int)c)); } } } } if (fontSettings.AutoFixWidth) { sw.WriteLine(@" // data list mos_font_data_t* {0}[] = {{{1}}};", arrayName, sb.ToString()); } else { sw.WriteLine("}"); } } } // ask for open export file if (MessageBox.Show(Properties.Resources.Inf_openFileConfirm, Properties.Resources.Caption_exportMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Process.Start(this.saveFileDialog1.FileName); } }