public static SpriteFont Compile(GraphicsDevice g, string file, out IDisposable gR) { FontDescriptionImporter ei = new FontDescriptionImporter(); FontDescription ec = ei.Import(file, new XNADynImporterContext()); FontDescriptionProcessor ep = new FontDescriptionProcessor(); var cec = ep.Process(ec, new XNADynProcessorContext()); // Get Private Texture Texture2DContent texC = sfcTexture.GetValue(cec) as Texture2DContent; MipmapChain o = txcMipmaps.GetValue(texC, null) as MipmapChain; BitmapContent texBMP = o[0]; SurfaceFormat sf; if (!texBMP.TryGetFormat(out sf)) { throw new InvalidContentException("Could Not Obtain The Surface Format Of The SpriteFont"); } Texture2D texture = new Texture2D(g, texBMP.Width, texBMP.Height, false, sf); texture.SetData(texBMP.GetPixelData()); // Get Private Glyph Data List <Rectangle> glyphs = sfcGlyphs.GetValue(cec) as List <Rectangle>; List <Rectangle> cropping = sfcCropping.GetValue(cec) as List <Rectangle>; List <char> charMap = sfcCharMap.GetValue(cec) as List <char>; int lineSpacing = (int)sfcLineSpacing.GetValue(cec); float spacing = (float)sfcSpacing.GetValue(cec); List <Vector3> kerning = sfcKerning.GetValue(cec) as List <Vector3>; char? defaultChar = sfcDefaultChar.GetValue(cec) as char?; // Invoke Private SpriteFont Constructor gR = texture; return(sfConstructor.Invoke(new object[] { texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultChar }) as SpriteFont); }
public override TOutput Process(TInput input, ContentProcessorContext context) { // contextを通してExternalReference(外部参照)のアセットをビルド処理できる。 // 通常、プロセッサを指定するが、ここではnullを指定することで、 // インポート直後のタイプを取得している。 FontDescription fontDescription = context.BuildAndLoadAsset <FontDescription, FontDescription>(input.FontDescription, null); string[] messageSource = context.BuildAndLoadAsset <string[], string[]>(input.Message, null); // FontDescriptionのCharactersにmessageSourceで使用している文字コードを追加する。 int totalCharacterCount = 0; foreach (string line in messageSource) { foreach (char c in line) { totalCharacterCount++; // FontDescription.Characters.Addメソッド内で // 文字コード重複チェックをしているので // ここでは重複を気にせずに文字を追加するだけでよい。 fontDescription.Characters.Add(c); } } // 最終結果に変換する TextMessageContent outContent = new TextMessageContent(); // FontDescriptionProcessorを直接実行して、SpriteFontContentを取得する。 FontDescriptionProcessor processor = new FontDescriptionProcessor(); outContent.Font = processor.Process(fontDescription, context); // メッセージ文字列の処理。DiscardMessageフラグがTrueの場合は処理しない。 if (!input.DiscardMessage) { outContent.Message = ProcessMessage(messageSource); } context.Logger.LogImportantMessage( String.Format("使用文字数{0}, 総文字数:{1}", fontDescription.Characters.Count, totalCharacterCount)); return(outContent); }
public CharactersToFontProcessor() { _baseProcessor = new FontDescriptionProcessor(); }
public void BuildFontFromDescription(TargetPlatform platform, TextureProcessorOutputFormat format) { var context = new TestProcessorContext(platform, "Arial.xnb"); var processor = new FontDescriptionProcessor() { TextureFormat = format, PremultiplyAlpha = true, }; FontDescription fontDescription = null; using (var input = XmlReader.Create(new StringReader(ArialFont))) fontDescription = IntermediateSerializer.Deserialize <FontDescription>(input, ""); fontDescription.Identity = new ContentIdentity("Arial.spritefont"); var output = processor.Process(fontDescription, context); Assert.IsNotNull(output, "output should not be null"); Assert.IsNotNull(output.Texture, "output.Texture should not be null"); var textureType = output.Texture.Faces[0][0].GetType(); switch (format) { case TextureProcessorOutputFormat.Color: Assert.IsTrue(textureType == typeof(PixelBitmapContent <Color>)); break; case TextureProcessorOutputFormat.Color16Bit: Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgr565>)); break; case TextureProcessorOutputFormat.Compressed: switch (platform) { case TargetPlatform.Windows: case TargetPlatform.DesktopGL: Assert.IsTrue(textureType == typeof(Dxt3BitmapContent)); break; case TargetPlatform.iOS: Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>)); break; case TargetPlatform.Android: Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>)); break; } break; case TextureProcessorOutputFormat.PvrCompressed: // because the font is not power of 2 we should use Brga4444 Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>)); break; case TextureProcessorOutputFormat.Etc1Compressed: // because the font has Alpha we should use Brga4444 Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>)); break; default: Assert.Fail("Test not written for " + format); break; } }