public HexFont(string hex) { this.fw = 16; this.fh = 16; byte[] pal = { 0, 1, }; string[] lines = hex.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { var words = line.Split(':'); int charIdx = int.Parse(words[0], System.Globalization.NumberStyles.HexNumber); var fontChar = new HexChar(); fontChars[charIdx] = fontChar; fontChar.fw = words[1].Length > 32 ? 16 : 8; fontChar.fh = 16; fontChar.bitmap = new byte[fontChar.fw * fontChar.fh]; uint[] uints = HexToUint(words[1]); int ii = 0; for (int i = 0; i < uints.Length; i++) { uint val = uints[i]; for (int j = 0; j < 32; j++) { fontChar.bitmap[ii] = pal[(val >> (31 - j)) & 1]; ii++; } } } }
private unsafe void DrawChar(HexChar fontChar, IntPtr dispBuf, int dispBW, int dispBH, int dx, int dy, int icolor) { int _fw = fontChar.fw; int x1 = dx; int y1 = dy; int x2 = dx + _fw - 1; int y2 = dy + fh - 1; if (x1 >= dispBW || x2 < 0 || y1 >= dispBH || y2 < 0) { return; } byte[] src = fontChar.bitmap; for (int y = 0; y < fh; y++) { if (dy + y < 0 || dy + y >= dispBH) { continue; } int *dst = (int *)dispBuf + dispBW * (dy + y) + dx; int srcIdx = y * _fw; for (int x = 0; x < _fw; x++, srcIdx++, dst++) { if (dx + x < 0 || dx + x >= dispBW) { continue; } if (src[srcIdx] != 0) { *dst = icolor; } } } }