public PersonaFont GetPersonaFont(string name) { if (encodings.ContainsKey(name)) { return(encodings[name]); } else { try { var enc = new PersonaFont(Path.Combine(sourcedir, name + ".fnt")); encodings.Add(name, enc); return(enc); } catch { return(null); } } }
public static ImageData DrawText(IList <TextBaseElement> text, PersonaEncoding.PersonaFont personaFont, Dictionary <int, byte> Shift, int LineSpacing) { if (text != null && personaFont != null) { ImageData returned = new ImageData(); ImageData line = new ImageData(); foreach (var a in text) { if (a.IsText) { for (int i = 0; i < a.Array.Length; i++) { int index = 0; if (0x20 <= a.Array[i] & a.Array[i] < 0x80) { index = a.Array[i]; } else if (0x80 <= a.Array[i] & a.Array[i] < 0xF0) { index = (a.Array[i] - 0x81) * 0x80 + a.Array[i + 1] + 0x20; i++; } var Glyph = personaFont.GetGlyph(index); if (Glyph.Item1 != null) { byte shift; bool shiftb = Shift.TryGetValue(index, out shift); ImageData glyph = new ImageData(Glyph.Item1, personaFont.PixelFormat, personaFont.Width, personaFont.Height); byte Left = Glyph.Item2.Left; byte Right = Glyph.Item2.Right; glyph = shiftb == false?ImageData.Crop(glyph, new ImageData.Rect(Left, 0, Right - Left, glyph.PixelHeight)) : ImageData.Shift(ImageData.Crop(glyph, new ImageData.Rect(Left, 0, Right - Left, glyph.PixelHeight)), shift); line = ImageData.MergeLeftRight(line, glyph, 1); } } } else { if (Util.ByteArrayCompareWithSimplest(a.Array, new byte[] { 0x0A })) { if (returned.IsEmpty) { if (line.IsEmpty) { returned = new ImageData(PixelFormats.Indexed4, 1, 32); } else { returned = line; line = new ImageData(); } } else { if (line.IsEmpty) { returned = MergeUpDown(returned, new ImageData(PixelFormats.Indexed4, 1, 32), LineSpacing); } else { returned = MergeUpDown(returned, line, LineSpacing); line = new ImageData(); } } } } } returned = ImageData.MergeUpDown(returned, line, LineSpacing); return(returned); } return(new ImageData()); }