GetStringLength() public method

public GetStringLength ( string text, float scale, float kerning ) : float
text string
scale float
kerning float
return float
Example #1
0
        public void AddString(Font font, string text, float x, float y, float z, float scale, float kerning, float rotation_x, float rotation_y, float rotation_z, Color color)
        {
            float a, b, c, d, e, f;

            float half_width  = font.GetStringLength(text, scale, kerning) / 2;
            float half_height = font.regions[0].height / 2.0f * scale;

            Matrix matrix = Matrix.Identity;

            if (rotation_z != 0 || rotation_x != 0 || rotation_y != 0)
            {
                a = (float)Math.Cos(rotation_x);
                b = (float)Math.Sin(rotation_x);

                c = (float)Math.Cos(rotation_y);
                d = (float)Math.Sin(rotation_y);

                e = (float)Math.Cos(rotation_z);
                f = (float)Math.Sin(rotation_z);

                matrix.M11 = (c * e);
                matrix.M12 = (c * f);
                matrix.M13 = -d;
                matrix.M21 = (e * b * d - a * f);
                matrix.M22 = ((e * a) + (f * b * d));
                matrix.M23 = (b * c);
                matrix.M31 = (e * a * d + b * f);
                matrix.M33 = (a * c);
                matrix.M32 = -(b * e - f * a * d);
            }

            matrix.M41 = x + half_width;
            matrix.M42 = y + half_height;
            matrix.M43 = z;

            TextureRegion region; float offset = 0;

            for (int i = 0; i < text.Length; i++)
            {
                a = offset - half_width;
                b = -half_height;
                c = z;

                d = (((a * matrix.M11) + (b * matrix.M21)) + (c * matrix.M31)) + matrix.M41;
                e = (((a * matrix.M12) + (b * matrix.M22)) + (c * matrix.M32)) + matrix.M42;
                f = (((a * matrix.M13) + (b * matrix.M23)) + (c * matrix.M33)) + matrix.M43;

                region = font.regions[font.char_set.IndexOf(text[i])];
                Add(region, color, d, e, f, region.width * scale, region.height * scale, rotation_x, rotation_y, rotation_z);
                offset += region.width * scale + kerning;
            }
        }
Example #2
0
        public void AddString(Font font, string text, float x, float y, float z, float scale, float kerning, float rotation_x, float rotation_y, float rotation_z, Color color)
        {
            float a, b, c, d, e, f;

            float half_width = font.GetStringLength(text, scale, kerning) / 2;
            float half_height = font.regions[0].height / 2.0f * scale;

            Matrix matrix = Matrix.Identity;
            if (rotation_z != 0 || rotation_x != 0 || rotation_y != 0)
            {
                a = (float)Math.Cos(rotation_x);
                b = (float)Math.Sin(rotation_x);

                c = (float)Math.Cos(rotation_y);
                d = (float)Math.Sin(rotation_y);

                e = (float)Math.Cos(rotation_z);
                f = (float)Math.Sin(rotation_z);

                matrix.M11 = (c * e);
                matrix.M12 = (c * f);
                matrix.M13 = -d;
                matrix.M21 = (e * b * d - a * f);
                matrix.M22 = ((e * a) + (f * b * d));
                matrix.M23 = (b * c);
                matrix.M31 = (e * a * d + b * f);
                matrix.M33 = (a * c);
                matrix.M32 = -(b * e - f * a * d);
            }

            matrix.M41 = x + half_width;
            matrix.M42 = y + half_height;
            matrix.M43 = z;

            TextureRegion region; float offset = 0;
            for (int i = 0; i < text.Length; i++)
            {
                a = offset - half_width;
                b = -half_height;
                c = z;

                d = (((a * matrix.M11) + (b * matrix.M21)) + (c * matrix.M31)) + matrix.M41;
                e = (((a * matrix.M12) + (b * matrix.M22)) + (c * matrix.M32)) + matrix.M42;
                f = (((a * matrix.M13) + (b * matrix.M23)) + (c * matrix.M33)) + matrix.M43;

                region = font.regions[font.char_set.IndexOf(text[i])];
                Add(region, color, d, e, f, region.width * scale, region.height * scale, rotation_x, rotation_y, rotation_z);
                offset += region.width * scale + kerning;
            }
        }