/// <summary> /// Loads an <see cref="EffectData"/> from the specified stream. /// </summary> /// <param name="device">The graphics device</param> /// <param name="stream">The stream.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="EffectData"/>. Null if the stream is not a serialized <see cref="EffectData"/>.</returns> /// <remarks> /// </remarks> public static SpriteFont Load(GraphicsDevice device, Stream stream, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { var spriteFontData = SpriteFontData.Load(stream, bitmapDataLoader); if (spriteFontData == null) { return(null); } return(New(device, spriteFontData)); }
/// <summary> /// Loads an <see cref="EffectData"/> from the specified stream. /// </summary> /// <param name="device">The graphics device</param> /// <param name="stream">The stream.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="EffectData"/>. Null if the stream is not a serialized <see cref="EffectData"/>.</returns> /// <remarks> /// </remarks> public static SpriteFont Load(GraphicsDevice device, Stream stream, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { var spriteFontData = SpriteFontData.Load(stream, bitmapDataLoader); if (spriteFontData == null) { return(null); } // the SpriteFontData is loaded here and will be used only in the current SpriteFont instance // therefore it is safe to dispose it's Texture2D instances, if any. return(New(device, spriteFontData, true)); }
/// <summary> /// Loads a <see cref="SpriteFontData"/> from the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="SpriteFontData"/>. Null if the stream is not a serialized <see cref="SpriteFontData"/>.</returns> public static SpriteFontData Load(Stream stream, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { var serializer = new BinarySerializer(stream, SerializerMode.Read, Text.Encoding.ASCII) { ArrayLengthType = ArrayLengthType.Int }; var data = new SpriteFontData(); var magicCode = FourCC.Empty; serializer.Serialize(ref magicCode); if (magicCode == "DXTK") { data.SerializeMakeSpriteFont(serializer); } else if (magicCode == new FourCC(0x03464D42)) // BMF\3 { data.SerializeBMFFont(serializer); } else { return(null); } // Glyphs are null, then this is not a SpriteFondData if (data.Glyphs == null) { return(null); } if (bitmapDataLoader != null) { foreach (var bitmap in data.Bitmaps) { // If the bitmap data is a string, then this is a texture to load if (bitmap.Data is string) { bitmap.Data = bitmapDataLoader((string)bitmap.Data); } } } return(data); }
/// <summary> /// Loads a <see cref="SpriteFontData"/> from the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="SpriteFontData"/>. Null if the stream is not a serialized <see cref="SpriteFontData"/>.</returns> public static SpriteFontData Load(Stream stream, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { var serializer = new BinarySerializer(stream, SerializerMode.Read, Text.Encoding.ASCII) {ArrayLengthType = ArrayLengthType.Int}; var data = new SpriteFontData(); var magicCode = FourCC.Empty; serializer.Serialize(ref magicCode); if (magicCode == "DXTK") { data.SerializeMakeSpriteFont(serializer); } else if (magicCode == new FourCC(0x03464D42)) // BMF\3 { data.SerializeBMFFont(serializer); } else { return null; } // Glyphs are null, then this is not a SpriteFondData if (data.Glyphs == null) return null; if (bitmapDataLoader != null) { foreach (var bitmap in data.Bitmaps) { // If the bitmap data is a string, then this is a texture to load if (bitmap.Data is string) { bitmap.Data = bitmapDataLoader((string) bitmap.Data); } } } return data; }
/// <summary> /// Loads a <see cref="SpriteFontData"/> from the specified stream. /// </summary> /// <param name="fileName">The filename.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="SpriteFontData"/>. Null if the stream is not a serialized <see cref="SpriteFontData"/>.</returns> public static SpriteFontData Load(string fileName, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { using (var stream = new NativeFileStream(fileName, NativeFileMode.Open, NativeFileAccess.Read)) return Load(stream, bitmapDataLoader); }
/// <summary> /// Loads a <see cref="SpriteFontData"/> from the specified stream. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="SpriteFontData"/>. Null if the stream is not a serialized <see cref="SpriteFontData"/>.</returns> public static SpriteFontData Load(byte[] buffer, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { return Load(new MemoryStream(buffer), bitmapDataLoader); }
/// <summary> /// Loads an <see cref="EffectData"/> from the specified buffer. /// </summary> /// <param name="device">The graphics device</param> /// <param name="buffer">The buffer.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="EffectData"/> </returns> public static SpriteFont Load(GraphicsDevice device, byte[] buffer, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { return(Load(device, new MemoryStream(buffer), bitmapDataLoader)); }
/// <summary> /// Loads a <see cref="SpriteFontData"/> from the specified stream. /// </summary> /// <param name="fileName">The filename.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="SpriteFontData"/>. Null if the stream is not a serialized <see cref="SpriteFontData"/>.</returns> public static SpriteFontData Load(string fileName, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { using (var stream = new NativeFileStream(fileName, NativeFileMode.Open, NativeFileAccess.Read)) return(Load(stream, bitmapDataLoader)); }
/// <summary> /// Loads a <see cref="SpriteFontData"/> from the specified stream. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="SpriteFontData"/>. Null if the stream is not a serialized <see cref="SpriteFontData"/>.</returns> public static SpriteFontData Load(byte[] buffer, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { return(Load(new MemoryStream(buffer), bitmapDataLoader)); }
/// <summary> /// Loads an <see cref="EffectData"/> from the specified buffer. /// </summary> /// <param name="device">The graphics device</param> /// <param name="buffer">The buffer.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="EffectData"/> </returns> public static SpriteFont Load(GraphicsDevice device, byte[] buffer, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { return Load(device, new MemoryStream(buffer), bitmapDataLoader); }
/// <summary> /// Loads an <see cref="EffectData"/> from the specified stream. /// </summary> /// <param name="device">The graphics device</param> /// <param name="stream">The stream.</param> /// <param name="bitmapDataLoader">A delegate to load bitmap data that are not stored in the buffer.</param> /// <returns>An <see cref="EffectData"/>. Null if the stream is not a serialized <see cref="EffectData"/>.</returns> /// <remarks> /// </remarks> public static SpriteFont Load(GraphicsDevice device, Stream stream, SpriteFontBitmapDataLoaderDelegate bitmapDataLoader = null) { var spriteFontData = SpriteFontData.Load(stream, bitmapDataLoader); if (spriteFontData == null) return null; return New(device, spriteFontData); }