Beispiel #1
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);
        }
Beispiel #2
0
        public static ZiFont FromBytes(byte[] bytes)
        {
            if (!VerifyHeader(bytes))
            {
                return(null);
            }

            var ziFont = new ZiFont();

            ziFont._header    = bytes.Take(HEADER_LENGTH).ToArray();
            ziFont.NameLength = ziFont._header[0x11];
            ziFont.Name       = Encoding.ASCII.GetString(bytes.Skip(HEADER_LENGTH).Take(ziFont.NameLength).ToArray());
            ziFont.FileSize   = bytes.Length;

            ziFont.CharacterWidth  = ziFont._header[0x6];
            ziFont.CharacterHeight = ziFont._header[0x7];

            ziFont.VariableDataLength = BitConverter.ToUInt32(ziFont._header.Skip(0x14).Take(4).ToArray(), 0);
            ziFont.CharDataLength     = ziFont.VariableDataLength - ziFont.NameLength;

            ziFont._charData    = bytes.Skip(HEADER_LENGTH + ziFont.NameLength).ToArray();
            ziFont.BytesPerChar = (ziFont.CharacterWidth * ziFont.CharacterHeight) / 8;

            var codePageId          = BitConverter.ToUInt16(ziFont._header.Skip(0x4).Take(2).ToArray(), 0);
            var characterCount      = BitConverter.ToUInt32(ziFont._header.Skip(0x0C).Take(4).ToArray(), 0);
            var calculatedCharCount = ziFont.CharDataLength / ziFont.BytesPerChar;

            ziFont.CodePage = CodePages.GetCodePage((CodePageIdentifier)codePageId);

            if (characterCount != calculatedCharCount)
            {
                throw new Exception($"{nameof(characterCount)} and {nameof(calculatedCharCount)} doesn't match.");
            }

            ziFont.CreateBitmaps();

            return(ziFont);
        }