public void TextRenderer_CutsOffTextThatExceedsVerticalLayoutSpace() { var content = new TextRendererTestContent( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum commodo pretium risus sollicitudin ultricies. " + "Ut quis arcu suscipit, rutrum libero nec, convallis sem. Morbi rhoncus urna nec turpis bibendum eleifend. In vestibulum " + "congue feugiat. In pulvinar enim quis diam malesuada, a vestibulum urna bibendum."); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); var width = window.ClientSize.Width / 2; var height = window.ClientSize.Height / 2; content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, width, height, TextFlags.AlignLeft, TextLayoutOptions.None)); content.SpriteBatch.Begin(); content.SpriteBatch.Draw(content.BlankTexture, new RectangleF(0, 0, width, height), Color.Red * 0.5f); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_CutsOffTextThatExceedsVerticalLayoutSpace.png"); }
public void TextRenderer_CorrectlyRendersSubstrings() { var content = new TextRendererTestContent("Welcome to |b||c:FFFF0000|Corneria|c||b|"); content.FontPath = "Fonts/SegoeUI"; var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, null, null, TextFlags.Standard)); content.SpriteBatch.Begin(); var positionX = 0f; var positionY = 0f; positionY = 0f; for (int i = 0; i < content.Text.Length; i++) { content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, new Vector2(positionX, positionY), Color.White, 0, i); positionY += content.TextLayoutResult.ActualHeight; } positionX = uv.GetPlatform().Windows.GetPrimary().ClientSize.Width / 3; positionY = 0f; for (int i = 0; i < content.Text.Length; i++) { content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, new Vector2(positionX, positionY), Color.White, i, Int32.MaxValue); positionY += content.TextLayoutResult.ActualHeight; } positionX = 2 * uv.GetPlatform().Windows.GetPrimary().ClientSize.Width / 3; positionY = 0f; for (int i = 0; i < content.Text.Length; i++) { content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, new Vector2(positionX, positionY), Color.White, i, 10); positionY += content.TextLayoutResult.ActualHeight; } content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_CorrectlyRendersSubstrings.png"); }
public void TextRenderer_BreaksAtLastBreakingSpace_WithLeftAlignment() { var content = new TextRendererTestContent("Hello! This is a |icon:test|test|b|test|b||i|test|i||b||i|test|i||b| of the line breaking algorithm."); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); var width = window.Compositor.Width / 2; var height = window.Compositor.Height; content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, width, height, TextFlags.AlignLeft, TextLayoutOptions.None)); content.SpriteBatch.Begin(); content.SpriteBatch.Draw(content.BlankTexture, new RectangleF(0, 0, width, height), Color.Red * 0.5f); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.End(); }); TheResultingValue(content.TextLayoutResult.TotalLength).ShouldBe("Hello! This is a Xtesttesttesttest of the line breaking algorithm.".Length); TheResultingValue(content.TextLayoutResult.GetLineInfo(0)) .ShouldHavePosition(0, 0) .ShouldHaveSize(132, 22) .ShouldHaveLengthInCommands(2) .ShouldHaveLengthInGlyphs(17); TheResultingValue(content.TextLayoutResult.GetLineInfo(1)) .ShouldHavePosition(0, 22) .ShouldHaveSize(236, 22) .ShouldHaveLengthInCommands(15) .ShouldHaveLengthInGlyphs(30); TheResultingValue(content.TextLayoutResult.GetLineInfo(2)) .ShouldHavePosition(0, 44) .ShouldHaveSize(166, 22) .ShouldHaveLengthInCommands(1) .ShouldHaveLengthInGlyphs(19); TheResultingImage(result) .ShouldMatch(@"Resources/Expected/Graphics/Graphics2D/Text/TextRenderer_BreaksAtLastBreakingSpace_WithLeftAlignment.png"); }
public void TextRenderer_CalculatesCorrectGlyphBounds_WhenCommandsAreDisabled() { var content = new TextRendererTestContent( "The |b||icon:test|quick brown fox|b| jumps\nover the |c:ffff0000|lazy dog.|c|\n" + "The |i|quick|i| brown |i|fox|i|\njumps over the |b||i|lazy dog|i||b|", TextParserOptions.IgnoreCommandCodes); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, window.ClientSize.Width, window.ClientSize.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle)); content.TextLayoutResult.AcquirePointers(); var glyph0Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 0); var glyph4Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 4); var glyph14Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 14); var glyph26Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 26); var glyph52Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 52); var glyph53Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 53); var glyphLastBounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, content.TextLayoutResult.TotalLength - 1); content.TextLayoutResult.ReleasePointers(); content.SpriteBatch.Begin(); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.Draw(content.BlankTexture, glyph0Bounds, Color.Red * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph4Bounds, Color.Cyan * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph14Bounds, Color.Lime * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph26Bounds, Color.Blue * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph52Bounds, Color.Yellow * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph53Bounds, Color.Purple * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyphLastBounds, Color.White * 0.5f); content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_CalculatesCorrectGlyphBounds_WhenCommandsAreDisabled.png"); }
public void TextRenderer_CalculatesCorrectLineBounds() { var content = new TextRendererTestContent( "The |b||icon:test|quick brown fox|b| jumps\nover the |c:ffff0000|lazy dog.|c|\n" + "The |i|quick|i| brown |i|fox|i|\njumps over the |b||i|lazy dog|i||b|"); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, window.ClientSize.Width, window.ClientSize.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle)); content.TextLayoutResult.AcquirePointers(); var line0Bounds = content.TextRenderer.GetLineBounds(content.TextLayoutResult, 0); var line1Bounds = content.TextRenderer.GetLineBounds(content.TextLayoutResult, 1); var line2Bounds = content.TextRenderer.GetLineBounds(content.TextLayoutResult, 2); var line3Bounds = content.TextRenderer.GetLineBounds(content.TextLayoutResult, 3); content.TextLayoutResult.ReleasePointers(); content.SpriteBatch.Begin(); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.Draw(content.BlankTexture, line0Bounds, Color.Red * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, line1Bounds, Color.Lime * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, line2Bounds, Color.Blue * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, line3Bounds, Color.Yellow * 0.5f); content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_CalculatesCorrectLineBounds.png"); }
public void TextRenderer_GetsCorrectGlyphAtPosition_ForPositionOutsideGlyph() { var content = new TextRendererTestContent( "The |b||icon:test|quick brown fox|b| jumps\nover the |c:ffff0000|lazy dog.|c|\n" + "The |i|quick|i| brown |i|fox|i|\njumps over the |b||i|lazy dog|i||b|"); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, window.ClientSize.Width, window.ClientSize.Height, TextFlags.AlignLeft | TextFlags.AlignTop)); content.TextLayoutResult.AcquirePointers(); var lines = new Int32?[5]; var glyphs = new[] { content.TextRenderer.GetGlyphAtPosition(content.TextLayoutResult, 169, 32, out lines[0]), content.TextRenderer.GetGlyphAtPosition(content.TextLayoutResult, 178, 122, out lines[1]), content.TextRenderer.GetGlyphAtPosition(content.TextLayoutResult, 472, 8, out lines[2]), content.TextRenderer.GetGlyphAtPosition(content.TextLayoutResult, 114, 203, out lines[3]), content.TextRenderer.GetGlyphAtPosition(content.TextLayoutResult, 391, 217, out lines[4]), }; content.TextLayoutResult.ReleasePointers(); TheResultingCollection(glyphs).ShouldBeExactly(null, null, null, null, null); TheResultingCollection(lines).ShouldBeExactly(1, null, 0, null, null); content.SpriteBatch.Begin(); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); var colors = new[] { Color.Red, Color.Lime, Color.Blue, Color.Yellow, Color.Purple }; for (int i = 0; i < glyphs.Length; i++) { var glyph = glyphs[i]; if (glyph.HasValue) { var bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, glyph.Value); content.SpriteBatch.Draw(content.BlankTexture, bounds, colors[i] * 0.5f); } } content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_GetsCorrectGlyphAtPosition_ForPositionOutsideGlyph.png"); }
public void TextRenderer_GetCorrectLineAtPosition_ForPositionOutsideText_Stretch() { var content = new TextRendererTestContent( "The |b||icon:test|quick brown fox|b| jumps\nover the |c:ffff0000|lazy dog.|c|\n" + "The |i|quick|i| brown |i|fox|i|\njumps over the |b||i|lazy dog|i||b|"); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, window.ClientSize.Width, window.ClientSize.Height, TextFlags.AlignLeft | TextFlags.AlignTop)); content.TextLayoutResult.AcquirePointers(); var lines = new[] { content.TextRenderer.GetLineAtPosition(content.TextLayoutResult, 350, 8, true), content.TextRenderer.GetLineAtPosition(content.TextLayoutResult, 350, 33, true), content.TextRenderer.GetLineAtPosition(content.TextLayoutResult, 350, 55, true), content.TextRenderer.GetLineAtPosition(content.TextLayoutResult, 350, 77, true), content.TextRenderer.GetLineAtPosition(content.TextLayoutResult, 350, 200, true), }; content.TextLayoutResult.ReleasePointers(); content.SpriteBatch.Begin(); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); var colors = new[] { Color.Red, Color.Lime, Color.Blue, Color.Yellow, Color.Purple }; for (int i = 0; i < lines.Length; i++) { var line = lines[i]; if (line.HasValue) { var bounds = new Rectangle(0, line.Value * content.SpriteFont.Regular.LineSpacing, window.ClientSize.Width, content.SpriteFont.Regular.LineSpacing); content.SpriteBatch.Draw(content.BlankTexture, bounds, colors[i] * 0.5f); } } content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_GetCorrectLineAtPosition_ForPositionOutsideText_Stretch.png"); }
public void TextRenderer_BreaksVeryLongWordsIntoMultipleLines_WithHyphens() { var content = new TextRendererTestContent("Welcome to Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch! Please enjoy your stay.\n\n" + "This message brought to you by the Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch tourist board."); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); var width = window.ClientSize.Width / 2; var height = window.ClientSize.Height; content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, width, height, TextFlags.Standard, TextLayoutOptions.Hyphenate)); content.SpriteBatch.Begin(); content.SpriteBatch.Draw(content.BlankTexture, new RectangleF(0, 0, width, height), Color.Red * 0.5f); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.End(); }); TheResultingValue(content.TextLayoutResult.TotalLength).ShouldBe(content.Text.Length); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_BreaksVeryLongWordsIntoMultipleLines_WithHyphens.png"); }
public void TextRenderer_BreaksOnNonBreakingSpace_WhenNoBreakingSpaceIsAvailable() { var content = new TextRendererTestContent("Every\u00A0single\u00A0space\u00A0on\u00A0this\u00A0line\u00A0is\u00A0non-breaking!"); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); var width = window.ClientSize.Width / 2; var height = window.ClientSize.Height; content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, width, height, TextFlags.AlignLeft, TextLayoutOptions.None)); content.SpriteBatch.Begin(); content.SpriteBatch.Draw(content.BlankTexture, new RectangleF(0, 0, width, height), Color.Red * 0.5f); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.End(); }); TheResultingValue(content.TextLayoutResult.TotalLength).ShouldBe(content.Text.Length); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_BreaksOnNonBreakingSpace_WhenNoBreakingSpaceIsAvailable.png"); }
public void TextRenderer_DoesNotBreakOnNonBreakingSpace_WhenBreakingSpaceIsAvailable() { var content = new TextRendererTestContent( "Distance to Moon: 238,900\u00A0mi\n" + "\n" + "Distance to Mars: 140\u00A0million\u00A0miles"); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); var width = window.ClientSize.Width / 2; var height = window.ClientSize.Height; content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, width, height, TextFlags.AlignLeft, TextLayoutOptions.None)); content.SpriteBatch.Begin(); content.SpriteBatch.Draw(content.BlankTexture, new RectangleF(0, 0, width, height), Color.Red * 0.5f); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_DoesNotBreakOnNonBreakingSpace_WhenBreakingSpaceIsAvailable.png"); }
public void TextRenderer_CalculatesCorrectGlyphBounds() { var content = new TextRendererTestContent( "The |b||icon:test|quick brown fox|b| jumps\nover the |c:ffff0000|lazy dog.|c|\n" + "The |i|quick|i| brown |i|fox|i|\njumps over the |b||i|lazy dog|i||b|"); var result = GivenAnUltravioletApplication() .WithContent(content.Load) .Render(uv => { uv.GetGraphics().Clear(Color.CornflowerBlue); var window = uv.GetPlatform().Windows.GetPrimary(); content.TextLayoutEngine.CalculateLayout(content.TextParserResult, content.TextLayoutResult, new TextLayoutSettings(content.SpriteFont, window.Compositor.Width, window.Compositor.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle)); content.TextLayoutResult.AcquirePointers(); var glyph0Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 0); var glyph4Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 4); var glyph14Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 14); var glyph26Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 26); var glyph27Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 27); var glyph53Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 53); var glyph54Bounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, 54); var glyphLastBounds = content.TextRenderer.GetGlyphBounds(content.TextLayoutResult, content.TextLayoutResult.TotalLength - 1); content.TextLayoutResult.ReleasePointers(); // Glyph 26 is a line break and therefore invisible, so check it manually TheResultingValue(glyph26Bounds.X).ShouldBe(369); TheResultingValue(glyph26Bounds.Y).ShouldBe(136); TheResultingValue(glyph26Bounds.Width).ShouldBe(0); TheResultingValue(glyph26Bounds.Height).ShouldBe(22); content.SpriteBatch.Begin(); content.TextRenderer.Draw(content.SpriteBatch, content.TextLayoutResult, Vector2.Zero, Color.White); content.SpriteBatch.Draw(content.BlankTexture, glyph0Bounds, Color.Red * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph4Bounds, Color.Cyan * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph14Bounds, Color.Lime * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph26Bounds, Color.Red * 0.5f); // should be invisible content.SpriteBatch.Draw(content.BlankTexture, glyph27Bounds, Color.Blue * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph53Bounds, Color.Yellow * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyph54Bounds, Color.Purple * 0.5f); content.SpriteBatch.Draw(content.BlankTexture, glyphLastBounds, Color.White * 0.5f); content.SpriteBatch.End(); }); TheResultingImage(result) .ShouldMatch(@"Resources/Expected/Graphics/Graphics2D/Text/TextRenderer_CalculatesCorrectGlyphBounds.png"); }