summaryrefslogtreecommitdiff
path: root/BitmapChar.cs
diff options
context:
space:
mode:
Diffstat (limited to 'BitmapChar.cs')
-rw-r--r--BitmapChar.cs127
1 files changed, 72 insertions, 55 deletions
diff --git a/BitmapChar.cs b/BitmapChar.cs
index f902d7c..e1cf532 100644
--- a/BitmapChar.cs
+++ b/BitmapChar.cs
@@ -195,30 +195,51 @@ namespace BitmapFontEd
public void Output(Stream stream)
{
- WriteUint(stream,m_width);
- WriteUint(stream,m_height);
+ Util.WriteUint(stream,m_width);
+ Util.WriteUint(stream,m_height);
- for(uint y=0;y<m_height;y++)
+ for(uint x=0;x<m_width;x++)
{
- for(uint x=0;x<m_width;x++)
+ for(uint y=0;y<m_height;y++)
{
- WriteInt(stream,m_data[x,y].ToArgb());
+ if (m_data[x,y]!=Color.Black)
+ {
+ Util.WriteInt(stream,m_data[x,y].ToArgb());
+ }
+ else
+ {
+ Util.WriteInt(stream,0);
+ }
}
}
}
public static BitmapChar Input(Stream stream)
{
- uint width=ReadUint(stream);
- uint height=ReadUint(stream);
+ uint width=Util.ReadUint(stream);
+ uint height=Util.ReadUint(stream);
BitmapChar s=new BitmapChar(width,height);
- for(uint y=0;y<height;y++)
+ for(uint x=0;x<width;x++)
{
- for(uint x=0;x<width;x++)
+ for(uint y=0;y<height;y++)
{
- s[x,y]=Color.FromArgb(ReadInt(stream));
+ int col=Util.ReadInt(stream);
+
+ if (col==0)
+ {
+ s[x,y]=Color.Black;
+ }
+ else
+ {
+ s[x,y]=Color.FromArgb(255,(col&0xff0000)>>16,(col&0xff00)>>8,col&0xff);
+
+ if (s[x,y].R==0 && s[x,y].G==0 && s[x,y].B==0)
+ {
+ s[x,y]=Color.Black;
+ }
+ }
}
}
@@ -244,50 +265,6 @@ namespace BitmapFontEd
return v;
}
-
- private static uint ReadUint(Stream s)
- {
- uint l=0;
-
- for(int f=0;f<4;f++)
- {
- int b=s.ReadByte();
- l|=(uint)(b<<(f*8));
- }
-
- return l;
- }
-
- private static int ReadInt(Stream s)
- {
- int l=0;
-
- for(int f=0;f<4;f++)
- {
- int b=s.ReadByte();
- l|=b<<(f*8);
- }
-
- return l;
- }
-
- private static void WriteUint(Stream s, uint l)
- {
- for(uint f=0;f<4;f++)
- {
- s.WriteByte((byte)(l&0xff));
- l=l>>8;
- }
- }
-
- private static void WriteInt(Stream s, int l)
- {
- for(uint f=0;f<4;f++)
- {
- s.WriteByte((byte)(l&0xff));
- l=l>>8;
- }
- }
}
/// <summary>
@@ -295,7 +272,7 @@ namespace BitmapFontEd
/// </summary>
public class BitmapCharList : IEnumerable
{
- private const int CHARS=96;
+ private const int CHARS=95;
public BitmapCharList()
{
@@ -325,6 +302,24 @@ namespace BitmapFontEd
set {m_changed=value;}
}
+ public bool IsFixedWidth
+ {
+ get
+ {
+ uint w=m_list[0].Width;
+
+ foreach (BitmapChar c in m_list)
+ {
+ if (c.Width!=w)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+
public IEnumerator GetEnumerator()
{
return m_list.GetEnumerator();
@@ -332,6 +327,17 @@ namespace BitmapFontEd
public void Output(Stream stream)
{
+ Util.WriteString(stream,MAGIC);
+
+ if (IsFixedWidth)
+ {
+ Util.WriteInt(stream,1);
+ }
+ else
+ {
+ Util.WriteInt(stream,0);
+ }
+
foreach (BitmapChar c in m_list)
{
c.Output(stream);
@@ -342,6 +348,15 @@ namespace BitmapFontEd
{
BitmapCharList l=new BitmapCharList();
+ string magic=Util.ReadString(stream,4);
+
+ if (magic!=MAGIC)
+ {
+ throw new Exception("Not a recognised BMF file");
+ }
+
+ Util.ReadInt(stream);
+
for(int f=0;f<CHARS;f++)
{
l.m_list[f]=BitmapChar.Input(stream);
@@ -355,6 +370,8 @@ namespace BitmapFontEd
// ------------------------------------------------
// PRIVATE
//
+ private const string MAGIC="BMF1";
+
private BitmapChar[] m_list;
private bool m_changed;
}