Created
January 24, 2011 03:16
-
-
Save chrisforbes/792771 to your computer and use it in GitHub Desktop.
Bitmap Font Generator compatible with GapiDraw 4.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Drawing; | |
namespace fontgen | |
{ | |
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var bitmap = new Bitmap(1024, 60); | |
var x = 0; | |
var s = MakeCharRange(' ', '~'); | |
var f = new Font( args[0], float.Parse(args[1]), FontStyle.Regular); | |
using (var g = Graphics.FromImage(bitmap)) | |
{ | |
g.FillRectangle( Brushes.Magenta, new Rectangle(0,0,bitmap.Width, bitmap.Height )); | |
foreach (var c in s) | |
{ | |
var w = g.MeasureString("_" + "" + c + "_", f).Width - | |
g.MeasureString("__", f).Width; | |
g.DrawWithContrast("" + c, f, Brushes.White, Brushes.Black, x-1, 3); | |
g.DrawLine(Pens.White, x, 0, x + (int)(w + .9f), 0); | |
x += (int)(w + 2.9f); | |
} | |
} | |
bitmap.Save(args[2]); | |
} | |
static void DrawWithContrast(this Graphics g, string s, Font f, Brush fg, Brush bg, int x, int y) | |
{ | |
for (var u = x - 1; u < x + 2; u++) | |
for (var v = y - 1; v < y + 2; v++) | |
g.DrawString(s, f, bg, u, v); | |
g.DrawString(s, f, fg, x, y); | |
} | |
static string MakeCharRange(char a, char b) | |
{ | |
var s = ""; | |
while (a <= b) | |
s += a++; | |
return s; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment