Skip to content

Commit

Permalink
Add unit test for UPF text shaping
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgkccampbell committed Jul 31, 2018
1 parent eb0e990 commit 0465b55
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Source/Ultraviolet.Tests/Content/Manifests/Global.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<Asset Name="DefaultUI">..\UI\DefaultUIFont</Asset>
<Asset Name="SegoeUI">SegoeUI</Asset>
</ContentGroup>
<ContentGroup Name="FreeTypeFonts" Directory="Fonts" Type="Ultraviolet.FreeType2.FreeTypeFont, Ultraviolet.FreeType2">
<Asset Name="FiraGO">FiraGO-Regular</Asset>
</ContentGroup>
<ContentGroup Name="Textures" Directory="Textures" Type="Ultraviolet.Graphics.Texture2D">
<Asset Name="DefaultUI">..\UI\DefaultUI</Asset>
<Asset Name="DefaultUIBackground">..\UI\DefaultUIBackground</Asset>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<UIPanelDefinition>
<View ViewModelType="Ultraviolet.Tests.UI.Presentation.Screens.UPF_View_DrawsShapedTextCorrectly_VM, Ultraviolet.Tests">

<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="مرحبا بالعالم">
<TextBlock.Font>#Global:FreeTypeFonts:FiraGO</TextBlock.Font>
<TextBlock.TextIsShaped>true</TextBlock.TextIsShaped>
<TextBlock.TextScript>Arabic</TextBlock.TextScript>
<TextBlock.TextDirection>RightToLeft</TextBlock.TextDirection>
<TextBlock.TextLanguage>ar</TextBlock.TextLanguage>
</TextBlock>

<TextBlock HorizontalAlignment="Right" VerticalAlignment="Top" Text="مرحبا بالعالم">
<TextBlock.Font>#Global:FreeTypeFonts:FiraGO</TextBlock.Font>
<TextBlock.TextIsShaped>true</TextBlock.TextIsShaped>
<TextBlock.TextScript>Arabic</TextBlock.TextScript>
<TextBlock.TextDirection>RightToLeft</TextBlock.TextDirection>
<TextBlock.TextLanguage>ar</TextBlock.TextLanguage>
</TextBlock>

<Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="مرحبا بالعالم">
<Button.Font>#Global:FreeTypeFonts:FiraGO</Button.Font>
<Button.TextIsShaped>true</Button.TextIsShaped>
<Button.TextScript>Arabic</Button.TextScript>
<Button.TextDirection>RightToLeft</Button.TextDirection>
<Button.TextLanguage>ar</Button.TextLanguage>
</Button>

<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" Text="مرحبا بالعالم">
<TextBlock.Font>#Global:FreeTypeFonts:FiraGO</TextBlock.Font>
<TextBlock.TextIsShaped>true</TextBlock.TextIsShaped>
<TextBlock.TextScript>Arabic</TextBlock.TextScript>
<TextBlock.TextDirection>RightToLeft</TextBlock.TextDirection>
<TextBlock.TextLanguage>ar</TextBlock.TextLanguage>
</TextBlock>

<TextBlock HorizontalAlignment="Right" VerticalAlignment="Bottom" Text="مرحبا بالعالم">
<TextBlock.Font>#Global:FreeTypeFonts:FiraGO</TextBlock.Font>
<TextBlock.TextIsShaped>true</TextBlock.TextIsShaped>
<TextBlock.TextScript>Arabic</TextBlock.TextScript>
<TextBlock.TextDirection>RightToLeft</TextBlock.TextDirection>
<TextBlock.TextLanguage>ar</TextBlock.TextLanguage>
</TextBlock>

</View>
</UIPanelDefinition>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,24 @@ public void UPF_TextBox_BindsCorrectlyToViewModel()
TheResultingImage(result).ShouldMatch(@"Resources/Expected/UI/Presentation/UPF_TextBox_BindsCorrectlyToViewModel.png");
}

[Test]
[Category("UPF"), Category("Rendering")]
[Description("Ensures that a UPF view can correctly render shaped text.")]
public void UPF_View_DrawsShapedTextCorrectly()
{
var result = GivenAPresentationFoundationTestFor(content => new UPF_View_DrawsShapedTextCorrectly(content))
.WithPlugin(new FreeType2.FreeTypeFontPlugin())
.Render(uv =>
{
using (var spriteBatch = SpriteBatch.Create())
{
uv.GetUI().GetScreens().Draw(new UltravioletTime(), spriteBatch);
}
});

TheResultingImage(result).ShouldMatch(@"Resources/Expected/UI/Presentation/UPF_View_DrawsShapedTextCorrectly.png");
}

/// <summary>
/// Runs a standard test by spinning up an Ultraviolet application and displaying the specified UPF screen.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Ultraviolet.Content;

namespace Ultraviolet.Tests.UI.Presentation.Screens
{
public class UPF_View_DrawsShapedTextCorrectly : TestScreenBase<UPF_View_DrawsShapedTextCorrectly_VM>
{
public UPF_View_DrawsShapedTextCorrectly(ContentManager globalContent)
: base("Content/UI/Screens/UPF_View_DrawsShapedTextCorrectly", "View", globalContent)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Ultraviolet.Tests.UI.Presentation.Screens
{
public class UPF_View_DrawsShapedTextCorrectly_VM
{

}
}
8 changes: 8 additions & 0 deletions Source/Ultraviolet.Tests/Ultraviolet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@
<Compile Include="UI\Presentation\Input\MouseGestureTests.cs" />
<Compile Include="UI\Presentation\Input\KeyGestureTests.cs" />
<Compile Include="UI\Presentation\PresentationFoundationTestFramework.cs" />
<Compile Include="UI\Presentation\Screens\UPF_View_DrawsShapedTextCorrectly.cs" />
<Compile Include="UI\Presentation\Screens\UPF_View_DrawsShapedTextCorrectly_VM.cs" />
<Compile Include="UI\Presentation\Screens\UPF_Grid_ArrangesAutoCellsCorrectly.cs" />
<Compile Include="UI\Presentation\Screens\UPF_Grid_ArrangesChildrenCorrectly2.cs" />
<Compile Include="UI\Presentation\Screens\UPF_Grid_ArrangesChildrenCorrectly2_VM.cs" />
Expand Down Expand Up @@ -405,6 +407,9 @@
<Compile Include="CircleTests.cs" />
<Compile Include="Size2Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Resources\Expected\UI\Presentation\UPF_View_DrawsShapedTextCorrectly.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\Expected\Graphics\Graphics2D\Text\TextRenderer_CorrectlyPerformsRightToLeftLayout%28sRGB%29.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -921,6 +926,9 @@
<None Include="Resources\Expected\Graphics\Graphics2D\SpriteBatch_CanRenderSimpleStrings_RightToLeft.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Content\UI\Screens\UPF_View_DrawsShapedTextCorrectly\View.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\Expected\Graphics\Graphics2D\SpriteBatch_CorrectlyRendersEastAsianCharacters%28FreeType2%29.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit 0465b55

Please sign in to comment.