public void LoadFreeType(ContentManager content) { Contract.Require(content, nameof(content)); this.SpriteBatch = SpriteBatch.Create(); this.Font = content.Load <UltravioletFont>(FontPath ?? "Fonts/FiraSans"); this.TextIcons = content.Load <Sprite>(IconPath ?? "Sprites/InterfaceIcons"); this.TextParserResult = new TextParserTokenStream(); this.TextParser = new TextParser(); this.TextParser.Parse(this.Text, this.TextParserResult, this.TextParserOptions); this.TextLayoutResult = new TextLayoutCommandStream(); this.TextLayoutEngine = new TextLayoutEngine(); this.TextLayoutEngine.RegisterTextShaper(TextShaper.Create()); this.TextLayoutEngine.RegisterIcon("test", this.TextIcons["test"], descender: -3); this.TextRenderer = new TextRenderer(); this.TextRenderer.RegisterTextShaper(TextShaper.Create()); this.TextRenderer.RegisterIcon("test", this.TextIcons["test"]); this.BlankTexture = Texture2D.CreateTexture(1, 1); this.BlankTexture.SetData(new[] { Color.White }); }
public void SpriteBatch_CorrectlyRendersShapedArabicScript() { var spriteBatch = default(SpriteBatch); var spriteFont = default(UltravioletFont); var sstr = default(ShapedString); var result = GivenAnUltravioletApplication() .WithPlugin(new FreeTypeFontPlugin()) .WithContent(content => { spriteBatch = SpriteBatch.Create(); spriteFont = content.Load <UltravioletFont>("Fonts/FiraGO-Regular"); using (var textShaper = TextShaper.Create()) { textShaper.SetUnicodeProperties(TextDirection.RightToLeft, TextScript.Arabic, "ar"); textShaper.Append("مرحبا بالعالم"); sstr = textShaper.CreateShapedString(spriteFont.Regular); } }) .Render(uv => { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); spriteBatch.DrawShapedString(spriteFont.Regular, sstr, Vector2.Zero, Color.White); spriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources/Expected/Graphics/Graphics2D/SpriteBatch_CorrectlyRendersShapedArabicScript.png"); }