コード例 #1
0
        internal void Draw(PrimitiveBatch primitiveBatch, string text, Vector2 position, Color color, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
        {
            StringProvider provider = new StringProvider(text);

            _colors[0] = color;
            DrawInternal(primitiveBatch, provider, position, _colors, 1, spacing, lineHeight, scale, rotation);
        }
コード例 #2
0
        Vector2 MeasureInternal(StringProvider text, float spacing, float lineHeight)
        {
            int  count        = text.Length;
            char previousChar = '\0';

            Vector2 position = Vector2.Zero;

            Vector2 size = Vector2.Zero;

            spacing = (float)Height * spacing;

            for (int idx = 0; idx < count; ++idx)
            {
                char  character = text[idx];
                Glyph glyph     = Find(character);

                if (glyph != null)
                {
                    if (previousChar != '\0')
                    {
                        float kerning = (float)glyph.Kerning(previousChar) / 10f;
                        position.X += kerning;
                        position.X += spacing;
                    }

                    previousChar = character;

                    position.X += glyph.Width;

                    size.X = Math.Max(size.X, position.X);
                    size.Y = position.Y + BaseLine - CapLine;
                }
                else if (text[idx] == '\n')
                {
                    position.X   = 0;
                    position.Y  += Height * lineHeight;
                    previousChar = '\0';
                }
            }

            return(size);
        }
コード例 #3
0
        void DrawInternal(PrimitiveBatch primitiveBatch, StringProvider text, Vector2 targetPosition, Color[] colors, float opacity, float spacing, float lineHeight, float scale, TextRotation rotation)
        {
            if (primitiveBatch.PrimitiveType != PrimitiveType.TriangleList)
            {
                throw new Exception("PrimitiveBatch has to be started with TriangleList primitive type.");
            }

            Vector2 right = new Vector2(1, 0);
            Vector2 down  = new Vector2(0, 1);

            switch (rotation)
            {
            case TextRotation.Rotate180:
                right = new Vector2(-1, 0);
                down  = new Vector2(0, -1);
                break;

            case TextRotation.Rotate270:
                right = new Vector2(0, 1);
                down  = new Vector2(-1, 0);
                break;

            case TextRotation.Rotate90:
                right = new Vector2(0, -1);
                down  = new Vector2(1, 0);
                break;
            }

            int  count        = text.Length;
            char previousChar = '\0';

            spacing = (float)Height * spacing * scale;

            Vector2 position = targetPosition;

            Color color;

            for (int idx = 0; idx < count; ++idx)
            {
                char  character = text[idx];
                Glyph glyph     = Find(character);

                if (glyph != null)
                {
                    if (previousChar != '\0')
                    {
                        float kerning = (float)glyph.Kerning(previousChar) / 10f;
                        position += right * (kerning * scale + spacing);
                    }

                    previousChar = character;

                    Vector2 pos = position + down * (scale * (glyph.Top - CapLine));

                    color = colors[idx % colors.Length] * opacity;

                    DrawGlyph(primitiveBatch, glyph, ref pos, ref color, scale, ref right, ref down);

                    position += right * (glyph.Width * scale);
                }
                else if (text[idx] == '\n')
                {
                    if (rotation == TextRotation.Rotate270 || rotation == TextRotation.Rotate90)
                    {
                        position.Y = targetPosition.Y;
                    }
                    else
                    {
                        position.X = targetPosition.X;
                    }

                    position    += down * (lineHeight * Height * scale);
                    previousChar = '\0';
                }
            }
        }
コード例 #4
0
        public Vector2 MeasureString(string text, float spacing, float lineHeight)
        {
            StringProvider provider = new StringProvider(text);

            return(MeasureInternal(provider, spacing, lineHeight));
        }
コード例 #5
0
        internal void Draw(PrimitiveBatch primitiveBatch, StringBuilder text, Vector2 position, Color[] colors, float opacity, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
        {
            StringProvider provider = new StringProvider(text);

            DrawInternal(primitiveBatch, provider, position, colors, opacity, spacing, lineHeight, scale, rotation);
        }