private static Set <string> GetDteGroups(FFTFont font, GenericCharMap charmap, IList <string> charset) { var f = new FFTFont(font.ToByteArray(), font.ToWidthsByteArray()); List <int> widths = new List <int>(2200); f.Glyphs.ForEach(g => widths.Add(g.Width)); return(TextUtilities.GetGroups(charmap, charset, widths)); }
private static void GenerateFontBinPatches( IEnumerable <KeyValuePair <string, byte> > dteEncodings, FFTFont baseFont, IList <string> baseCharSet, out byte[] fontBytes, out byte[] widthBytes) { FFTFont font = new FFTFont(baseFont.ToByteArray(), baseFont.ToWidthsByteArray()); IList <string> charSet = new List <string>(baseCharSet); foreach (var kvp in dteEncodings) { int[] chars = new int[] { charSet.IndexOf(kvp.Key.Substring(0, 1)), charSet.IndexOf(kvp.Key.Substring(1, 1)) }; int[] widths = new int[] { font.Glyphs[chars[0]].Width, font.Glyphs[chars[1]].Width }; int newWidth = widths[0] + widths[1]; font.Glyphs[kvp.Value].Width = (byte)newWidth; IList <FontColor> newPixels = font.Glyphs[kvp.Value].Pixels; for (int i = 0; i < newPixels.Count; i++) { newPixels[i] = FontColor.Transparent; } const int fontHeight = 14; const int fontWidth = 10; int offset = 0; for (int c = 0; c < chars.Length; c++) { var pix = font.Glyphs[chars[c]].Pixels; for (int x = 0; x < widths[c]; x++) { for (int y = 0; y < fontHeight; y++) { newPixels[y * fontWidth + x + offset] = pix[y * fontWidth + x]; } } offset += widths[c]; } } fontBytes = font.ToByteArray(); widthBytes = font.ToWidthsByteArray(); }
private static void GenerateFontBinPatches( IEnumerable <KeyValuePair <string, byte> > dteEncodings, FFTFont baseFont, IList <string> baseCharSet, out byte[] fontBytes, out byte[] widthBytes) { // Make a copy of the font FFTFont font = new FFTFont(baseFont.ToByteArray(), baseFont.ToWidthsByteArray()); IList <string> charSet = new List <string>(baseCharSet); charSet.Add(" "); var myGlyphs = new List <Glyph>(font.Glyphs); myGlyphs.Add(new Glyph(0, 4, new byte[14 * 10 / 4])); foreach (var kvp in dteEncodings) { int[] chars = new int[] { charSet.IndexOf(kvp.Key.Substring(0, 1)), // Find the index of the first character in the pair charSet.IndexOf(kvp.Key.Substring(1, 1)) // Second character in the pair }; int[] widths = new int[] { myGlyphs[chars[0]].Width, // width of first char myGlyphs[chars[1]].Width // width of secont char }; // The width of the concatenated character is the sum... int newWidth = widths[0] + widths[1]; myGlyphs[kvp.Value].Width = (byte)newWidth; // Erase all the pixels of the character to replace IList <FontColor> newPixels = myGlyphs[kvp.Value].Pixels; for (int i = 0; i < newPixels.Count; i++) { newPixels[i] = FontColor.Transparent; } const int fontHeight = 14; const int fontWidth = 10; int offset = 0; // for each character in the pair... for (int c = 0; c < chars.Length; c++) { var pix = myGlyphs[chars[c]].Pixels; // ... copy the pixels to the concatenated character for (int x = 0; x < widths[c]; x++) { for (int y = 0; y < fontHeight; y++) { newPixels[y * fontWidth + x + offset] = pix[y * fontWidth + x]; } } offset += widths[c]; } } // Return the new font and widths arrays fontBytes = font.ToByteArray(); widthBytes = font.ToWidthsByteArray(); }