/// <summary> /// Creates an array of <see cref="TextureFont"/>-s from the <see cref="TrippyFontFile"/>. /// </summary> /// <param name="font">The <see cref="TrippyFontFile"/> to create fonts from.</param> /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> the <see cref="TextureFont"/>-s will use.</param> /// <param name="generateMipmaps">Whether to generate mipmaps for the texture's font.</param> public static TextureFont[] CreateFonts(this TrippyFontFile font, GraphicsDevice graphicsDevice, bool generateMipmaps = false) { if (graphicsDevice == null) { throw new ArgumentNullException(nameof(graphicsDevice)); } if (font == null) { throw new ArgumentNullException(nameof(font)); } font.ThrowIfAnyNull(); Texture2D texture = new Texture2D(graphicsDevice, (uint)font.Image.Width, (uint)font.Image.Height, generateMipmaps); try { TextureFont[] textureFonts = new TextureFont[font.FontDatas.Length]; for (int i = 0; i < textureFonts.Length; i++) { textureFonts[i] = font.FontDatas[i].CreateFont(texture); } texture.SetData(font.Image); return(textureFonts); } catch { texture.Dispose(); throw; } }
/// <summary> /// Creates an array of <see cref="TextureFont"/>-s by loading them from a trippy font file. /// </summary> /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> the <see cref="TextureFont"/>-s will use.</param> /// <param name="streamReader">The stream where the trippy font file is located.</param> /// <param name="generateMipmaps">Whether to generate mipmaps for the texture's font.</param> public static TextureFont[] FromStream(GraphicsDevice graphicsDevice, BinaryReader streamReader, bool generateMipmaps = false) { using TrippyFontFile fontFile = TrippyFontFile.FromStream(streamReader); return(fontFile.CreateFonts(graphicsDevice, generateMipmaps)); }
/// <summary> /// Creates an array of <see cref="TextureFont"/>-s by loading them from a trippy font file. /// </summary> /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> the <see cref="TextureFont"/>-s will use.</param> /// <param name="file">The file on disk where the trippy font file is located.</param> /// <param name="generateMipmaps">Whether to generate mipmaps for the texture's font.</param> public static TextureFont[] FromFile(GraphicsDevice graphicsDevice, string file, bool generateMipmaps = false) { using TrippyFontFile fontFile = TrippyFontFile.FromFile(file); return(fontFile.CreateFonts(graphicsDevice, generateMipmaps)); }
/// <summary> /// Creates a single <see cref="TextureFont"/> from the <see cref="TrippyFontFile"/>. /// </summary> /// <param name="font">The <see cref="TrippyFontFile"/> to create fonts from.</param> /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> the <see cref="TextureFont"/> will use.</param> /// <param name="generateMipmaps">Whether to generate mipmaps for the texture's font.</param> public static TextureFont CreateFont(this TrippyFontFile font, GraphicsDevice graphicsDevice, bool generateMipmaps = false) { return(font.CreateFonts(graphicsDevice, generateMipmaps)[0]); }