Example #1
0
        void ReadCharacter(List <BitmapChar> chars, string[] charData)
        {
            BitmapChar bitmapChar = new BitmapChar();

            foreach (string item in charData)
            {
                object value = "";
                string key   = GetKeyValue(item, out value);

                switch (key)
                {
                case "id":
                    bitmapChar.id = Convert.ToInt32(value);
                    break;

                case "page":
                    bitmapChar.page = Convert.ToInt32(value);
                    break;

                case "chnl":
                    bitmapChar.chnl = Convert.ToInt32(value);
                    break;

                case "xadvance":
                    bitmapChar.xAdvance = Convert.ToInt32(value);
                    break;

                case "x":
                    bitmapChar.position.x = float.Parse(value as string, System.Globalization.NumberFormatInfo.InvariantInfo);
                    break;

                case "y":
                    bitmapChar.position.y = float.Parse(value as string, System.Globalization.NumberFormatInfo.InvariantInfo);
                    break;

                case "width":
                    bitmapChar.size.x = float.Parse(value as string, System.Globalization.NumberFormatInfo.InvariantInfo);
                    break;

                case "height":
                    bitmapChar.size.y = float.Parse(value as string, System.Globalization.NumberFormatInfo.InvariantInfo);
                    break;

                case "xoffset":
                    bitmapChar.offset.x = float.Parse(value as string, System.Globalization.NumberFormatInfo.InvariantInfo);
                    break;

                case "yoffset":
                    bitmapChar.offset.y = float.Parse(value as string, System.Globalization.NumberFormatInfo.InvariantInfo);
                    break;
                }
            }
            chars.Add(bitmapChar);
        }
Example #2
0
        public Rect GetUVRect(BitmapChar bitmapChar)
        {
            //Convert positions/scale from AngleCode-format (pixels, top left origin) to uv format (0-1, bottom left origin)
            Vector2 scaledSize = new Vector2(bitmapChar.size.x / m_ScaleW, bitmapChar.size.y / m_ScaleH);
            Vector2 scaledPos  = new Vector2(bitmapChar.position.x / m_ScaleW, bitmapChar.position.y / m_ScaleH);
            Vector2 uvCharPos  = new Vector2(scaledPos.x, 1 - (scaledPos.y + scaledSize.y));

            //Scale and translate according to page atlas
            Rect offset = m_PageOffsets[bitmapChar.page];

            uvCharPos  = new Vector2(uvCharPos.x * offset.width + offset.xMin, uvCharPos.y * offset.height + offset.yMin);
            scaledSize = new Vector2(scaledSize.x * offset.width, scaledSize.y * offset.height);

            return(new Rect(uvCharPos.x, uvCharPos.y, scaledSize.x, scaledSize.y));
        }
Example #3
0
        public Vector2 CalculateSize(string str, Vector2 renderSize)
        {
            Vector2 curPos = new Vector2(0, renderSize.y);
            Vector2 scale  = renderSize / m_Size;

            for (int idx = 0; idx < str.Length; idx++)
            {
                char       c        = str[idx];
                BitmapChar charInfo = GetBitmapChar((int)c);

                float krn = 0;
                if (idx < str.Length - 1)
                {
                    krn = GetKerning(c, str[idx + 1]);
                }
                curPos.x += (charInfo.xAdvance + krn) * scale.x;
            }

            return(curPos);
        }
Example #4
0
        public Rect GetUVRect(int c)
        {
            BitmapChar bitmapChar = GetBitmapChar(c);

            return(GetUVRect(bitmapChar));
        }