Skip to content

Commit 87800f7

Browse files
authored
Merge branch 'master' into danwalmsley-patch-1
2 parents 05568be + 74485f1 commit 87800f7

File tree

59 files changed

+1585
-656
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1585
-656
lines changed

src/Avalonia.Controls/Primitives/AccessText.cs

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public override void Render(DrawingContext context)
6767

6868
if (underscore != -1 && ShowAccessKey)
6969
{
70-
var rect = HitTestTextPosition(underscore);
70+
var rect = TextLayout.HitTestTextPosition(underscore);
7171
var offset = new Vector(0, -0.5);
7272
context.DrawLine(
7373
new Pen(Foreground, 1),
@@ -76,80 +76,6 @@ public override void Render(DrawingContext context)
7676
}
7777
}
7878

79-
/// <summary>
80-
/// Get the pixel location relative to the top-left of the layout box given the text position.
81-
/// </summary>
82-
/// <param name="textPosition">The text position.</param>
83-
/// <returns></returns>
84-
private Rect HitTestTextPosition(int textPosition)
85-
{
86-
if (TextLayout == null)
87-
{
88-
return new Rect();
89-
}
90-
91-
if (TextLayout.TextLines.Count == 0)
92-
{
93-
return new Rect();
94-
}
95-
96-
if (textPosition < 0 || textPosition >= Text.Length)
97-
{
98-
var lastLine = TextLayout.TextLines[TextLayout.TextLines.Count - 1];
99-
100-
var lineX = lastLine.LineMetrics.Size.Width;
101-
102-
var lineY = Bounds.Height - lastLine.LineMetrics.Size.Height;
103-
104-
return new Rect(lineX, lineY, 0, lastLine.LineMetrics.Size.Height);
105-
}
106-
107-
var currentY = 0.0;
108-
109-
foreach (var textLine in TextLayout.TextLines)
110-
{
111-
if (textLine.TextRange.End < textPosition)
112-
{
113-
currentY += textLine.LineMetrics.Size.Height;
114-
115-
continue;
116-
}
117-
118-
var currentX = 0.0;
119-
120-
foreach (var textRun in textLine.TextRuns)
121-
{
122-
if (!(textRun is ShapedTextCharacters shapedTextCharacters))
123-
{
124-
continue;
125-
}
126-
127-
if (shapedTextCharacters.GlyphRun.Characters.End < textPosition)
128-
{
129-
currentX += shapedTextCharacters.Size.Width;
130-
131-
continue;
132-
}
133-
134-
var characterHit =
135-
shapedTextCharacters.GlyphRun.FindNearestCharacterHit(textPosition, out var width);
136-
137-
var distance = shapedTextCharacters.GlyphRun.GetDistanceFromCharacterHit(characterHit);
138-
139-
currentX += distance - width;
140-
141-
if (characterHit.TrailingLength == 0)
142-
{
143-
width = 0.0;
144-
}
145-
146-
return new Rect(currentX, currentY, width, shapedTextCharacters.Size.Height);
147-
}
148-
}
149-
150-
return new Rect();
151-
}
152-
15379
/// <inheritdoc/>
15480
protected override TextLayout CreateTextLayout(Size constraint, string text)
15581
{

src/Avalonia.Controls/TextBlock.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -416,26 +416,8 @@ public override void Render(DrawingContext context)
416416
{
417417
return;
418418
}
419-
420-
var textAlignment = TextAlignment;
421-
422-
var width = Bounds.Size.Width;
423-
424-
var offsetX = 0.0;
425-
426-
switch (textAlignment)
427-
{
428-
case TextAlignment.Center:
429-
offsetX = (width - TextLayout.Size.Width) / 2;
430-
break;
431-
432-
case TextAlignment.Right:
433-
offsetX = width - TextLayout.Size.Width;
434-
break;
435-
}
436-
419+
437420
var padding = Padding;
438-
439421
var top = padding.Top;
440422
var textSize = TextLayout.Size;
441423

@@ -453,10 +435,7 @@ public override void Render(DrawingContext context)
453435
}
454436
}
455437

456-
using (context.PushPostTransform(Matrix.CreateTranslation(padding.Left + offsetX, top)))
457-
{
458-
TextLayout.Draw(context);
459-
}
438+
TextLayout.Draw(context, new Point(padding.Left, top));
460439
}
461440

462441
/// <summary>

src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSiz
9090
return new HeadlessBitmapStub(destinationSize, new Vector(96, 96));
9191
}
9292

93-
public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width)
93+
public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun)
9494
{
95-
width = 100;
9695
return new HeadlessGlyphRunStub();
9796
}
9897

src/Avalonia.Input/MouseDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ private void SetPointerOver(IPointerDevice device, ulong timestamp, IInputRoot r
435435

436436
IInputElement? branch = null;
437437

438-
var el = element;
438+
IInputElement? el = element;
439439

440440
while (el != null)
441441
{
Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,66 @@
11
Compat issues with assembly Avalonia.Visuals:
2+
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract.
3+
CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' is abstract in the implementation but is missing in the contract.
4+
CannotSealType : Type 'Avalonia.Media.TextFormatting.GenericTextParagraphProperties' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
5+
CannotMakeMemberNonVirtual : Member 'public Avalonia.Media.TextFormatting.TextRunProperties Avalonia.Media.TextFormatting.GenericTextParagraphProperties.DefaultTextRunProperties' is non-virtual in the implementation but is virtual in the contract.
6+
CannotMakeMemberNonVirtual : Member 'public System.Double Avalonia.Media.TextFormatting.GenericTextParagraphProperties.LineHeight' is non-virtual in the implementation but is virtual in the contract.
7+
CannotMakeMemberNonVirtual : Member 'public Avalonia.Media.TextAlignment Avalonia.Media.TextFormatting.GenericTextParagraphProperties.TextAlignment' is non-virtual in the implementation but is virtual in the contract.
8+
CannotMakeMemberNonVirtual : Member 'public Avalonia.Media.TextWrapping Avalonia.Media.TextFormatting.GenericTextParagraphProperties.TextWrapping' is non-virtual in the implementation but is virtual in the contract.
9+
CannotMakeMemberNonVirtual : Member 'public Avalonia.Media.TextFormatting.TextRunProperties Avalonia.Media.TextFormatting.GenericTextParagraphProperties.DefaultTextRunProperties.get()' is non-virtual in the implementation but is virtual in the contract.
10+
CannotMakeMemberNonVirtual : Member 'public System.Double Avalonia.Media.TextFormatting.GenericTextParagraphProperties.LineHeight.get()' is non-virtual in the implementation but is virtual in the contract.
11+
CannotMakeMemberNonVirtual : Member 'public Avalonia.Media.TextAlignment Avalonia.Media.TextFormatting.GenericTextParagraphProperties.TextAlignment.get()' is non-virtual in the implementation but is virtual in the contract.
12+
CannotMakeMemberNonVirtual : Member 'public Avalonia.Media.TextWrapping Avalonia.Media.TextFormatting.GenericTextParagraphProperties.TextWrapping.get()' is non-virtual in the implementation but is virtual in the contract.
13+
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.GenericTextRunProperties..ctor(Avalonia.Media.Typeface, System.Double, Avalonia.Media.TextDecorationCollection, Avalonia.Media.IBrush, Avalonia.Media.IBrush, System.Globalization.CultureInfo)' does not exist in the implementation but it does exist in the contract.
14+
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.ShapedTextCharacters.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract.
15+
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.TextEndOfLine..ctor()' does not exist in the implementation but it does exist in the contract.
16+
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.TextLayout.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract.
17+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Baseline' is abstract in the implementation but is missing in the contract.
18+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Extent' is abstract in the implementation but is missing in the contract.
19+
CannotAddAbstractMembers : Member 'public System.Boolean Avalonia.Media.TextFormatting.TextLine.HasOverflowed' is abstract in the implementation but is missing in the contract.
20+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Height' is abstract in the implementation but is missing in the contract.
21+
CannotAddAbstractMembers : Member 'public System.Int32 Avalonia.Media.TextFormatting.TextLine.NewLineLength' is abstract in the implementation but is missing in the contract.
22+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.OverhangAfter' is abstract in the implementation but is missing in the contract.
23+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.OverhangLeading' is abstract in the implementation but is missing in the contract.
24+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.OverhangTrailing' is abstract in the implementation but is missing in the contract.
25+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Start' is abstract in the implementation but is missing in the contract.
26+
CannotAddAbstractMembers : Member 'public System.Int32 Avalonia.Media.TextFormatting.TextLine.TrailingWhitespaceLength' is abstract in the implementation but is missing in the contract.
27+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Width' is abstract in the implementation but is missing in the contract.
28+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.WidthIncludingTrailingWhitespace' is abstract in the implementation but is missing in the contract.
29+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Baseline.get()' is abstract in the implementation but is missing in the contract.
30+
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.TextLine.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract.
31+
CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.TextLine.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' is abstract in the implementation but is missing in the contract.
32+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Extent.get()' is abstract in the implementation but is missing in the contract.
33+
CannotAddAbstractMembers : Member 'public System.Boolean Avalonia.Media.TextFormatting.TextLine.HasOverflowed.get()' is abstract in the implementation but is missing in the contract.
34+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Height.get()' is abstract in the implementation but is missing in the contract.
35+
MembersMustExist : Member 'public Avalonia.Media.TextFormatting.TextLineMetrics Avalonia.Media.TextFormatting.TextLine.LineMetrics.get()' does not exist in the implementation but it does exist in the contract.
36+
CannotAddAbstractMembers : Member 'public System.Int32 Avalonia.Media.TextFormatting.TextLine.NewLineLength.get()' is abstract in the implementation but is missing in the contract.
37+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.OverhangAfter.get()' is abstract in the implementation but is missing in the contract.
38+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.OverhangLeading.get()' is abstract in the implementation but is missing in the contract.
39+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.OverhangTrailing.get()' is abstract in the implementation but is missing in the contract.
40+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Start.get()' is abstract in the implementation but is missing in the contract.
41+
CannotAddAbstractMembers : Member 'public System.Int32 Avalonia.Media.TextFormatting.TextLine.TrailingWhitespaceLength.get()' is abstract in the implementation but is missing in the contract.
42+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.Width.get()' is abstract in the implementation but is missing in the contract.
43+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextLine.WidthIncludingTrailingWhitespace.get()' is abstract in the implementation but is missing in the contract.
44+
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.TextLineMetrics..ctor(Avalonia.Size, System.Double, Avalonia.Media.TextFormatting.TextRange, System.Boolean)' does not exist in the implementation but it does exist in the contract.
45+
MembersMustExist : Member 'public Avalonia.Media.TextFormatting.TextLineMetrics Avalonia.Media.TextFormatting.TextLineMetrics.Create(System.Collections.Generic.IEnumerable<Avalonia.Media.TextFormatting.TextRun>, Avalonia.Media.TextFormatting.TextRange, System.Double, Avalonia.Media.TextFormatting.TextParagraphProperties)' does not exist in the implementation but it does exist in the contract.
46+
MembersMustExist : Member 'public Avalonia.Size Avalonia.Media.TextFormatting.TextLineMetrics.Size.get()' does not exist in the implementation but it does exist in the contract.
47+
MembersMustExist : Member 'public Avalonia.Media.TextFormatting.TextRange Avalonia.Media.TextFormatting.TextLineMetrics.TextRange.get()' does not exist in the implementation but it does exist in the contract.
48+
CannotAddAbstractMembers : Member 'public System.Boolean Avalonia.Media.TextFormatting.TextParagraphProperties.FirstLineInParagraph' is abstract in the implementation but is missing in the contract.
49+
CannotAddAbstractMembers : Member 'public Avalonia.Media.FlowDirection Avalonia.Media.TextFormatting.TextParagraphProperties.FlowDirection' is abstract in the implementation but is missing in the contract.
50+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextParagraphProperties.Indent' is abstract in the implementation but is missing in the contract.
51+
CannotAddAbstractMembers : Member 'public System.Boolean Avalonia.Media.TextFormatting.TextParagraphProperties.FirstLineInParagraph.get()' is abstract in the implementation but is missing in the contract.
52+
CannotAddAbstractMembers : Member 'public Avalonia.Media.FlowDirection Avalonia.Media.TextFormatting.TextParagraphProperties.FlowDirection.get()' is abstract in the implementation but is missing in the contract.
53+
CannotAddAbstractMembers : Member 'public System.Double Avalonia.Media.TextFormatting.TextParagraphProperties.Indent.get()' is abstract in the implementation but is missing in the contract.
54+
CannotAddAbstractMembers : Member 'public Avalonia.Media.BaselineAlignment Avalonia.Media.TextFormatting.TextRunProperties.BaselineAlignment' is abstract in the implementation but is missing in the contract.
55+
CannotAddAbstractMembers : Member 'public Avalonia.Media.BaselineAlignment Avalonia.Media.TextFormatting.TextRunProperties.BaselineAlignment.get()' is abstract in the implementation but is missing in the contract.
256
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.PopBitmapBlendMode()' is present in the implementation but not in the contract.
357
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.PushBitmapBlendMode(Avalonia.Visuals.Media.Imaging.BitmapBlendingMode)' is present in the implementation but not in the contract.
458
InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength' is present in the implementation but not in the contract.
559
InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength.get()' is present in the implementation but not in the contract.
660
InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAndTangentAtDistance(System.Double, Avalonia.Point, Avalonia.Point)' is present in the implementation but not in the contract.
761
InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAtDistance(System.Double, Avalonia.Point)' is present in the implementation but not in the contract.
862
InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetSegment(System.Double, System.Double, System.Boolean, Avalonia.Platform.IGeometryImpl)' is present in the implementation but not in the contract.
9-
Total Issues: 7
63+
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun)' is present in the implementation but not in the contract.
64+
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun, System.Double)' is present in the contract but not in the implementation.
65+
MembersMustExist : Member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun, System.Double)' does not exist in the implementation but it does exist in the contract.
66+
Total Issues: 64
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace Avalonia.Media
2+
{
3+
/// <summary>
4+
/// Enum specifying where a box should be positioned Vertically
5+
/// </summary>
6+
public enum BaselineAlignment
7+
{
8+
/// <summary>Align top toward top of container</summary>
9+
Top,
10+
11+
/// <summary>Center vertically</summary>
12+
Center,
13+
14+
/// <summary>Align bottom toward bottom of container</summary>
15+
Bottom,
16+
17+
/// <summary>Align at baseline</summary>
18+
Baseline,
19+
20+
/// <summary>Align toward text's top of container</summary>
21+
TextTop,
22+
23+
/// <summary>Align toward text's bottom of container</summary>
24+
TextBottom,
25+
26+
/// <summary>Align baseline to subscript position of container</summary>
27+
Subscript,
28+
29+
/// <summary>Align baseline to superscript position of container</summary>
30+
Superscript,
31+
}
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace Avalonia.Media
2+
{
3+
/// <summary>
4+
/// The 'flow-direction' property specifies whether the primary text advance
5+
/// direction shall be left-to-right or right-to-left.
6+
/// </summary>
7+
public enum FlowDirection
8+
{
9+
/// <internalonly>
10+
/// Sets the primary text advance direction to left-to-right, and the line
11+
/// progression direction to top-to-bottom as is common in most Roman-based
12+
/// documents. For most characters, the current text position is advanced
13+
/// from left to right after each glyph is rendered. The 'direction' property
14+
/// is set to 'ltr'.
15+
/// </internalonly>
16+
LeftToRight,
17+
18+
/// <internalonly>
19+
/// Sets the primary text advance direction to right-to-left, and the line
20+
/// progression direction to top-to-bottom as is common in Arabic or Hebrew
21+
/// scripts. The direction property is set to 'rtl'.
22+
/// </internalonly>
23+
RightToLeft
24+
}
25+
}

0 commit comments

Comments
 (0)