Browse Source

Merge pull request #5876 from Gillibald/fixes/5875

Fix break pair cluster building
pull/5856/head
Benedikt Stebner 5 years ago
committed by GitHub
parent
commit
51278bbccf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Skia/Avalonia.Skia/TextShaperImpl.cs
  2. 43
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextShaperTests.cs

2
src/Skia/Avalonia.Skia/TextShaperImpl.cs

@ -87,7 +87,7 @@ namespace Avalonia.Skia
{
var nextCodepoint = Codepoint.ReadAt(text, i + 1, out _);
if (nextCodepoint == '\r' && codepoint == '\n' || nextCodepoint == '\n' && codepoint == '\r')
if (nextCodepoint == '\n' && codepoint == '\r')
{
count++;

43
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextShaperTests.cs

@ -0,0 +1,43 @@
using System;
using System.Globalization;
using Avalonia.Media;
using Avalonia.Media.TextFormatting;
using Avalonia.UnitTests;
using Xunit;
namespace Avalonia.Skia.UnitTests.Media.TextFormatting
{
public class TextShaperTests
{
[Fact]
public void Should_Form_Clusters_For_BreakPairs()
{
using (Start())
{
var text = "\n\r\n".AsMemory();
var glyphRun = TextShaper.Current.ShapeText(
text,
Typeface.Default,
12,
CultureInfo.CurrentCulture);
Assert.Equal(glyphRun.Characters.Length, text.Length);
Assert.Equal(glyphRun.GlyphClusters.Length, text.Length);
Assert.Equal(0, glyphRun.GlyphClusters[0]);
Assert.Equal(1, glyphRun.GlyphClusters[1]);
Assert.Equal(1, glyphRun.GlyphClusters[2]);
}
}
private static IDisposable Start()
{
var disposable = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface
.With(renderInterface: new PlatformRenderInterface(null),
textShaperImpl: new TextShaperImpl(),
fontManagerImpl: new CustomFontManagerImpl()));
return disposable;
}
}
}
Loading…
Cancel
Save