private void generateFont() { btnGenerate.Enabled = false; try { if (cbBold.Checked) { m_font.FontStyle = FontStyle.Bold; } else { m_font.FontStyle = FontStyle.Regular; } int num = int.Parse(cbHeight.Text); pictureBoxC.Width = num; pictureBoxC.Height = num; m_font.FontName = cbChinese.Text; GdiFont.InfoGdiFont e_ = new GdiFont.InfoGdiFont(); e_ = GdiFont.GetFontSize( "S".Translate(), m_font.FontName, m_font.FontStyle, pictureBoxC.Width, pictureBoxC.Height, (float)Utility.GetInt(cbHeight.Text), true, pictureBox ); if (e_.FontSize != 0f) { m_font.FontSize = e_.FontSize; m_font.Xpi = ((pictureBoxC.Width - e_.Width) / 2) - e_.Xpi; m_font.Ypi = ((pictureBoxC.Height - e_.Height) / 2) - e_.Ypi; Font font = new Font(m_font.FontName, m_font.FontSize, m_font.FontStyle); m_image = new Bitmap(pictureBoxC.Width, pictureBoxC.Height); Graphics graphics = Graphics.FromImage(m_image); graphics.Clear(Color.FromArgb(0, 0, 0)); graphics.DrawString("S".Translate(), font, Brushes.Red, (PointF) new Point(m_font.Xpi, m_font.Ypi)); pictureBoxC.Image = m_image; btnGenerate.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void refreshChars() { btnGenerate.Enabled = false; try { if (cbBold.Checked) { m_char.FontStyle = FontStyle.Bold; } else { m_char.FontStyle = FontStyle.Regular; } int num = int.Parse(cbHeight.Text); pictureBoxL.Width = num / 2; pictureBoxL.Height = num; m_char.FontName = cbLetter.Text; showFont = GdiFont.GetFontSize( "8", m_char.FontName, m_char.FontStyle, pictureBoxL.Width, pictureBoxL.Height, (float)Utility.GetInt(cbHeight.Text), true, pictureBox ); if (showFont.FontSize != 0f) { m_char.FontSize = showFont.FontSize; m_char.Xpi = ((pictureBoxL.Width - showFont.Width) / 2) - showFont.Xpi; m_char.Ypi = ((pictureBoxL.Height - showFont.Height) / 2) - showFont.Ypi; Font font = new Font(m_char.FontName, m_char.FontSize, m_char.FontStyle); m_image = new Bitmap(pictureBoxL.Width, pictureBoxL.Height); adjustmentFont(m_image, m_char, Encoding.GetEncoding(cbEncode.Text), (byte)'X'); pictureBoxL.Image = m_image; btnGenerate.Enabled = true; } } catch { } }
private bool adjustmentFont(Bitmap image, FontDescriptor zipos, Encoding ec, byte ascii) { Graphics graphics = null; try { bool flag = true; int num = 0; byte[] bytes = new byte[] { ascii }; string s = ec.GetString(bytes, 0, 1); FontDescriptor fontDesc = new FontDescriptor(); fontDesc = zipos; int width = image.Width; int height = image.Height; if (width != height / 2) { width = height / 2; } Graphics.FromImage(image).Clear(Color.FromArgb(0, 0, 0)); Bitmap bmi = new Bitmap(width * 3, height * 2); using (graphics = Graphics.FromImage(bmi)) { if (s == "w") { s = "w"; } if (s != "" && s != " ") { while (flag) { int num7; Graphics graphics2; int num4 = 0; fontDesc.Ypi--; while (num4 == 0) { fontDesc.Ypi++; Font font = new Font(fontDesc.FontName, fontDesc.FontSize, fontDesc.FontStyle); graphics.Clear(Color.FromArgb(0, 0, 0)); graphics.DrawString(s, font, Brushes.Red, (PointF) new Point(0, fontDesc.Ypi)); num4 = GdiFont.GetYFree(bmi); } Bitmap bitmap2 = new Bitmap(bmi.Width, height); int height2 = bmi.Height - GdiFont.GetY2Free(bmi); if (height2 > height) { Graphics.FromImage(bitmap2).DrawImage( bmi, new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), new Rectangle(0, 0, bitmap2.Width, height2), GraphicsUnit.Pixel ); } else { Graphics.FromImage(bitmap2).DrawImage( bmi, new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), GraphicsUnit.Pixel ); } int bmwidth = GdiFont.GetImageWidth(bitmap2); if ((width > 24 && bmwidth < width) || (width <= 24 && bmwidth <= width + 1)) { num4 = GdiFont.GetXFree(bitmap2); num7 = (width - bmwidth) / 2; graphics2 = Graphics.FromImage(image); if (num > 0) { int num8 = GdiFont.GetY2Free(bitmap2); Graphics.FromImage(image).DrawImage( bitmap2, new Rectangle(0, 0, width, height), new Rectangle(num4 - num7, num - num8, width, height), GraphicsUnit.Pixel ); } else { Graphics.FromImage(image).DrawImage( bitmap2, new Rectangle(0, 0, width, height), new Rectangle(num4 - num7, 0, width, height), GraphicsUnit.Pixel ); } graphics2.Dispose(); flag = false; } else if (cbCompensation.SelectedIndex == 3) { if (num == 0) { num = GdiFont.GetY2Free(bitmap2); } fontDesc.FontSize -= 0.5f; flag = true; } else { num7 = GdiFont.GetXFree(bitmap2); using (graphics2 = Graphics.FromImage(image)) { graphics2.InterpolationMode = m_settings; if (width > 24) { graphics2.DrawImage( bitmap2, new Rectangle(1, 0, width - 2, height), new Rectangle(num7, 0, bmwidth, height), GraphicsUnit.Pixel ); } else { graphics2.DrawImage( bitmap2, new Rectangle(0, 0, width, height), new Rectangle(num7, 0, bmwidth, height), GraphicsUnit.Pixel ); } if (s == "X") { s = "X"; } } flag = false; } } } pictureBoxL.Image = image; Application.DoEvents(); } return(true); } catch (Exception ex) { graphics.Dispose(); MessageBox.Show(ex.Message); } return(false); }