(09.01.2021 00:27)feanor Wrote: формат шрифта потом найду и выложу, но там версии если только самому прикручивать, кажется.
Короче, так
- 5 байт заголовок, {31, 255, 8, 0, 0}
- 1 байт высоты глифов
- 26 нулевых байт
- 256 раз по три дворда: отступ от символа слева, ширина, отступ от символа справа. Отступы могут быть отрицательными
- 256 двордов, которые показывают смещение данных о глифе
- 256 битмапов на каждый глиф, ширина*высота байт
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace H3Fnt
{
struct H3Char
{
public int left;
public int width;
public int right;
public int offset;
public byte[] bytestring;
public int height;
}
}
[/code]
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace H3Fnt
{
internal class H3Font
{
byte[] tmp_header;
public byte height;
byte[] tmp_fill;
public H3Char[] charset;
public H3Font()
{
tmp_header = new byte[]{31,255,8,0,0};
height = 0;
tmp_fill = new byte[26];
charset = new H3Char[256];
}
public void Load(string path)
{
using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open)))
{
this.tmp_header = br.ReadBytes(5);
this.height = br.ReadByte();
this.tmp_fill = br.ReadBytes(26);
for (int i = 0; i != 256; i++)
{
this.charset[i].left = br.ReadInt32();
this.charset[i].width = br.ReadInt32();
this.charset[i].right = br.ReadInt32();
this.charset[i].height = this.height;
}
for (int i = 0; i != 256; i++)
{
this.charset[i].offset = br.ReadInt32();
}
/*for (int i = 0; i != 255; i++)
{
fnt[i].bytestring = br.ReadBytes(fnt[i+1].offset - fnt[i].offset);
}
fnt[255].bytestring = br.ReadBytes(fnt[255].width * heigth);*/
for (int i = 0; i != 256; i++)
{
this.charset[i].bytestring = br.ReadBytes(this.charset[i].width * this.height);
}
}
}
public void Save(string path)
{
using (BinaryWriter br = new BinaryWriter(File.Open(path, FileMode.Create)))
{
br.Write(tmp_header);
br.Write(height);
br.Write(tmp_fill);
for (int i = 0; i != 256; i++)
{
br.Write(this.charset[i].left);
br.Write(this.charset[i].width);
br.Write(this.charset[i].right);
}
for (int i = 0, offset = 0; i != 256; i++)
{
br.Write(offset);
offset += this.charset[i].width * this.height;
}
for (int i = 0; i != 256; i++)
{
br.Write(this.charset[i].bytestring);
}
}
}
}
}