public static FormattedText Create(string text, Font font, TextAlignment alignment, SizeConstraint constraint)
        {
            if (text == null)
            {
                return new FormattedText(null, new Box2(0, 0, 0, 0), text, font, alignment, constraint);
            }
            else
            {
                var instances = new List<GlyphInstance>(text.Length);
                var x = 0f;

                foreach (var c in text)
                {
                    var glyph = font.GetGlyph(c);

                    if (glyph != null)
                    {
                        instances.Add(new GlyphInstance(new Box2(x, 0, glyph.Size.X, glyph.Size.Y), glyph.Sprite));
                        x += glyph.Size.X;
                    }
                }

                return new FormattedText(instances, new Box2(0, 0, x, font.Height), text, font, alignment, constraint);
            }
        }
 private FormattedText(List<GlyphInstance> instances, Box2 bounds, string text, Font font, TextAlignment alignment, SizeConstraint constraint)
 {
     m_instances = instances;
     Bounds = bounds;
     Text = text;
     Font = font;
     Alignment = alignment;
     Constraint = constraint;
 }
Example #3
0
 public Glyph(Font font, GlyphInfo info)
 {
     Font = font;
     Character = info.Character;
     Size = info.TextureBox.Size;
     Sprite = new Sprite(
         font.Texture,
         info.TextureBox.Position / (Vector2)font.Texture.Size,
         (info.TextureBox.Position + info.TextureBox.Size) / (Vector2)font.Texture.Size
     );
 }
Example #4
0
        public void Draw(Vector2 position, Font font, string text, Color4ub color)
        {
            foreach (var c in text)
            {
                var glyph = font.GetGlyph(c);

                if (glyph != null)
                {
                    Draw(new Box2(position, glyph.Size), glyph.Sprite, color);
                    position = new Vector2(position.X + glyph.Size.X, position.Y);
                }
            }
        }
Example #5
0
 public void Draw(Vector2 position, Font font, string text)
 {
     Draw(position, font, text, new Color4ub(0xFF, 0xFF, 0xFF, 0xFF));
 }
        static InternalFonts()
        {
            s_texture = new Lazy<Texture2D>(() =>
            {
                var bytes = new byte[c_width * c_height];

                using (var mstream = new MemoryStream(s_bytes))
                {
                    using (var cstream = new GZipStream(mstream, CompressionMode.Decompress))
                    {
                        cstream.Read(bytes, 0, bytes.Length);
                    }
                }

                var pixels = new Color4ub[c_width * c_height * 4];

                for (int i = 0; i < c_width * c_height; i++)
                {
                    pixels[i] = new Color4ub(0xFF, 0xFF, 0xFF, bytes[i]);
                }

                var texture = new Texture2D();
                texture.SetData(c_width, c_height, pixels);
                return texture;
            });

            s_regularSmallVariableWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_regularSmallVariableWidthFontGlyphs);

                return font;
            });

            s_boldSmallVariableWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_boldSmallVariableWidthFontGlyphs);

                return font;
            });

            s_italicSmallVariableWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_italicSmallVariableWidthFontGlyphs);

                return font;
            });

            s_regularBigVariableWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_regularBigVariableWidthFontGlyphs);

                return font;
            });

            s_regularSmallFixedWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_regularSmallFixedWidthFontGlyphs);

                return font;
            });

            s_boldSmallFixedWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_boldSmallFixedWidthFontGlyphs);

                return font;
            });

            s_italicSmallFixedWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_italicSmallFixedWidthFontGlyphs);

                return font;
            });

            s_regularBigFixedWidthFont = new Lazy<Font>(() =>
            {
                var font = new Font(s_texture.Value, s_regularBigFixedWidthFontGlyphs);

                return font;
            });
        }