/// <summary>
        /// 用一个纹理绘制指定范围内的所有可见字符
        /// </summary>
        /// <param name="ttfFullname"></param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar"></param>
        /// <param name="lastChar"></param>
        /// <param name="maxTextureWidth">生成的纹理的最大宽度。</param>
        /// <returns></returns>
        public static FontTexture GetTTFTexture(string ttfFullname, int fontHeight, int maxTextureWidth, char firstChar, char lastChar)
        {
            FreeTypeLibrary library = new FreeTypeLibrary();

            FreeTypeFace face = new FreeTypeFace(library, ttfFullname);

            Dictionary <char, CharacterInfo> charInfoDict;
            int textureWidth, textureHeight;

            GetTextureBlueprint(face, fontHeight, maxTextureWidth, firstChar, lastChar, out charInfoDict, out textureWidth, out textureHeight);

            if (textureWidth == 0)
            {
                textureWidth = 1;
            }
            if (textureHeight == 0)
            {
                textureHeight = 1;
            }

            System.Drawing.Bitmap bigBitmap = GetBigBitmap(face, fontHeight, maxTextureWidth, firstChar, lastChar, charInfoDict, textureWidth, textureHeight);

            face.Dispose();
            library.Dispose();

            var result = new FontTexture()
            {
                TtfFullname = ttfFullname, FontHeight = fontHeight, FirstChar = firstChar, LastChar = lastChar, BigBitmap = bigBitmap, CharInfoDict = charInfoDict,
            };

            return(result);
        }
 public FontTexturePNGPrinter(CSharpGL.Texts.FontTexture ttfTexture)
 {
     // TODO: Complete member initialization
     this.ttfTexture = ttfTexture;
     this.font = new Font("微软雅黑", ttfTexture.FontHeight / 2);
     this.outputWidth = ttfTexture.FontHeight * 40;
 }
Example #3
0
 public FontTexturePNGPrinter(CSharpGL.Texts.FontTexture ttfTexture)
 {
     // TODO: Complete member initialization
     this.ttfTexture  = ttfTexture;
     this.font        = new Font("微软雅黑", ttfTexture.FontHeight / 2);
     this.outputWidth = ttfTexture.FontHeight * 40;
 }
        /// <summary>
        /// 用一个纹理绘制指定范围内的所有可见字符
        /// </summary>
        /// <param name="ttfFullname"></param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar"></param>
        /// <param name="lastChar"></param>
        /// <param name="maxTextureWidth">生成的纹理的最大宽度。</param>
        /// <returns></returns>
        public static IEnumerable <TTFTextureYeildingState> GetTTFTexture(
            string ttfFullname, int fontHeight, int maxTextureWidth, char firstChar, char lastChar)
        {
            FreeTypeLibrary library = new FreeTypeLibrary();

            FreeTypeFace face = new FreeTypeFace(library, ttfFullname);

            Dictionary <char, CharacterInfo> charInfoDict = null;
            int textureWidth = 0, textureHeight = 0;

            System.Drawing.Bitmap bigBitmap = null;

            foreach (var item in GetTextureBlueprint(face, fontHeight, maxTextureWidth, firstChar, lastChar))
            {
                charInfoDict  = item.dict;
                textureWidth  = item.textureWidth;
                textureHeight = item.textureHeight;

                yield return(item);
            }

            if (textureWidth == 0)
            {
                textureWidth = 1;
            }
            if (textureHeight == 0)
            {
                textureHeight = 1;
            }

            foreach (var item in GetBigBitmap(face, fontHeight, maxTextureWidth,
                                              firstChar, lastChar, charInfoDict, textureWidth, textureHeight))
            {
                bigBitmap = item.bigBitmap;

                yield return(item);
            }

            face.Dispose();
            library.Dispose();

            var result = new FontTexture()
            {
                TtfFullname  = ttfFullname,
                FontHeight   = fontHeight,
                FirstChar    = firstChar,
                LastChar     = lastChar,
                BigBitmap    = bigBitmap,
                CharInfoDict = charInfoDict,
            };

            FileInfo fileInfo = new FileInfo(ttfFullname);

            yield return(new TTFTextureYeildingState()
            {
                percent = 100,
                ttfTexture = result,
                message = string.Format("got font texture for {0}", fileInfo.Name),
            });
        }
Example #5
0
        /// <summary>
        /// 用一个纹理绘制指定范围内的可见字符
        /// </summary>
        /// <param name="fontFilename">字体文件名</param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar">要显示的第一个字符</param>
        /// <param name="lastChar">要显示的最后一个字符</param>
        public FontElement(string fontFilename, int fontHeight, char firstChar, char lastChar)
        {
            if (firstChar > lastChar) { throw new ArgumentException("first char should <= last char"); }

            int[] maxTextureWidth = new int[1];
            //	Get the maximum texture size supported by GL.
            GL.GetInteger(GetTarget.MaxTextureSize, maxTextureWidth);

            this.ttfTexture = FontTextureHelper.GetTTFTexture(fontFilename, fontHeight, maxTextureWidth[0], firstChar, lastChar);
        }
        /// <summary>
        /// 根据已经生成的贴图和附带的Xml配置文件得到一个<see cref="FontTexture"/>。
        /// <para>此贴图和Xml文件</para>
        /// </summary>
        /// <param name="textureFullname"></param>
        /// <param name="xmlFullname"></param>
        /// <returns></returns>
        public static FontTexture GetTTFTexture(string textureFullname, string xmlFullname)
        {
            XElement    ttfTextureElement = XElement.Load(xmlFullname); //new XElement(xmlFullname);
            FontTexture result            = Parse(ttfTextureElement);

            System.Drawing.Bitmap bigBitmap = new System.Drawing.Bitmap(textureFullname);
            result.BigBitmap = bigBitmap;

            return(result);
        }
        public static XElement ToXElement(this FontTexture texture)
        {
            XElement result = new XElement(strTTFTexture,
                                           new XAttribute(strFontHeight, texture.FontHeight),
                                           new XAttribute(strFirstChar, (int)texture.FirstChar),
                                           new XAttribute(strLastChar, (int)texture.LastChar),
                                           texture.CharInfoDict.ToXElement());

            return(result);
        }
Example #8
0
        private static FontTexture Parse(XElement xElement)
        {
            FontTexture result = new FontTexture();
            result.FontHeight = int.Parse(xElement.Attribute(strFontHeight).Value);
            result.FirstChar = (char)int.Parse(xElement.Attribute(strFirstChar).Value);
            result.LastChar = (char)int.Parse(xElement.Attribute(strLastChar).Value);
            result.CharInfoDict = CharacterInfoDictHelper.Parse(
                xElement.Element(CharacterInfoDictHelper.strCharacterInfoDict));

            return result;
        }
        private static FontTexture Parse(XElement xElement)
        {
            FontTexture result = new FontTexture();

            result.FontHeight   = int.Parse(xElement.Attribute(strFontHeight).Value);
            result.FirstChar    = (char)int.Parse(xElement.Attribute(strFirstChar).Value);
            result.LastChar     = (char)int.Parse(xElement.Attribute(strLastChar).Value);
            result.CharInfoDict = CharacterInfoDictHelper.Parse(
                xElement.Element(CharacterInfoDictHelper.strCharacterInfoDict));

            return(result);
        }
        /// <summary>
        /// 用一个纹理绘制指定范围内的所有可见字符
        /// </summary>
        /// <param name="ttfFullname"></param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar"></param>
        /// <param name="lastChar"></param>
        /// <param name="maxTextureWidth">生成的纹理的最大宽度。</param>
        /// <returns></returns>
        public static IEnumerable<TTFTextureYeildingState> GetTTFTexture(
            string ttfFullname, int fontHeight, int maxTextureWidth, char firstChar, char lastChar)
        {
            FreeTypeLibrary library = new FreeTypeLibrary();

            FreeTypeFace face = new FreeTypeFace(library, ttfFullname);

            Dictionary<char, CharacterInfo> charInfoDict = null;
            int textureWidth = 0, textureHeight = 0;
            System.Drawing.Bitmap bigBitmap = null;

            foreach (var item in GetTextureBlueprint(face, fontHeight, maxTextureWidth, firstChar, lastChar))
            {
                charInfoDict = item.dict;
                textureWidth = item.textureWidth;
                textureHeight = item.textureHeight;

                yield return item;
            }

            if (textureWidth == 0) { textureWidth = 1; }
            if (textureHeight == 0) { textureHeight = 1; }

            foreach (var item in GetBigBitmap(face, fontHeight, maxTextureWidth,
                firstChar, lastChar, charInfoDict, textureWidth, textureHeight))
            {
                bigBitmap = item.bigBitmap;

                yield return item;
            }

            face.Dispose();
            library.Dispose();

            var result = new FontTexture()
            {
                TtfFullname = ttfFullname,
                FontHeight = fontHeight,
                FirstChar = firstChar,
                LastChar = lastChar,
                BigBitmap = bigBitmap,
                CharInfoDict = charInfoDict,
            };

            FileInfo fileInfo = new FileInfo(ttfFullname);
            yield return new TTFTextureYeildingState()
            {
                percent = 100,
                ttfTexture = result,
                message = string.Format("got font texture for {0}", fileInfo.Name),
            };
        }
Example #11
0
        /// <summary>
        /// 用一个纹理绘制指定范围内的所有可见字符
        /// </summary>
        /// <param name="ttfFullname"></param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar"></param>
        /// <param name="lastChar"></param>
        /// <param name="maxTextureWidth">生成的纹理的最大宽度。</param>
        /// <returns></returns>
        public static FontTexture GetTTFTexture(string ttfFullname, int fontHeight, int maxTextureWidth, char firstChar, char lastChar)
        {
            FreeTypeLibrary library = new FreeTypeLibrary();

            FreeTypeFace face = new FreeTypeFace(library, ttfFullname);

            Dictionary<char, CharacterInfo> charInfoDict;
            int textureWidth, textureHeight;

            GetTextureBlueprint(face, fontHeight, maxTextureWidth, firstChar, lastChar, out charInfoDict, out textureWidth, out textureHeight);

            if (textureWidth == 0) { textureWidth = 1; }
            if (textureHeight == 0) { textureHeight = 1; }

            System.Drawing.Bitmap bigBitmap = GetBigBitmap(face, fontHeight, maxTextureWidth, firstChar, lastChar, charInfoDict, textureWidth, textureHeight);

            face.Dispose();
            library.Dispose();

            var result = new FontTexture() { TtfFullname = ttfFullname, FontHeight = fontHeight, FirstChar = firstChar, LastChar = lastChar, BigBitmap = bigBitmap, CharInfoDict = charInfoDict, };

            return result;
        }
Example #12
0
 public FontTextureXmlPrinter(CSharpGL.Texts.FontTexture ttfTexture)
 {
     // TODO: Complete member initialization
     this.ttfTexture = ttfTexture;
 }
 public FontTextureXmlPrinter(CSharpGL.Texts.FontTexture ttfTexture)
 {
     // TODO: Complete member initialization
     this.ttfTexture = ttfTexture;
 }
Example #14
0
 public FontTexturePNGPrinter(CSharpGL.Texts.FontTexture ttfTexture)
 {
     this.ttfTexture  = ttfTexture;
     this.font        = new Font("微软雅黑", ttfTexture.FontHeight / 2);
     this.outputWidth = ttfTexture.FontHeight * 40;
 }
 private void CreateTextureObject(FontTexture fontTexture)
 {
     this.texture = new Texture2D();
     this.texture.Initialize(fontTexture.BigBitmap);
 }
 /// <summary>
 /// 用一个纹理绘制指定范围内的可见字符
 /// </summary>
 /// <param name="fontFilename">字体文件名</param>
 /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
 /// <param name="firstChar">要显示的第一个字符</param>
 /// <param name="lastChar">要显示的最后一个字符</param>
 public WholeFontTextureElement(string textureFilename, string xmlFilename)
 {
     this.ttfTexture = FontTextureHelper.GetTTFTexture(textureFilename, xmlFilename);
 }
 public FontTexturePNGPrinter(CSharpGL.Texts.FontTexture ttfTexture)
 {
     this.ttfTexture = ttfTexture;
     this.font = new Font("微软雅黑", ttfTexture.FontHeight / 2);
     this.outputWidth = ttfTexture.FontHeight * 40;
 }