Esempio n. 1
0
        public override InfoBlock GetInfoBlock()
        {
            TextLine line = reader.ReadLine();

            if (line.Id != "info")
            {
                throw new Exception("Failed to load angel bmp file, unexpected block '" + line.Id + "'");
            }

            InfoBlock block = new InfoBlock();

            block.FontName  = line.GetString("face") ?? "";
            block.FontSize  = line.GetInt("size") ?? 0;
            block.IsBold    = line.GetBool("bold") ?? false;
            block.IsItalic  = line.GetBool("italic") ?? false;
            block.CharSet   = line.GetUInt("charset") ?? 0;
            block.IsUnicode = line.GetBool("unicode") ?? false;
            block.StretchH  = line.GetUInt("stretchH") ?? 0;
            block.IsSmooth  = line.GetBool("smooth") ?? false;
            block.AA        = line.GetUInt("aa") ?? 0;
            Vector4i padding = line.GetVector4i("padding") ?? Vector4i.Zero;

            block.PaddingUp    = (uint)padding.X;
            block.PaddingRight = (uint)padding.Y;
            block.PaddingDown  = (uint)padding.Z;
            block.PaddingLeft  = (uint)padding.W;
            Vector2i spacing = line.GetVector2i("spacing") ?? Vector2i.Zero;

            block.SpacingHoriz = spacing.X;
            block.SpacingVert  = spacing.Y;
            block.Outline      = line.GetInt("outline") ?? 0;

            return(block);
        }
Esempio n. 2
0
        public override Dictionary <Tuple <char, char>, int> GetKerningPairs()
        {
            Dictionary <Tuple <char, char>, int> pairs = new Dictionary <Tuple <char, char>, int>();

            if (stream.Position < stream.Length)
            {
                TextLine line = reader.ReadLine();
                if (line.Id != "kernings")
                {
                    throw new Exception("Failed to load angel bmp file, unexpected block '" + line.Id + "'");
                }

                uint numPairs = line.GetUInt("count") ?? 0;

                for (int i = 0; i < numPairs; i++)
                {
                    TextLine kline = reader.ReadLine();
                    if (kline.Id != "kerning")
                    {
                        throw new Exception("Failed to load angel bmp file, unexpected block '" + kline.Id + "'");
                    }

                    uint first  = kline.GetUInt("first") ?? 0;
                    uint second = kline.GetUInt("second") ?? 0;
                    int  amount = kline.GetInt("amount") ?? 0;

                    pairs.Add(new Tuple <char, char>((char)first, (char)second), amount);
                }
            }

            return(pairs);
        }
Esempio n. 3
0
        public override Dictionary <char, BMPFontCharacter> GetCharacters()
        {
            TextLine line = reader.ReadLine();

            if (line.Id != "chars")
            {
                throw new Exception("Failed to load angel bmp file, unexpected block '" + line.Id + "'");
            }

            uint numChars = line.GetUInt("count") ?? 0;
            Dictionary <char, BMPFontCharacter> chars = new Dictionary <char, BMPFontCharacter>();

            for (int i = 0; i < numChars; i++)
            {
                TextLine cline = reader.ReadLine();
                if (cline.Id != "char")
                {
                    throw new Exception("Failed to load angel bmp file, unexpected block '" + cline.Id + "'");
                }

                uint charId   = cline.GetUInt("id") ?? '\0';
                uint x        = cline.GetUInt("x") ?? 0;
                uint y        = cline.GetUInt("y") ?? 0;
                uint width    = cline.GetUInt("width") ?? 0;
                uint height   = cline.GetUInt("height") ?? 0;
                int  xOffset  = cline.GetInt("xoffset") ?? 0;
                int  yOffset  = cline.GetInt("yoffset") ?? 0;
                int  xAdvance = cline.GetInt("xadvance") ?? 0;
                uint page     = cline.GetUInt("page") ?? 0;
                byte channel  = cline.GetByte("chnl") ?? 0;

                BMPFontCharacter c = new BMPFontCharacter(charId, x, y, width, height,
                                                          xOffset, yOffset, xAdvance, page, channel);

                chars.Add(c.Character, c);
            }

            return(chars);
        }