Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,13 @@ private static UnshapedTextRun CreateShapeableRun(ReadOnlyMemory<char> text,

var codepoint = Codepoint.ReplacementCodepoint;

var codepointEnumerator = new CodepointEnumerator(text.Slice(count).Span);
var graphemeEnumerator = new GraphemeEnumerator(text.Slice(count).Span);

while (codepointEnumerator.MoveNext(out var cp))
if (graphemeEnumerator.MoveNext(out var grapheme))
{
if (cp.IsWhiteSpace)
{
continue;
}

codepoint = cp;

break;
codepoint = grapheme.FirstCodepoint;
}

//ToDo: Fix FontFamily fallback
var matchFound =
fontManager.TryMatchCharacter(codepoint, defaultTypeface.Style, defaultTypeface.Weight,
defaultTypeface.Stretch, defaultTypeface.FontFamily, defaultProperties.CultureInfo,
Expand All @@ -151,7 +143,8 @@ private static UnshapedTextRun CreateShapeableRun(ReadOnlyMemory<char> text,
// no fallback found
var enumerator = new GraphemeEnumerator(textSpan);

while (enumerator.MoveNext(out var grapheme))
//Move forward until we reach the next base character
while (enumerator.MoveNext(out grapheme))
{
if (!grapheme.FirstCodepoint.IsWhiteSpace && defaultGlyphTypeface.TryGetGlyph(grapheme.FirstCodepoint, out _))
{
Expand Down
4 changes: 1 addition & 3 deletions src/Avalonia.Base/Media/TextFormatting/Unicode/Codepoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ public bool IsWhiteSpace
{
const ulong whiteSpaceMask =
(1UL << (int)GeneralCategory.Control) |
(1UL << (int)GeneralCategory.NonspacingMark) |
(1UL << (int)GeneralCategory.Format) |
(1UL << (int)GeneralCategory.SpaceSeparator) |
(1UL << (int)GeneralCategory.SpacingMark);
(1UL << (int)GeneralCategory.SpaceSeparator);

return ((1UL << (int)GeneralCategory) & whiteSpaceMask) != 0UL;
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,32 @@ public void Should_Wrap_Chinese()
}
}

[Fact]
public void Should_MatchCharacter_For_Spacing_CombiningMark()
{
using (Start())
{
var text = "𖾇";

var typeface = new Typeface(new FontFamily(new Uri("resm:Avalonia.Skia.UnitTests.Fonts?assembly=Avalonia.Skia.UnitTests"), "Noto Mono"));
var defaultRunProperties = new GenericTextRunProperties(typeface);
var paragraphProperties = new GenericTextParagraphProperties(defaultRunProperties, textWrapping: TextWrapping.Wrap);
var textLine = TextFormatter.Current.FormatLine(new SimpleTextSource(text, defaultRunProperties), 0, 120, paragraphProperties);

Assert.NotNull(textLine);

var textRuns = textLine.TextRuns;

Assert.NotEmpty(textRuns);

var firstRun = textRuns[0];

Assert.NotNull(firstRun.Properties);

Assert.Equal("Noto Sans Miao", firstRun.Properties.Typeface.GlyphTypeface.FamilyName);
}
}

protected readonly record struct SimpleTextSource : ITextSource
{
private readonly string _text;
Expand Down
Loading