Пример #1
0
        /// <summary>
        /// Converts the font out of an OpenGLFont object.
        /// </summary>
        /// <param name="font">The OpenGLFont.</param>
        /// <returns>Font.</returns>
        public static System.Drawing.Font ConvertFont(OpenGLFont font)
        {
            FontStyle style;

            switch (font.Accessoire)
            {
            case TextAccessoire.Bold:
                style = FontStyle.Bold;
                break;

            case TextAccessoire.Italic:
                style = FontStyle.Italic;
                break;

            case TextAccessoire.Strikeout:
                style = FontStyle.Strikeout;
                break;

            case TextAccessoire.Underline:
                style = FontStyle.Underline;
                break;

            default:
                style = FontStyle.Regular;
                break;
            }

            return(new System.Drawing.Font(font.FontFamily, font.Size, style));
        }
Пример #2
0
 /// <summary>
 /// Initializes a new TextEntity class.
 /// </summary>
 /// <param name="text">The Text.</param>
 /// <param name="font">The Font.</param>
 /// <param name="color">The Color.</param>
 /// <param name="wrapWidth">The Wordwrap Width.</param>
 public TextEntity(string text, OpenGLFont font, Color color, int wrapWidth = 0)
 {
     if (wrapWidth > 0) text = text.WordWrap(wrapWidth);
     var gdiFont = OpenGLHelper.ConvertFont(font);
     Id = text.GetHashCode() + gdiFont.GetHashCode() + color.GetHashCode();
     _text = text;
     _font = gdiFont;
     _color = color;
 }
Пример #3
0
        /// <summary>
        /// Initializes a new TextEntity class.
        /// </summary>
        /// <param name="text">The Text.</param>
        /// <param name="font">The Font.</param>
        /// <param name="color">The Color.</param>
        /// <param name="wrapWidth">The Wordwrap Width.</param>
        public TextEntity(string text, OpenGLFont font, Color color, int wrapWidth = 0)
        {
            if (wrapWidth > 0)
            {
                text = text.WordWrap(wrapWidth);
            }
            var gdiFont = OpenGLHelper.ConvertFont(font);

            Id     = text.GetHashCode() + gdiFont.GetHashCode() + color.GetHashCode();
            _text  = text;
            _font  = gdiFont;
            _color = color;
        }
Пример #4
0
        /// <summary>
        /// Gets the font texture.
        /// </summary>
        /// <param name="text">The Text.</param>
        /// <param name="font">The Font.</param>
        /// <param name="color">The Color.</param>
        /// <param name="wrapWidth">The WrapWidth.</param>
        /// <returns></returns>
        public OpenGLTexture GetFontTexture(string text, OpenGLFont font, Color color, int wrapWidth = 0)
        {
            var textEntity = new TextEntity(text, font, color, wrapWidth);
            if (_cache.ContainsKey(textEntity.Id))
            {
                return _cache[textEntity.Id].Texture;
            }

            if (_cache.Count > MaxEntityCache)
            {
                var entity = _cache.Values.First();
                _cache.Remove(entity.Id);
            }

            textEntity.DrawText();
            _cache.Add(textEntity.Id, textEntity);
            return textEntity.Texture;
        }
Пример #5
0
        /// <summary>
        /// Gets the font texture.
        /// </summary>
        /// <param name="text">The Text.</param>
        /// <param name="font">The Font.</param>
        /// <param name="color">The Color.</param>
        /// <param name="wrapWidth">The WrapWidth.</param>
        /// <returns></returns>
        public OpenGLTexture GetFontTexture(string text, OpenGLFont font, Color color, int wrapWidth = 0)
        {
            var textEntity = new TextEntity(text, font, color, wrapWidth);

            if (_cache.ContainsKey(textEntity.Id))
            {
                return(_cache[textEntity.Id].Texture);
            }

            if (_cache.Count > MaxEntityCache)
            {
                var entity = _cache.Values.First();
                _cache.Remove(entity.Id);
            }

            textEntity.DrawText();
            _cache.Add(textEntity.Id, textEntity);
            return(textEntity.Texture);
        }
Пример #6
0
        /// <summary>
        /// Converts the font out of an OpenGLFont object.
        /// </summary>
        /// <param name="font">The OpenGLFont.</param>
        /// <returns>Font.</returns>
        public static System.Drawing.Font ConvertFont(OpenGLFont font)
        {
            FontStyle style;
            switch (font.Accessoire)
            {
                case TextAccessoire.Bold:
                    style = FontStyle.Bold;
                    break;
                case TextAccessoire.Italic:
                    style = FontStyle.Italic;
                    break;
                case TextAccessoire.Strikeout:
                    style = FontStyle.Strikeout;
                    break;
                case TextAccessoire.Underline:
                    style = FontStyle.Underline;
                    break;
                default:
                    style = FontStyle.Regular;
                    break;
            }

            return new System.Drawing.Font(font.FontFamily, font.Size, style);
        }