public static FontFile Load(String filename)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(FontFile));
            TextReader    textReader   = new StreamReader(filename);
            FontFile      file         = (FontFile)deserializer.Deserialize(textReader);

            textReader.Close();
            return(file);
        }
Example #2
0
        public static FontFile LoadFromString(String text)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(FontFile));
            TextReader    textReader   = new StreamReader(GenerateStreamFromString(text));

            FontFile file = ( FontFile )deserializer.Deserialize(textReader);

            textReader.Close( );
            return(file);
        }
Example #3
0
        public FontRenderer(FontFile fontFile, Texture2D fontTexture)
        {
            _fontFile     = fontFile;
            _texture      = fontTexture;
            _characterMap = new Dictionary <char, FontChar>();

            foreach (var fontCharacter in _fontFile.Chars)
            {
                char c = (char)fontCharacter.ID;
                _characterMap.Add(c, fontCharacter);
            }
        }
Example #4
0
        public FontRenderer(FontFile fontFile, Texture2D fontTexture)
        {
            _fontFile = fontFile;
            _texture = fontTexture;
            _characterMap = new Dictionary<char, FontChar>();

            foreach (var fontCharacter in _fontFile.Chars)
            {
                char c = (char)fontCharacter.ID;
                _characterMap.Add(c, fontCharacter);
            }
        }
Example #5
0
    protected TextLabel(SpriteRenderer spriteRenderer, FontFile fontFile, Texture2D texture)
        : base()
    {
        this.spriteRenderer = spriteRenderer;
        this.fontAtlas = texture;
        lineHeight = fontFile.Common.LineHeight;
        sprites = new List<Sprite>();
        characterMap = new Dictionary<char, FontChar>();

        foreach(var fontCharacter in fontFile.Chars)
        {
            char c = (char) fontCharacter.ID;
            characterMap.Add(c, fontCharacter);
        }
    }
Example #6
0
        public FontRenderer(string fontFileName, string textureFileName, GraphicsDevice device)
        {
            var fontFile = FontLoader.Load(fontFileName);
            var textureStream = TitleContainer.OpenStream(textureFileName);
            var fontTexture = Texture2D.FromStream(device, textureStream);
            textureStream.Close();
            _fontFile = fontFile;
            _texture = fontTexture;
            _characterMap = new Dictionary<char, FontChar>();

            foreach (var fontCharacter in _fontFile.Chars)
            {
                var c = (char)fontCharacter.ID;
                _characterMap.Add(c, fontCharacter);
            }
        }
    public void InitializeFont()
    {
        if (fontConfig != null && fontMaterials.Length > 0) {
            _fontFile = FontLoader.LoadFromString(fontConfig.text);
            if (_fontFile.Pages.Count != fontMaterials.Length)
            {
                Debug.LogError("Materials count don't match!");
                return;
            }

            _indexLists = new List<List<int>>();
            for (int i = 0; i < _fontFile.Pages.Count; ++i)
                _indexLists.Add(new List<int>());

            _textureSize = new Vector2(_fontFile.Common.ScaleW, _fontFile.Common.ScaleH);
            _charMap = new Dictionary<int, SpriteChar>();
            for (int i = 0; i < _fontFile.Chars.Count; ++i) {
                SpriteChar sc = new SpriteChar();
                Rect rect = new Rect(_fontFile.Chars[i].X, _fontFile.Chars[i].Y,  _fontFile.Chars[i].Width, _fontFile.Chars[i].Height);
                sc.fontChar = _fontFile.Chars[i];
                sc.rect = rect;
                _charMap.Add(_fontFile.Chars[i].ID, sc);
            }

            Debug.Log("Font Initialized");
        }
    }