static void Main(string[] args) { /* * var bitmap = new Bitmap(200, 200); * var g = Graphics.FromImage(bitmap); * var Font = new Font("MS Gothic", 16, FontStyle.Regular); * var size = g.MeasureString("a", Font); * g.DrawString("a", Font, new SolidBrush(Color.Black), new PointF(0, 0)); * bitmap.Save("temp.png"); * Console.WriteLine(size); */ PGF PGF = new PGF(); //PGF.load("../../ltn0.pgf"); PGF.load("../../jpn0.pgf"); for (int m = 0; m < PGF.charMap.Length; m++) { //Console.WriteLine("{0} -> {1} :: {2}", m, PGF.charMap[m], (int)'あ'); } //PGF.write("../../ltn0.pgf.bak"); PGF.GetGlyph('あ').Shadow.GetBitmap().Save("_a.png"); PGF.GetGlyph('な').Shadow.GetBitmap().Save("_na.png"); PGF.GetGlyph('た').Shadow.GetBitmap().Save("_ta.png"); PGF.GetGlyph('私').Shadow.GetBitmap().Save("_watashi.png"); PGF.GetGlyph('あ').Face.GetBitmap().Save("a.png"); PGF.GetGlyph('な').Face.GetBitmap().Save("na.png"); PGF.GetGlyph('た').Face.GetBitmap().Save("ta.png"); PGF.GetGlyph('私').Face.GetBitmap().Save("watashi.png"); /* * int n = 0; * foreach (var Glyph in PGF.Glyphs) * { * Glyph.GetBitmap().Save(String.Format("dump/{0}.png", n)); * n++; * //break; * } * */ //PGF.GetGlyph('a').GetBitmap().Save("a.png"); //test(); Console.ReadKey(); }
static void Main(string[] args) { /* var bitmap = new Bitmap(200, 200); var g = Graphics.FromImage(bitmap); var Font = new Font("MS Gothic", 16, FontStyle.Regular); var size = g.MeasureString("a", Font); g.DrawString("a", Font, new SolidBrush(Color.Black), new PointF(0, 0)); bitmap.Save("temp.png"); Console.WriteLine(size); */ PGF PGF = new PGF(); //PGF.load("../../ltn0.pgf"); PGF.load("../../jpn0.pgf"); for (int m = 0; m < PGF.charMap.Length; m++) { //Console.WriteLine("{0} -> {1} :: {2}", m, PGF.charMap[m], (int)'あ'); } //PGF.write("../../ltn0.pgf.bak"); PGF.GetGlyph('あ').Shadow.GetBitmap().Save("_a.png"); PGF.GetGlyph('な').Shadow.GetBitmap().Save("_na.png"); PGF.GetGlyph('た').Shadow.GetBitmap().Save("_ta.png"); PGF.GetGlyph('私').Shadow.GetBitmap().Save("_watashi.png"); PGF.GetGlyph('あ').Face.GetBitmap().Save("a.png"); PGF.GetGlyph('な').Face.GetBitmap().Save("na.png"); PGF.GetGlyph('た').Face.GetBitmap().Save("ta.png"); PGF.GetGlyph('私').Face.GetBitmap().Save("watashi.png"); /* int n = 0; foreach (var Glyph in PGF.Glyphs) { Glyph.GetBitmap().Save(String.Format("dump/{0}.png", n)); n++; //break; } * */ //PGF.GetGlyph('a').GetBitmap().Save("a.png"); //test(); Console.ReadKey(); }
public GlyphSymbol Read(PGF PGF, int GlyphIndex) { var br = new BitReader(PGF.charData); br.Position = PGF.charPointer[GlyphIndex] * 4 * 8; this.GlyphIndex = GlyphIndex; this.UnicodeChar = (char)PGF.reverseCharMap[GlyphIndex]; //int NextOffset = br.Position; //br.Position = NextOffset; int ShadowOffset = (int)br.Position + (int)br.ReadBits(14) * 8; if (GlyphType == GlyphFlags.FONT_PGF_SHADOWGLYPH) { br.Position = ShadowOffset; br.SkipBits(14); } this.Width = br.ReadBits(7); this.Height = br.ReadBits(7); this.Left = br.ReadBitsSigned(7); this.Top = br.ReadBitsSigned(7); this.Flags = (GlyphFlags)br.ReadBits(6); if (Flags.HasFlag(GlyphFlags.FONT_PGF_CHARGLYPH)) { br.SkipBits(7); var shadowId = br.ReadBits(9); br.SkipBits(24); if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG1)) br.SkipBits(56); if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG2)) br.SkipBits(56); if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG3)) br.SkipBits(56); this.AdvanceIndex = br.ReadBits(8); } this.DataByteOffset = (uint)(br.Position / 8); uint PixelIndex = 0; uint NumberOfPixels = Width * Height; bool BitmapHorizontalRows = (Flags & GlyphFlags.FONT_PGF_BMP_OVERLAY) == GlyphFlags.FONT_PGF_BMP_H_ROWS; this.Data = new byte[NumberOfPixels]; int Count; uint Value = 0; uint x, y; //Console.WriteLine(br.BitsLeft); while (PixelIndex < NumberOfPixels) { uint Code = br.ReadBits(4); if (Code < 8) { Value = br.ReadBits(4); Count = (int)Code + 1; } else { Count = 16 - (int)Code; } for (int n = 0; (n < Count) && (PixelIndex < NumberOfPixels); n++) { if (Code >= 8) { Value = br.ReadBits(4); } if (BitmapHorizontalRows) { x = PixelIndex % Width; y = PixelIndex / Width; } else { x = PixelIndex / Height; y = PixelIndex % Height; } this.Data[x + y * Width] = (byte)((Value << 0) | (Value << 4)); PixelIndex++; } } /* for (int y = 0, n = 0; y < Height; y++) { for (int x = 0; x < Width; x++, n++) { Console.Write("{0:X1}", this.Data[n] & 0xF); //String.Format } Console.WriteLine(""); } */ //Console.WriteLine(this); return this; }
public Glyph(PGF PGF, int GlyphIndex) { this.PGF = PGF; this.GlyphIndex = GlyphIndex; }
public GlyphSymbol Read(PGF PGF, int GlyphIndex) { var br = new BitReader(PGF.charData); br.Position = PGF.charPointer[GlyphIndex] * 4 * 8; this.GlyphIndex = GlyphIndex; this.UnicodeChar = (char)PGF.reverseCharMap[GlyphIndex]; //int NextOffset = br.Position; //br.Position = NextOffset; int ShadowOffset = (int)br.Position + (int)br.ReadBits(14) * 8; if (GlyphType == GlyphFlags.FONT_PGF_SHADOWGLYPH) { br.Position = ShadowOffset; br.SkipBits(14); } this.Width = br.ReadBits(7); this.Height = br.ReadBits(7); this.Left = br.ReadBitsSigned(7); this.Top = br.ReadBitsSigned(7); this.Flags = (GlyphFlags)br.ReadBits(6); if (Flags.HasFlag(GlyphFlags.FONT_PGF_CHARGLYPH)) { br.SkipBits(7); var shadowId = br.ReadBits(9); br.SkipBits(24); if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG1)) { br.SkipBits(56); } if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG2)) { br.SkipBits(56); } if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG3)) { br.SkipBits(56); } this.AdvanceIndex = br.ReadBits(8); } this.DataByteOffset = (uint)(br.Position / 8); uint PixelIndex = 0; uint NumberOfPixels = Width * Height; bool BitmapHorizontalRows = (Flags & GlyphFlags.FONT_PGF_BMP_OVERLAY) == GlyphFlags.FONT_PGF_BMP_H_ROWS; this.Data = new byte[NumberOfPixels]; int Count; uint Value = 0; uint x, y; //Console.WriteLine(br.BitsLeft); while (PixelIndex < NumberOfPixels) { uint Code = br.ReadBits(4); if (Code < 8) { Value = br.ReadBits(4); Count = (int)Code + 1; } else { Count = 16 - (int)Code; } for (int n = 0; (n < Count) && (PixelIndex < NumberOfPixels); n++) { if (Code >= 8) { Value = br.ReadBits(4); } if (BitmapHorizontalRows) { x = PixelIndex % Width; y = PixelIndex / Width; } else { x = PixelIndex / Height; y = PixelIndex % Height; } this.Data[x + y * Width] = (byte)((Value << 0) | (Value << 4)); PixelIndex++; } } /* * for (int y = 0, n = 0; y < Height; y++) * { * for (int x = 0; x < Width; x++, n++) * { * Console.Write("{0:X1}", this.Data[n] & 0xF); * //String.Format * } * Console.WriteLine(""); * } * */ //Console.WriteLine(this); return(this); }