Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update Unicode data and algorithms to v. 15.1 #16919

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
802 changes: 401 additions & 401 deletions src/Avalonia.Base/Media/TextFormatting/Unicode/BiDi.trie.cs

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions src/Avalonia.Base/Media/TextFormatting/Unicode/BiDiData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ internal sealed class BidiData

public sbyte ParagraphEmbeddingLevel { get; set; }

public bool HasBrackets { get; private set; }
public bool? HasBrackets { get; private set; }

public bool HasEmbeddings { get; private set; }
public bool? HasEmbeddings { get; private set; }

public bool HasIsolates { get; private set; }
public bool? HasIsolates { get; private set; }

/// <summary>
/// Gets the length of the data held by the BidiData
Expand Down Expand Up @@ -86,46 +86,54 @@ public void Append(ReadOnlySpan<char> text)
(1U << (int)BidiClass.RightToLeftIsolate) |
(1U << (int)BidiClass.FirstStrongIsolate) |
(1U << (int)BidiClass.PopDirectionalIsolate);

var codePointEnumerator = new CodepointEnumerator(text);

while (codePointEnumerator.MoveNext(out var codepoint))
{
// Look up BiDiClass
var dir = codepoint.BiDiClass;

_classes[i] = dir;

var dirBit = 1U << (int)dir;
HasEmbeddings = (dirBit & embeddingMask) != 0U;
HasIsolates = (dirBit & isolateMask) != 0U;

if (!HasEmbeddings.HasValue && (dirBit & embeddingMask) != 0U)
{
HasEmbeddings = true;
}

if (!HasIsolates.HasValue && (dirBit & isolateMask) != 0U)
{
HasIsolates = true;
}

// Lookup paired bracket types
var pbt = codepoint.PairedBracketType;

_pairedBracketTypes[i] = pbt;

if (pbt == BidiPairedBracketType.Open)
{
// Opening bracket types can never have a null pairing.
codepoint.TryGetPairedBracket(out var paired);

_pairedBracketValues[i] = (int)Codepoint.GetCanonicalType(paired).Value;

HasBrackets = true;
}
else if (pbt == BidiPairedBracketType.Close)
{
_pairedBracketValues[i] = (int)Codepoint.GetCanonicalType(codepoint).Value;

HasBrackets = true;
}

i++;
}

Length = i;

Classes = _classes.AsSlice(0, Length);
PairedBracketTypes = _pairedBracketTypes.AsSlice(0, Length);
PairedBracketValues = _pairedBracketValues.AsSlice(0, Length);
Expand Down Expand Up @@ -174,7 +182,7 @@ public void RestoreTypes()
public ArraySlice<sbyte> GetTempLevelBuffer(int length)
{
_tempLevelBuffer.Clear();

return _tempLevelBuffer.Add(length, false);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Avalonia.Base/Media/TextFormatting/Unicode/Codepoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public static Codepoint ReplacementCodepoint
/// </summary>
public GraphemeBreakClass GraphemeBreakClass => UnicodeData.GetGraphemeClusterBreak(_value);

/// <summary>
/// Gets the <see cref="EastAsianWidthClass"/>.
/// </summary>
public EastAsianWidthClass EastAsianWidthClass => UnicodeData.GetEastAsianWidthClass(_value);

/// <summary>
/// Determines whether this <see cref="Codepoint"/> is a break char.
/// </summary>
Expand Down
669 changes: 669 additions & 0 deletions src/Avalonia.Base/Media/TextFormatting/Unicode/EastAsianWidth.trie.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Avalonia.Media.TextFormatting.Unicode
{
public enum EastAsianWidthClass
{
Ambiguous, //A
Fullwidth, //F
Halfwidth, //H
Neutral, //N
Narrow, //Na
Wide, //W
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public enum LineBreakClass
ContingentBreak, //CB
Unknown, //XX
Ambiguous, //AI
Aksara, //AK
AksaraPrebase, //AP
AksaraStart, //AS
MandatoryBreak, //BK
ConditionalJapaneseStarter, //CJ
CarriageReturn, //CR
Expand All @@ -45,5 +48,7 @@ public enum LineBreakClass
ComplexContext, //SA
Surrogate, //SG
Space, //SP
ViramaFinal, //VF
Virama, //VI
}
}
Loading
Loading