private void ReadFONT(FNT FNT) { Height = FNT.Header.Glyphs.Size1; Width = FNT.Header.Glyphs.Size2; Palette = FNT.Palette.Pallete; if (FNT.Header.Glyphs.BitsPerPixel == 4) { PixelFormat = PixelFormats.Indexed4; } else if (FNT.Header.Glyphs.BitsPerPixel == 8) { PixelFormat = PixelFormats.Indexed8; } else { throw new Exception("ReadFONT Error: unknown PixelFormat"); } var DecList = FNT.Compressed.GetDecompressedData(); if (FNT.Header.Glyphs.BitsPerPixel == 4) { ArrayTool.ReverseByteInList(DecList); } for (int i = 0; i < DecList.Count; i++) { var Cut = FNT.WidthTable[i] == null ? new VerticalCut(0, (byte)Width) : FNT.WidthTable[i].Value; int index = i + 32; if (DataList.ContainsKey(index)) { DataList[index] = DecList[i]; } else { DataList.Add(index, DecList[i]); } if (CutList.ContainsKey(index)) { CutList[index] = Cut; } else { CutList.Add(index, Cut); } } }
private void OpenFont() { var GlyphList = fnt.Compressed.GetDecompressedData(); var CutList = fnt.WidthTable.WidthTable; PixelFormat pixelFormat; if (fnt.Header.Glyphs.BitsPerPixel == 4) { pixelFormat = PixelFormats.Indexed4; } else if (fnt.Header.Glyphs.BitsPerPixel == 8) { pixelFormat = PixelFormats.Indexed8; } else { pixelFormat = PixelFormats.Default; } if (pixelFormat == PixelFormats.Indexed4) { ArrayTool.ReverseByteInList(GlyphList); } var pallete = new BitmapPalette(fnt.Palette.GetImagePalette().Select(x => Color.FromArgb(x.A, x.R, x.G, x.B)).ToArray()); if (GlyphList.Count <= CutList.Count) { for (int i = 0; i < GlyphList.Count; i++) { var image = BitmapSource.Create(fnt.Header.Glyphs.Size1, fnt.Header.Glyphs.Size2, 96, 96, pixelFormat, pallete, GlyphList[i], (pixelFormat.BitsPerPixel * fnt.Header.Glyphs.Size2 + 7) / 8); image.Freeze(); GlyphCuts.Add(new GlyphCut(image, CutList[i], i)); } } }