Browse Source
Merge pull request #8998 from Gillibald/fixes/bidiMirrors
Fix bidi mirror handling
pull/9035/head
Benedikt Stebner
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
22 additions and
9 deletions
-
src/Avalonia.Base/Media/GlyphRun.cs
-
src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs
-
src/Avalonia.Base/Media/TextFormatting/Unicode/BiDiData.cs
-
src/Skia/Avalonia.Skia/TextShaperImpl.cs
-
src/Windows/Avalonia.Direct2D1/Media/TextShaperImpl.cs
-
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs
|
|
|
@ -361,7 +361,9 @@ namespace Avalonia.Media |
|
|
|
|
|
|
|
characterIndex = cluster; |
|
|
|
|
|
|
|
if (currentX - advance < distance) |
|
|
|
var offsetX = currentX - advance; |
|
|
|
|
|
|
|
if (offsetX < distance) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -375,7 +377,8 @@ namespace Avalonia.Media |
|
|
|
var characterHit = FindNearestCharacterHit(characterIndex, out var width); |
|
|
|
|
|
|
|
var delta = width / 2; |
|
|
|
var offset = IsLeftToRight ? distance - currentX : currentX - distance; |
|
|
|
|
|
|
|
var offset = IsLeftToRight ? Math.Round(distance - currentX, 3) : Math.Round(currentX - distance, 3); |
|
|
|
|
|
|
|
var isTrailing = offset > delta; |
|
|
|
|
|
|
|
|
|
|
|
@ -76,7 +76,7 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
{ |
|
|
|
if (script == Script.Common && previousTypeface is not null) |
|
|
|
{ |
|
|
|
if (TryGetShapeableLength(text, previousTypeface.Value, defaultTypeface, out var fallbackCount, out _)) |
|
|
|
if (TryGetShapeableLength(text, previousTypeface.Value, null, out var fallbackCount, out _)) |
|
|
|
{ |
|
|
|
return new ShapeableTextCharacters(text.Take(fallbackCount), |
|
|
|
defaultProperties.WithTypeface(previousTypeface.Value), biDiLevel); |
|
|
|
|
|
|
|
@ -71,9 +71,6 @@ namespace Avalonia.Media.TextFormatting.Unicode |
|
|
|
|
|
|
|
// Resolve the BidiCharacterType, paired bracket type and paired
|
|
|
|
// bracket values for all code points
|
|
|
|
HasBrackets = false; |
|
|
|
HasEmbeddings = false; |
|
|
|
HasIsolates = false; |
|
|
|
|
|
|
|
int i = Length; |
|
|
|
|
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
buffer.GuessSegmentProperties(); |
|
|
|
|
|
|
|
buffer.Direction = Direction.LeftToRight; //Always shape LeftToRight
|
|
|
|
buffer.Direction = (bidiLevel & 1) == 0 ? Direction.LeftToRight : Direction.RightToLeft; |
|
|
|
|
|
|
|
buffer.Language = new Language(culture ?? CultureInfo.CurrentCulture); |
|
|
|
|
|
|
|
@ -35,6 +35,11 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
font.Shape(buffer); |
|
|
|
|
|
|
|
if(buffer.Direction == Direction.RightToLeft) |
|
|
|
{ |
|
|
|
buffer.Reverse(); |
|
|
|
} |
|
|
|
|
|
|
|
font.GetScale(out var scaleX, out _); |
|
|
|
|
|
|
|
var textScale = fontRenderingEmSize / scaleX; |
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ namespace Avalonia.Direct2D1.Media |
|
|
|
|
|
|
|
buffer.GuessSegmentProperties(); |
|
|
|
|
|
|
|
buffer.Direction = Direction.LeftToRight; //Always shape LeftToRight
|
|
|
|
buffer.Direction = (bidiLevel & 1) == 0 ? Direction.LeftToRight : Direction.RightToLeft; |
|
|
|
|
|
|
|
buffer.Language = new Language(culture ?? CultureInfo.CurrentCulture); |
|
|
|
|
|
|
|
@ -35,6 +35,11 @@ namespace Avalonia.Direct2D1.Media |
|
|
|
|
|
|
|
font.Shape(buffer); |
|
|
|
|
|
|
|
if(buffer.Direction == Direction.RightToLeft) |
|
|
|
{ |
|
|
|
buffer.Reverse(); |
|
|
|
} |
|
|
|
|
|
|
|
font.GetScale(out var scaleX, out _); |
|
|
|
|
|
|
|
var textScale = fontRenderingEmSize / scaleX; |
|
|
|
|
|
|
|
@ -1009,7 +1009,10 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting |
|
|
|
|
|
|
|
currentX += glyphAdvance; |
|
|
|
|
|
|
|
cluster = clusters[j]; |
|
|
|
if(glyphAdvance > 0) |
|
|
|
{ |
|
|
|
cluster = clusters[j]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|