diff options
Diffstat (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts')
10 files changed, 320 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontChar.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontChar.cs new file mode 100644 index 0000000..c012da4 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontChar.cs @@ -0,0 +1,41 @@ +using System.Xml.Serialization; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + // ---- AngelCode BmFont XML serializer ---------------------- + // ---- By DeadlyDan @ deadlydan@gmail.com ------------------- + // ---- There's no license restrictions, use as you will. ---- + // ---- Credits to http://www.angelcode.com/ ----------------- + public class BitmapFontChar + { + [XmlAttribute("id")] + public int Id { get; set; } + + [XmlAttribute("x")] + public int X { get; set; } + + [XmlAttribute("y")] + public int Y { get; set; } + + [XmlAttribute("width")] + public int Width { get; set; } + + [XmlAttribute("height")] + public int Height { get; set; } + + [XmlAttribute("xoffset")] + public int XOffset { get; set; } + + [XmlAttribute("yoffset")] + public int YOffset { get; set; } + + [XmlAttribute("xadvance")] + public int XAdvance { get; set; } + + [XmlAttribute("page")] + public int Page { get; set; } + + [XmlAttribute("chnl")] + public int Channel { get; set; } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontCommon.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontCommon.cs new file mode 100644 index 0000000..6247fcf --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontCommon.cs @@ -0,0 +1,41 @@ +using System.Xml.Serialization; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + // ---- AngelCode BmFont XML serializer ---------------------- + // ---- By DeadlyDan @ deadlydan@gmail.com ------------------- + // ---- There's no license restrictions, use as you will. ---- + // ---- Credits to http://www.angelcode.com/ ----------------- + public class BitmapFontCommon + { + [XmlAttribute("lineHeight")] + public int LineHeight { get; set; } + + [XmlAttribute("base")] + public int Base { get; set; } + + [XmlAttribute("scaleW")] + public int ScaleW { get; set; } + + [XmlAttribute("scaleH")] + public int ScaleH { get; set; } + + [XmlAttribute("pages")] + public int Pages { get; set; } + + [XmlAttribute("packed")] + public int Packed { get; set; } + + [XmlAttribute("alphaChnl")] + public int AlphaChannel { get; set; } + + [XmlAttribute("redChnl")] + public int RedChannel { get; set; } + + [XmlAttribute("greenChnl")] + public int GreenChannel { get; set; } + + [XmlAttribute("blueChnl")] + public int BlueChannel { get; set; } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontFile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontFile.cs new file mode 100644 index 0000000..db77270 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontFile.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + // ---- AngelCode BmFont XML serializer ---------------------- + // ---- By DeadlyDan @ deadlydan@gmail.com ------------------- + // ---- There's no license restrictions, use as you will. ---- + // ---- Credits to http://www.angelcode.com/ ----------------- + [XmlRoot("font")] + public class BitmapFontFile + { + [XmlElement("info")] + public BitmapFontInfo Info { get; set; } + + [XmlElement("common")] + public BitmapFontCommon Common { get; set; } + + [XmlArray("pages")] + [XmlArrayItem("page")] + public List<BitmapFontPage> Pages { get; set; } + + [XmlArray("chars")] + [XmlArrayItem("char")] + public List<BitmapFontChar> Chars { get; set; } + + [XmlArray("kernings")] + [XmlArrayItem("kerning")] + public List<BitmapFontKerning> Kernings { get; set; } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontImporter.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontImporter.cs new file mode 100644 index 0000000..ea4c528 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontImporter.cs @@ -0,0 +1,22 @@ +using System.IO; +using System.Xml.Serialization; +using Microsoft.Xna.Framework.Content.Pipeline; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + [ContentImporter(".fnt", DefaultProcessor = "BitmapFontProcessor", + DisplayName = "BMFont Importer - MonoGame.Extended")] + public class BitmapFontImporter : ContentImporter<BitmapFontFile> + { + public override BitmapFontFile Import(string filename, ContentImporterContext context) + { + context.Logger.LogMessage("Importing XML file: {0}", filename); + + using (var streamReader = new StreamReader(filename)) + { + var deserializer = new XmlSerializer(typeof(BitmapFontFile)); + return (BitmapFontFile)deserializer.Deserialize(streamReader); + } + } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontInfo.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontInfo.cs new file mode 100644 index 0000000..1f50cf8 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontInfo.cs @@ -0,0 +1,47 @@ +using System.Xml.Serialization; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + // ---- AngelCode BmFont XML serializer ---------------------- + // ---- By DeadlyDan @ deadlydan@gmail.com ------------------- + // ---- There's no license restrictions, use as you will. ---- + // ---- Credits to http://www.angelcode.com/ ----------------- + public class BitmapFontInfo + { + [XmlAttribute("face")] + public string Face { get; set; } + + [XmlAttribute("size")] + public int Size { get; set; } + + [XmlAttribute("bold")] + public int Bold { get; set; } + + [XmlAttribute("italic")] + public int Italic { get; set; } + + [XmlAttribute("charset")] + public string CharSet { get; set; } + + [XmlAttribute("unicode")] + public int Unicode { get; set; } + + [XmlAttribute("stretchH")] + public int StretchHeight { get; set; } + + [XmlAttribute("smooth")] + public int Smooth { get; set; } + + [XmlAttribute("aa")] + public int SuperSampling { get; set; } + + [XmlAttribute("padding")] + public string Padding { get; set; } + + [XmlAttribute("spacing")] + public string Spacing { get; set; } + + [XmlAttribute("outline")] + public int OutLine { get; set; } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontKerning.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontKerning.cs new file mode 100644 index 0000000..77caf13 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontKerning.cs @@ -0,0 +1,20 @@ +using System.Xml.Serialization; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + // ---- AngelCode BmFont XML serializer ---------------------- + // ---- By DeadlyDan @ deadlydan@gmail.com ------------------- + // ---- There's no license restrictions, use as you will. ---- + // ---- Credits to http://www.angelcode.com/ ----------------- + public class BitmapFontKerning + { + [XmlAttribute("first")] + public int First { get; set; } + + [XmlAttribute("second")] + public int Second { get; set; } + + [XmlAttribute("amount")] + public int Amount { get; set; } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontPage.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontPage.cs new file mode 100644 index 0000000..3841ff5 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontPage.cs @@ -0,0 +1,17 @@ +using System.Xml.Serialization; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + // ---- AngelCode BmFont XML serializer ---------------------- + // ---- By DeadlyDan @ deadlydan@gmail.com ------------------- + // ---- There's no license restrictions, use as you will. ---- + // ---- Credits to http://www.angelcode.com/ ----------------- + public class BitmapFontPage + { + [XmlAttribute("id")] + public int Id { get; set; } + + [XmlAttribute("file")] + public string File { get; set; } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontProcessor.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontProcessor.cs new file mode 100644 index 0000000..a859eb5 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontProcessor.cs @@ -0,0 +1,33 @@ +using System; +using System.IO; +using Microsoft.Xna.Framework.Content.Pipeline; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + [ContentProcessor(DisplayName = "BMFont Processor - MonoGame.Extended")] + public class BitmapFontProcessor : ContentProcessor<BitmapFontFile, BitmapFontProcessorResult> + { + public override BitmapFontProcessorResult Process(BitmapFontFile bitmapFontFile, ContentProcessorContext context) + { + try + { + context.Logger.LogMessage("Processing BMFont"); + var result = new BitmapFontProcessorResult(bitmapFontFile); + + foreach (var fontPage in bitmapFontFile.Pages) + { + var assetName = Path.GetFileNameWithoutExtension(fontPage.File); + context.Logger.LogMessage("Expected texture asset: {0}", assetName); + result.TextureAssets.Add(assetName); + } + + return result; + } + catch (Exception ex) + { + context.Logger.LogMessage("Error {0}", ex); + throw; + } + } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontProcessorResult.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontProcessorResult.cs new file mode 100644 index 0000000..5841acc --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontProcessorResult.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + public class BitmapFontProcessorResult + { + public List<string> TextureAssets { get; private set; } + public BitmapFontFile FontFile { get; private set; } + + public BitmapFontProcessorResult(BitmapFontFile fontFile) + { + FontFile = fontFile; + TextureAssets = new List<string>(); + } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontWriter.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontWriter.cs new file mode 100644 index 0000000..343c40c --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/BitmapFonts/BitmapFontWriter.cs @@ -0,0 +1,52 @@ +using Microsoft.Xna.Framework.Content.Pipeline; +using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; + +namespace MonoGame.Extended.Content.Pipeline.BitmapFonts +{ + [ContentTypeWriter] + public class BitmapFontWriter : ContentTypeWriter<BitmapFontProcessorResult> + { + protected override void Write(ContentWriter writer, BitmapFontProcessorResult result) + { + writer.Write(result.TextureAssets.Count); + + foreach (var textureAsset in result.TextureAssets) + writer.Write(textureAsset); + + var fontFile = result.FontFile; + writer.Write(fontFile.Common.LineHeight); + writer.Write(fontFile.Chars.Count); + + foreach (var c in fontFile.Chars) + { + writer.Write(c.Id); + writer.Write(c.Page); + writer.Write(c.X); + writer.Write(c.Y); + writer.Write(c.Width); + writer.Write(c.Height); + writer.Write(c.XOffset); + writer.Write(c.YOffset); + writer.Write(c.XAdvance); + } + + writer.Write(fontFile.Kernings.Count); + foreach(var k in fontFile.Kernings) + { + writer.Write(k.First); + writer.Write(k.Second); + writer.Write(k.Amount); + } + } + + public override string GetRuntimeType(TargetPlatform targetPlatform) + { + return "MonoGame.Extended.BitmapFonts.BitmapFont, MonoGame.Extended"; + } + + public override string GetRuntimeReader(TargetPlatform targetPlatform) + { + return "MonoGame.Extended.BitmapFonts.BitmapFontReader, MonoGame.Extended"; + } + } +}
\ No newline at end of file |