public SdrFontPack MakeNarrowPack(float hScale) { //Make pack SdrFontPack pack = new SdrFontPack((byte)(width * hScale), height); //Convert characters foreach (var c in font) { byte[] data = new byte[pack.height * pack.width]; for (int y = 0; y < pack.height; y++) { int srcY = y; for (int x = 0; x < pack.width; x++) { int srcX = (int)(x / hScale); data[x + (y * pack.width)] = Math.Max(c.Value[srcX + (srcY * width)], c.Value[srcX + (srcY * width) + 1]); } } pack.font.Add(c.Key, data); } return(pack); }
public static SdrFontPack FromStream(Stream s) { //Load header byte[] header = new byte[Math.Max(HEADER_SIZE, CHAR_HEADER_SIZE)]; s.Read(header, 0, HEADER_SIZE); //Check magic if (header[0] != 'S' || header[1] != 'D' || header[2] != 'R' || header[3] != 'F') { throw new Exception("Invalid file"); } //Read header parts byte version = header[4]; byte count = header[5]; byte width = header[6]; byte height = header[7]; //Create SdrFontPack pack = new SdrFontPack(width, height); //Load all fonts for (int i = 0; i < count; i++) { //Load font header s.Read(header, 0, CHAR_HEADER_SIZE); byte charCode = header[0]; byte charFlags = header[1]; //Read font data byte[] buffer = new byte[width * height]; s.Read(buffer, 0, buffer.Length); pack.font.Add((char)charCode, buffer); } return(pack); }