ReadBitsSigned() public method

public ReadBitsSigned ( int Count ) : int
Count int
return int
Esempio n. 1
0
        public GlyphSymbol Read(PGF PGF, int GlyphIndex)
        {
            var BitReader = new BitReader(PGF.CharData);
            BitReader.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)BitReader.Position + (int)BitReader.ReadBits(14) * 8;
            if (GlyphType == GlyphFlags.FONT_PGF_SHADOWGLYPH)
            {
                BitReader.Position = ShadowOffset;
                BitReader.SkipBits(14);
            }

            this.Width = BitReader.ReadBits(7);
            this.Height = BitReader.ReadBits(7);
            this.Left = BitReader.ReadBitsSigned(7);
            this.Top = BitReader.ReadBitsSigned(7);
            this.Flags = (GlyphFlags)BitReader.ReadBits(6);

            if (Flags.HasFlag(GlyphFlags.FONT_PGF_CHARGLYPH))
            {
                BitReader.SkipBits(7);
                var shadowId = BitReader.ReadBits(9);
                BitReader.SkipBits(24);
                if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG1)) BitReader.SkipBits(56);
                if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG2)) BitReader.SkipBits(56);
                if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG3)) BitReader.SkipBits(56);
                this.AdvanceIndex = BitReader.ReadBits(8);
            }

            this.DataByteOffset = (uint)(BitReader.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 = BitReader.ReadBits(4);

                if (Code < 8)
                {
                    Value = BitReader.ReadBits(4);
                    Count = (int)Code + 1;
                }
                else
                {
                    Count = 16 - (int)Code;
                }

                for (int n = 0; (n < Count) && (PixelIndex < NumberOfPixels); n++)
                {
                    if (Code >= 8)
                    {
                        Value = BitReader.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;
        }