/// <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); }
/// <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), }); }
static void Main(string[] args) { var library = new FreeTypeLibrary(); FT_Library_Version(library.Native, out var major, out var minor, out var patch); Console.WriteLine($"FreeType version: {major}.{minor}.{patch}"); Console.WriteLine($"FreeType native path: {NativeLibraryLoader.NativeLibraryPath}"); }
protected override void Initialize() { var library = new FreeTypeLibrary(); FT_Library_Version(library.Native, out var major, out var minor, out var patch); Console.WriteLine($"FreeType version: {major}.{minor}.{patch}"); Console.WriteLine($"FreeType path: {NativeLibraryLoader.NativeLibraryPath}"); base.Initialize(); }
/// <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), }; }
/// <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 FreeType(FreeTypeLibrary freeTypeLibrary) { this.freeTypeLibrary = freeTypeLibrary; disposables = new List <IDisposable>(); }