Exemple #1
0
        public void TestFloatParameters()
        {
            TagText tagText = new TagText();

            tagText.Load("<a b=0.0 c=-1.1 d=1.1>TEST</a>");

            Assert.AreEqual("TEST", tagText.Text);

            foreach (TagText.Node node in tagText.Nodes)
            {
                TagText.Parameter b = node.Parameters[0];
                Assert.AreEqual("b", b.Name);
                Assert.AreEqual("0.0", b.Value);
                Assert.AreEqual(0.0f, b.GetFloat());

                TagText.Parameter c = node.Parameters[1];
                Assert.AreEqual("c", c.Name);
                Assert.AreEqual("-1.1", c.Value);
                Assert.AreEqual(-1.1f, c.GetFloat());

                TagText.Parameter d = node.Parameters[2];
                Assert.AreEqual("d", d.Name);
                Assert.AreEqual("1.1", d.Value);
                Assert.AreEqual(1.1f, d.GetFloat());
            }
        }
Exemple #2
0
        public void TestIntegerParameters()
        {
            TagText tagText = new TagText();

            tagText.Load("<a b=0 c=-1 d=1>TEST</a>");

            Assert.AreEqual("TEST", tagText.Text);

            foreach (TagText.Node node in tagText.Nodes)
            {
                TagText.Parameter b = node.Parameters[0];
                Assert.AreEqual("b", b.Name);
                Assert.AreEqual("0", b.Value);
                Assert.AreEqual(0, b.GetInteger());

                TagText.Parameter c = node.Parameters[1];
                Assert.AreEqual("c", c.Name);
                Assert.AreEqual("-1", c.Value);
                Assert.AreEqual(-1, c.GetInteger());

                TagText.Parameter d = node.Parameters[2];
                Assert.AreEqual("d", d.Name);
                Assert.AreEqual("1", d.Value);
                Assert.AreEqual(1, d.GetInteger());
            }
        }
Exemple #3
0
        public string TestText(string _Text)
        {
            TagText tagText = new TagText();

            tagText.Load(_Text);
            return(tagText.Text);
        }
Exemple #4
0
        public void TestBoolParameters()
        {
            TagText tagText = new TagText();

            tagText.Load("<a b=true c=True d=false e=False>TEST</a>");

            Assert.AreEqual("TEST", tagText.Text);

            foreach (TagText.Node node in tagText.Nodes)
            {
                TagText.Parameter b = node.Parameters[0];
                Assert.AreEqual("b", b.Name);
                Assert.AreEqual("true", b.Value);
                Assert.AreEqual(true, b.GetBool());

                TagText.Parameter c = node.Parameters[1];
                Assert.AreEqual("c", c.Name);
                Assert.AreEqual("True", c.Value);
                Assert.AreEqual(true, c.GetBool());

                TagText.Parameter d = node.Parameters[2];
                Assert.AreEqual("d", d.Name);
                Assert.AreEqual("false", d.Value);
                Assert.AreEqual(false, d.GetBool());

                TagText.Parameter e = node.Parameters[3];
                Assert.AreEqual("e", e.Name);
                Assert.AreEqual("False", e.Value);
                Assert.AreEqual(false, e.GetBool());
            }
        }
Exemple #5
0
        public void TestColorParameters()
        {
            TagText tagText = new TagText();

            tagText.Load("<a b=#FFFFFFFF c=#000000FF d=#FF0000FF e=#00FF00FF f=#0000FFFF>TEST</a>");

            Assert.AreEqual("TEST", tagText.Text);

            foreach (TagText.Node node in tagText.Nodes)
            {
                TagText.Parameter white = node.Parameters[0];
                Assert.AreEqual("b", white.Name);
                Assert.AreEqual("#FFFFFFFF", white.Value);
                Assert.AreEqual(Color.white, white.GetColor());

                TagText.Parameter black = node.Parameters[1];
                Assert.AreEqual("c", black.Name);
                Assert.AreEqual("#000000FF", black.Value);
                Assert.AreEqual(Color.black, black.GetColor());

                TagText.Parameter red = node.Parameters[2];
                Assert.AreEqual("d", red.Name);
                Assert.AreEqual("#FF0000FF", red.Value);
                Assert.AreEqual(Color.red, red.GetColor());

                TagText.Parameter green = node.Parameters[3];
                Assert.AreEqual("e", green.Name);
                Assert.AreEqual("#00FF00FF", green.Value);
                Assert.AreEqual(Color.green, green.GetColor());

                TagText.Parameter blue = node.Parameters[4];
                Assert.AreEqual("f", blue.Name);
                Assert.AreEqual("#0000FFFF", blue.Value);
                Assert.AreEqual(Color.blue, blue.GetColor());
            }
        }
Exemple #6
0
    void ProcessCharacters()
    {
        Scale = 1;

        if (m_TagText == null)
        {
            m_TagText = new TagText();
        }

        m_TagText.Load(Text);

        if (m_Lines == null)
        {
            m_Lines = new List <BitmapLine>();
        }
        else
        {
            m_Lines.Clear();
        }

        if (m_Characters == null)
        {
            m_Characters = new List <BitmapCharacter>();
        }

        int delta = m_TagText.Text.Length - m_Characters.Count;

        for (int i = 0; i < delta; i++)
        {
            m_Characters.Add(new BitmapCharacter());
        }

        for (int i = 0; i < m_Characters.Count; i++)
        {
            if (m_Characters[i] == null)
            {
                m_Characters[i] = new BitmapCharacter();
            }

            BitmapCharacter character = m_Characters[i];

            character.Index   = -1;
            character.Enabled = false;
            character.Visible = false;
            character.Tint    = Color.white;
            character.Offset  = Vector2.zero;
        }

        List <BitmapCharacter> line = new List <BitmapCharacter>();
        int index = 0;

        for (int i = 0; i < m_TagText.Text.Length; i++)
        {
            if (m_TagText.Text[i] == '\n')
            {
                m_Lines.Add(new BitmapLine(line));
                line.Clear();

                index++;
                continue;
            }

            BitmapCharacter character = m_Characters[index];

            character.Index     = i;
            character.Enabled   = true;
            character.Character = m_TagText.Text[i];

            BitmapGlyph glyph = Font.GetGlyph(character.Character);
            if (glyph != null)
            {
                Rect glyphRect = glyph.Rect;
                character.Visible        = true;
                character.Rect           = glyphRect.Scale(CharSize);
                character.BaselineOffset = glyph.Offset * CharSize;
                character.LineHeight     = Font.Ascender * CharSize;
                character.UV             = glyph.UV;
                character.Color          = color;
            }
            else if (character.Character == ' ')
            {
                Rect glyphRect = new Rect(0, 0, Font.SpaceWidth, 0);

                character.Visible = false;
                character.Rect    = glyphRect.Scale(CharSize);
            }

            line.Add(character);

            index++;
        }
        m_Lines.Add(new BitmapLine(line));
        line.Clear();
    }