Exemple #1
0
        //public ZiFont(byte width, byte height, CodePage codePage) {
        //    CharacterWidth = width;
        //    CharacterHeight = height;
        //    CodePage = codePage;
        //}

        public void Save(string fileName, CodePage codePage)
        {
            _charData = CreateCharData(CharBitmaps);

            var file = new List <byte>();

            file.AddRange(MagicNumbers);
            file.AddRange(BitConverter.GetBytes((ushort)codePage.CodePageIdentifier));
            file.Add(CharacterWidth);
            file.Add(CharacterHeight);
            file.Add((byte)(codePage.IsMultibyte ? codePage.FirstByteStart : 0));
            file.Add((byte)(codePage.IsMultibyte ? codePage.FirstByteEnd : 0));
            file.Add((byte)(codePage.IsMultibyte ? codePage.SecondByteStart : codePage.FirstByteStart));
            file.Add((byte)(codePage.IsMultibyte ? codePage.SecondByteEnd : codePage.FirstByteEnd));
            file.AddRange(BitConverter.GetBytes(CodePage.CharacterCount));
            file.Add(FileFormatVersion);
            file.Add(NameLength);
            file.Add(NameLength);
            file.Add(0x00); // Reserved
            file.AddRange(BitConverter.GetBytes(VariableDataLength));
            file.Add(0x00); // Reserved
            file.Add(0x00); // Reserved
            file.Add(0x00); // Reserved
            file.Add(0x00); // Reserved
            file.AddRange(Encoding.ASCII.GetBytes(Name));
            file.AddRange(_charData);

            File.WriteAllBytes(fileName, file.ToArray());
        }
Exemple #2
0
        public static ZiFont FromCharacterBitmaps(string fontName, byte width, byte height, CodePage codePage, List <Bitmap> characters)
        {
            var bytesPerChar   = width * height / 8;
            var charDataLength = (uint)(bytesPerChar * characters.Count());

            var ziFont = new ZiFont {
                Name               = fontName,
                NameLength         = (byte)fontName.Length,
                CharacterWidth     = width,
                CharacterHeight    = height,
                CodePage           = codePage,
                CharDataLength     = charDataLength,
                VariableDataLength = (uint)fontName.Length + charDataLength,
                BytesPerChar       = bytesPerChar,
            };

            ziFont._charData = ziFont.CreateCharData(characters);

            //var charData = new List<byte>();
            //foreach (var cb in characters) {
            //    charData.AddRange(BinaryTools.BitmapTo1BppData(cb));
            //}
            //ziFont._charData = charData.ToArray();

            return(ziFont);
        }
 //public ZiFont(byte width, byte height, CodePage codePage) {
 //    CharacterWidth = width;
 //    CharacterHeight = height;
 //    CodePage = codePage;
 //}
 public void Save(string fileName, CodePage codePage)
 {
     CodePage  = codePage;
     _charData = CreateCharData(CharBitmaps);
     Save(fileName);
 }