} // GetFontFromBitmap private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { if (CurChar == -1) { return; } int tw = CharBox.Width; int th = CharBox.Height; int border = (int)BorderSize.Value; Pen pen = new Pen(Color.Red, 1); FontChar c = (FontChar)Chars[CurChar - MinChar]; float x = CharBox.Left + tw / 2 - c.Width / 2 - border; float y = CharBox.Top + th / 2 - c.Height / 2 - border; e.Graphics.DrawRectangle(pen, x - border, y - border, c.Width + border * 2, c.Height + border * 2); e.Graphics.DrawImage(c.Bmp, x, y); }
} // ReplicateAlpha private void CreateFont_Closed(object sender, System.EventArgs e) { MainForm.Instance.Visible = true; for (int i = MinChar; i <= MaxChar; i++) { char[] ch = new char[1]; ch[0] = (char)i; string str = new string( ch ); if (Chars.Count <= i - MinChar) { continue; } FontChar c = (FontChar)Chars[i - MinChar]; ColorFormat colorFmt = (ColorFormat)MainForm.Instance.ColorFormatBox.SelectedIndex; bool bBorder = MainForm.Instance.IsFiltered.Checked; MainForm.Instance.SPack.Sprites.Add(new Sprite(str, "", c.Bmp, colorFmt, bBorder)); } MainForm.Instance.UpdateFileList(); }
} // GenerateFontBitmap void GetFontFromBitmap() { int border = (int)BorderSize.Value; ImportProgress.Visible = true; ImportProgress.Minimum = MinChar; ImportProgress.Maximum = MaxChar; ImportProgress.Value = MinChar; ImportProgress.Step = 1; for (int i = MinChar; i <= MaxChar; i++) { FontChar c = (FontChar)Chars[i - MinChar]; Rectangle rct = new Rectangle(c.X, c.Y, c.Width, c.Height); if (rct.Width == 0) { continue; } c.Bmp = Bmp.Clone(rct, PixelFormat.Format32bppArgb); ImportProgress.PerformStep(); ImportProgress.Update(); } ImportProgress.Visible = false; Update(); } // GetFontFromBitmap
private void GenerateFontBitmap() { if (CurFont == null) return; int fontH = (int)CurFont.GetHeight(); int border = (int)BorderSize.Value; SolidBrush br = new SolidBrush( Color.White ); SolidBrush brBack = new SolidBrush( Color.Black ); int maxW = 0; Graphics graphics = Graphics.FromImage( Bmp ); if (DoAntialias.Checked) { graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; } else { graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; } Chars.Clear(); StringFormat fmt = new StringFormat( StringFormat.GenericTypographic ); for (int i = MinChar; i <= MaxChar; i++) { FontChar c = new FontChar(); char ch = GetChar( i, CurFont.GdiCharSet ); c.Code = i; c.Width = MeasureCharWidth( graphics, ch, CurFont ); c.Height = fontH + border; if (c.Width > maxW) maxW = (int)c.Width; Chars.Add( c ); } graphics.Dispose(); float area = (maxW + border*2)*(fontH + border*2)*(MaxChar - MinChar + 1); int bmpSide = 64; while (bmpSide*bmpSide < (int)area) bmpSide *= 2; Bmp.Dispose(); Bmp = new Bitmap( bmpSide, bmpSide, PixelFormat.Format32bppArgb ); graphics = Graphics.FromImage( Bmp ); if (DoAntialias.Checked) graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; else graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; graphics.FillRectangle( brBack, 0, 0, bmpSide, bmpSide ); int x = border; int y = border; for (int i = MinChar; i <= MaxChar; i++) { char[] ch = new char[1]; ch[0] = GetChar( i, CurFont.GdiCharSet ); string s = new string( ch ); FontChar c = (FontChar)Chars[i - MinChar]; if (x + c.Width + border*2 > bmpSide) { x = border; y += fontH + border*2; } graphics.DrawString( s, CurFont, br, x + border, y + border, fmt ); c.X = x + border; c.Y = y + border; x += c.Width + border*2; } graphics.Dispose(); ReplicateAlpha( ref Bmp ); GetFontFromBitmap(); }
private void GenerateFontBitmap() { if (CurFont == null) { return; } int fontH = (int)CurFont.GetHeight(); int border = (int)BorderSize.Value; SolidBrush br = new SolidBrush(Color.White); SolidBrush brBack = new SolidBrush(Color.Black); int maxW = 0; Graphics graphics = Graphics.FromImage(Bmp); if (DoAntialias.Checked) { graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; } else { graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; } Chars.Clear(); StringFormat fmt = new StringFormat(StringFormat.GenericTypographic); for (int i = MinChar; i <= MaxChar; i++) { FontChar c = new FontChar(); char ch = GetChar(i, CurFont.GdiCharSet); c.Code = i; c.Width = MeasureCharWidth(graphics, ch, CurFont); c.Height = fontH + border; if (c.Width > maxW) { maxW = (int)c.Width; } Chars.Add(c); } graphics.Dispose(); float area = (maxW + border * 2) * (fontH + border * 2) * (MaxChar - MinChar + 1); int bmpSide = 64; while (bmpSide * bmpSide < (int)area) { bmpSide *= 2; } Bmp.Dispose(); Bmp = new Bitmap(bmpSide, bmpSide, PixelFormat.Format32bppArgb); graphics = Graphics.FromImage(Bmp); if (DoAntialias.Checked) { graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; } else { graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; } graphics.FillRectangle(brBack, 0, 0, bmpSide, bmpSide); int x = border; int y = border; for (int i = MinChar; i <= MaxChar; i++) { char[] ch = new char[1]; ch[0] = GetChar(i, CurFont.GdiCharSet); string s = new string( ch ); FontChar c = (FontChar)Chars[i - MinChar]; if (x + c.Width + border * 2 > bmpSide) { x = border; y += fontH + border * 2; } graphics.DrawString(s, CurFont, br, x + border, y + border, fmt); c.X = x + border; c.Y = y + border; x += c.Width + border * 2; } graphics.Dispose(); ReplicateAlpha(ref Bmp); GetFontFromBitmap(); } // GenerateFontBitmap