コード例 #1
0
ファイル: Font.cs プロジェクト: MikeG621/LfdReader
 /// <summary>Creates a new instance and prepares for a new character set</summary>
 /// <param name="startChar">First defined ASCII value (normally <b>32</b>)</param>
 /// <param name="numberOfChars">Number of characters to be defined</param>
 /// <param name="height">Height of the character set in pixels</param>
 /// <remarks><see cref="BaseLine"/> is set between 2/3 and 3/4 of <i>height</i>.<br/>
 /// <see cref="BitsPerScanLine"/> is set to round up from square characters.
 /// A <i>height</i> of <b>8</b> produces a maximum width of <b>8</b>,
 /// while a <i>height</i> of <b>12</b> produces a width of <b>16</b>.<br/>
 /// All images in <see cref="Glyphs"/> are initialized to blank <see cref="PixelFormat.Format1bppIndexed"/> images,
 /// <see cref="BitsPerScanLine"/>x<see cref="Height"/> in size.</remarks>
 public Font(short startChar, short numberOfChars, short height)
 {
     _startingChar = startChar;
     _height = height;
     BaseLine = (short)Math.Ceiling((double)_height * .67);
     _bitsPerScanLine = (short)(_height + (_height % 8 == 0 ? 0 : 8 - (_height % 8)));
     _glyphs = new Bitmap[numberOfChars];
     for (int i = 0; i < _glyphs.Length; i++) _glyphs[i] = new Bitmap(_bitsPerScanLine, _height, PixelFormat.Format1bppIndexed);
     _glyphIndexer = new GlyphIndexer(this);
 }
コード例 #2
0
ファイル: Font.cs プロジェクト: MikeG621/LfdReader
 /// <summary>Processes raw data to populate the resource</summary>
 /// <param name="raw">Raw byte data</param>
 /// <param name="containsHeader">Whether or not <i>raw</i> contains the resource Header information</param>
 /// <exception cref="ArgumentException">Header-defined <see cref="Type"/> is not <see cref="ResourceType.Font"/></exception>
 public override void DecodeResource(byte[] raw, bool containsHeader)
 {
     _decodeResource(raw, containsHeader);
     if (_type != ResourceType.Font) throw new ArgumentException("Raw header is not for a Font resource");
     int offset = 0;
     _startingChar = BitConverter.ToInt16(_rawData, offset);
     _glyphs = new Bitmap[BitConverter.ToInt16(_rawData, offset + 2)];
     _bitsPerScanLine = BitConverter.ToInt16(_rawData, offset + 4);
     _height = BitConverter.ToInt16(_rawData, offset + 6);
     _baseLine = BitConverter.ToInt16(_rawData, offset + 8);
     offset += 12;
     for (int i = 0; i < _glyphs.Length; i++)
         _glyphs[i] = new Bitmap(_rawData[offset++], _height, PixelFormat.Format1bppIndexed);
     for (int i = 0; i < _glyphs.Length; i++)
     {
         BitmapData bd1 = GraphicsFunctions.GetBitmapData(_glyphs[i]);
         byte[] pix1 = new byte[bd1.Stride * bd1.Height];
         for (int y = 0; y < _height; y++)
             for (int s = 0; s < (_bitsPerScanLine / 8); s++)
                 pix1[y * bd1.Stride + s] = _rawData[offset++];
         GraphicsFunctions.CopyBytesToImage(pix1, bd1);
         _glyphs[i].UnlockBits(bd1);
     }
     _glyphIndexer = new GlyphIndexer(this);
 }