Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static void ParsingFontTable()
{
string hex = "93A68Ch"; // Shallie Font Table
string startHex = hex.Replace("h", "");
string fileName = "../../../JP_Atelier_Shallie.exe";
List<Glyph> listGlyph = new List<Glyph>();
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
int size = (int)fs.Length;
byte[] buff = new byte[size];
fs.Position = Convert.ToInt64(startHex, 16);
while (fs.Position < size)
{
byte[] bytes = new byte[28];
int n = fs.Read(bytes, 0, 28);
byte[] UTF8 = new byte[4];
Array.Copy(bytes, UTF8, 4);
Glyph glyph = new Glyph
{
UTF8 = BitConverter.ToUInt32(bytes, 0),
X = BitConverter.ToUInt16(bytes, 4),
Y = BitConverter.ToUInt16(bytes, 6),
Width = BitConverter.ToUInt16(bytes, 8),
Height = BitConverter.ToUInt16(bytes, 10),
PaddingLeft = BitConverter.ToInt32(bytes, 12),
PaddingTop = BitConverter.ToInt32(bytes, 16),
PaddingRigth = BitConverter.ToInt32(bytes, 20),
PaddingBottom = BitConverter.ToInt32(bytes, 24),
};
if (glyph.Char == '\\')
{
SaveBitmap(listGlyph);
return;
}
listGlyph.Add(glyph);
}
}
}
struct Glyph
{
public uint UTF8;
public ushort X;
public ushort Y;
public ushort Width;
public ushort Height;
public int PaddingLeft;
public int PaddingTop;
public int PaddingRigth;
public int PaddingBottom;
//public Bitmap Texture;
public char Char
{
get
{
if (UTF8 == 0)
return char.MinValue;
var Bytes = BitConverter.GetBytes(UTF8);
while (Bytes.Last() == 0)
Array.Resize(ref Bytes, Bytes.Length - 1);
Bytes = Bytes.Reverse().ToArray();
if (Bytes.Length <= 1 || Bytes[1] == 0)
return '\\';
return Encoding.UTF8.GetString(Bytes).Single();
}
set
{
var Bytes = Encoding.UTF8.GetBytes(value.ToString());
Bytes = Bytes.Reverse().ToArray();
byte[] DW = new byte[4];
Bytes.CopyTo(DW, 0);
UTF8 = BitConverter.ToUInt32(DW, 0);
}
}
public override string ToString()
{
return string.Format("Char: {0}, X: {1}, Y: {2}, W: {3}, H: {4}" +
",L : {5} ,T : {6}, R : {7}, B : {8} "
, Char, X, Y, Width, Height, PaddingBottom, PaddingLeft, PaddingRigth, PaddingTop);
}
}
private static void SaveBitmap(List<Glyph> listGlyph)
{
string imageFilePath = @"../../../shallie_empty.png";
Bitmap bitmap = (Bitmap)System.Drawing.Image.FromFile(imageFilePath);//load the image file
foreach (var glyph in listGlyph)
{
string Text = glyph.Char.ToString();
int x = glyph.X - 0;//3;
int y = glyph.Y - 8;//6;
System.Drawing.PointF Location = new System.Drawing.PointF(x, y);
StringFormat sf = new StringFormat(StringFormat.GenericTypographic);
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Near;
sf.Trimming = StringTrimming.None;
using (Graphics graphics = Graphics.FromImage(bitmap))
{
using (System.Drawing.Font arialFont = new System.Drawing.Font("빙그레체", 25, FontStyle.Bold))
{
graphics.DrawString(Text, arialFont, Brushes.Black, Location, sf);
}
}
}
bitmap.Save(@"../../../shallie_font.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment