示例#1
0
        public int GetWidth(ref string text)
        {
            int w = 0;

            if (text != null)
            {
                AtlasChar prev = null;
                AtlasChar chr;
                for (int i = 0; i < text.Length; ++i)
                {
                    chr = GetChar(text[i]);
                    if (prev != null)
                    {
                        w += prev.GetKerning(text[i]);
                    }
                    w   += chr.Advance;
                    prev = chr;
                }

                //For the final character, we want to slice off the character spacing
                if (prev != null)
                {
                    w -= prev.Advance - prev.Image.Width;
                }
            }

            return(w);
        }
示例#2
0
        public void DrawText(AtlasFont font, ref string text, Vector2 position, Color4 color)
        {
            var pos = position;

            AtlasChar prev = null;
            AtlasChar chr;

            for (int i = 0; i < text.Length; ++i)
            {
                chr = font.GetChar(text[i]);

                if (prev != null)
                {
                    pos.X += prev.GetKerning(chr.Char);
                }

                if (chr.Image != null)
                {
                    DrawImage(chr.Image, pos, color);
                }

                pos.X += chr.Advance;
                prev   = chr;
            }
        }
示例#3
0
        public AtlasChar AddChar(char chr, int width, int height, int advance, int offsetX, int offsetY, Rectangle uvRect, bool rotate90)
        {
            if (chars.ContainsKey(chr))
            {
                throw new Exception(string.Format("Font already has character: '{0}' (U+{1:X4})", chr, (UInt16)chr));
            }

            var name = chr.ToString();

            AtlasImage image = null;

            if (width > 0)
            {
                image = new AtlasImage(Atlas, ref name, width, height, offsetX, offsetY, width, height, ref uvRect, rotate90);
            }

            var result = new AtlasChar(this, chr, advance, image);

            chars.Add(chr, result);

            return(result);
        }
示例#4
0
 public bool TryGetchar(char chr, out AtlasChar result)
 {
     return(chars.TryGetValue(chr, out result));
 }