Browse Source

Introduce GlyphRun.Bounds

pull/10530/head
Benedikt Stebner 3 years ago
parent
commit
147db08f90
  1. 14
      src/Avalonia.Base/Media/GlyphRun.cs
  2. 2
      src/Avalonia.Base/Media/GlyphRunDrawing.cs
  3. 2
      src/Avalonia.Base/Media/TextDecoration.cs
  4. 4
      src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs
  5. 2
      src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs
  6. 2
      src/Avalonia.Base/Media/TextFormatting/TextLeadingPrefixCharacterEllipsis.cs
  7. 6
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
  8. 3
      src/Avalonia.Base/Platform/IGlyphRunImpl.cs
  9. 8
      src/Avalonia.Base/Rendering/Composition/Server/DiagnosticTextRenderer.cs
  10. 5
      src/Avalonia.Base/Rendering/SceneGraph/GlyphRunNode.cs
  11. 4
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  12. 2
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  13. 4
      src/Skia/Avalonia.Skia/GlyphRunImpl.cs
  14. 4
      src/Windows/Avalonia.Direct2D1/Media/GlyphRunImpl.cs
  15. 2
      tests/Avalonia.Benchmarks/NullGlyphRun.cs
  16. 4
      tests/Avalonia.UnitTests/MockGlyphRun.cs

14
src/Avalonia.Base/Media/GlyphRun.cs

@ -151,9 +151,9 @@ namespace Avalonia.Media
}
/// <summary>
/// Gets or sets the conservative bounding box of the <see cref="GlyphRun"/>.
/// Gets the conservative bounding box of the <see cref="GlyphRun"/>.
/// </summary>
public Size Size => PlatformImpl.Item.Size;
public Rect Bounds => PlatformImpl.Item.Bounds;
/// <summary>
///
@ -252,7 +252,7 @@ namespace Avalonia.Media
if (characterIndex > Metrics.LastCluster)
{
return Size.Width;
return Bounds.Width;
}
var glyphIndex = FindGlyphIndex(characterIndex);
@ -287,7 +287,7 @@ namespace Avalonia.Media
if (characterIndex <= Metrics.FirstCluster)
{
return Size.Width;
return Bounds.Width;
}
for (var i = glyphIndex + 1; i < _glyphInfos.Count; i++)
@ -295,7 +295,7 @@ namespace Avalonia.Media
distance += _glyphInfos[i].GlyphAdvance;
}
return Size.Width - distance;
return Bounds.Width - distance;
}
}
@ -321,7 +321,7 @@ namespace Avalonia.Media
}
//After
if (distance >= Size.Width)
if (distance >= Bounds.Width)
{
isInside = false;
@ -354,7 +354,7 @@ namespace Avalonia.Media
}
else
{
currentX = Size.Width;
currentX = Bounds.Width;
for (var index = _glyphInfos.Count - 1; index >= 0; index--)
{

2
src/Avalonia.Base/Media/GlyphRunDrawing.cs

@ -32,7 +32,7 @@
public override Rect GetBounds()
{
return GlyphRun != null ? new Rect(GlyphRun.Size) : default;
return GlyphRun != null ? GlyphRun.Bounds : default;
}
}
}

2
src/Avalonia.Base/Media/TextDecoration.cs

@ -223,7 +223,7 @@ namespace Avalonia.Media
if (intersections.Count > 0)
{
var last = baselineOrigin.X;
var finalPos = last + glyphRun.Size.Width;
var finalPos = last + glyphRun.Bounds.Width;
var end = last;
var points = new List<double>();

4
src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs

@ -38,14 +38,14 @@ namespace Avalonia.Media.TextFormatting
public override double Baseline => -TextMetrics.Ascent;
public override Size Size => GlyphRun.Size;
public override Size Size => GlyphRun.Bounds.Size;
public GlyphRun GlyphRun => _glyphRun ??= CreateGlyphRun();
/// <inheritdoc/>
public override void Draw(DrawingContext drawingContext, Point origin)
{
using (drawingContext.PushPreTransform(Matrix.CreateTranslation(origin)))
using (drawingContext.PushTransform(Matrix.CreateTranslation(origin)))
{
if (GlyphRun.GlyphInfos.Count == 0)
{

2
src/Avalonia.Base/Media/TextFormatting/TextEllipsisHelper.cs

@ -19,7 +19,7 @@ namespace Avalonia.Media.TextFormatting
var collapsedLength = 0;
var shapedSymbol = TextFormatterImpl.CreateSymbol(properties.Symbol, FlowDirection.LeftToRight);
if (properties.Width < shapedSymbol.GlyphRun.Size.Width)
if (properties.Width < shapedSymbol.GlyphRun.Bounds.Width)
{
//Not enough space to fit in the symbol
return Array.Empty<TextRun>();

2
src/Avalonia.Base/Media/TextFormatting/TextLeadingPrefixCharacterEllipsis.cs

@ -60,7 +60,7 @@ namespace Avalonia.Media.TextFormatting
var currentWidth = 0.0;
var shapedSymbol = TextFormatterImpl.CreateSymbol(Symbol, FlowDirection.LeftToRight);
if (Width < shapedSymbol.GlyphRun.Size.Width)
if (Width < shapedSymbol.GlyphRun.Bounds.Width)
{
return Array.Empty<TextRun>();
}

6
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

@ -423,7 +423,7 @@ namespace Avalonia.Media.TextFormatting
{
if (currentGlyphRun != null)
{
currentDistance -= currentGlyphRun.Size.Width;
currentDistance -= currentGlyphRun.Bounds.Width;
}
return currentDistance + distance;
@ -477,7 +477,7 @@ namespace Avalonia.Media.TextFormatting
{
if (currentGlyphRun.IsLeftToRight || flowDirection == FlowDirection.RightToLeft)
{
distance = currentGlyphRun.Size.Width;
distance = currentGlyphRun.Bounds.Width;
}
return true;
@ -1483,7 +1483,7 @@ namespace Avalonia.Media.TextFormatting
trailingWhitespaceLength += glyphRunMetrics.TrailingWhitespaceLength;
var whitespaceWidth = glyphRun.Size.Width - glyphRunMetrics.Width;
var whitespaceWidth = glyphRun.Bounds.Width - glyphRunMetrics.Width;
width -= whitespaceWidth;
}

3
src/Avalonia.Base/Platform/IGlyphRunImpl.cs

@ -10,11 +10,10 @@ namespace Avalonia.Platform
[Unstable]
public interface IGlyphRunImpl : IDisposable
{
/// <summary>
/// Gets the conservative bounding box of the glyph run./>.
/// </summary>
Size Size { get; }
Rect Bounds { get; }
/// <summary>
/// Gets the baseline origin of the glyph run./>.

8
src/Avalonia.Base/Rendering/Composition/Server/DiagnosticTextRenderer.cs

@ -20,7 +20,7 @@ namespace Avalonia.Rendering.Composition.Server
for (var c = FirstChar; c <= LastChar; c++)
{
var height = _runs[c - FirstChar].Size.Height;
var height = _runs[c - FirstChar].Bounds.Height;
if (height > maxHeight)
{
maxHeight = height;
@ -51,8 +51,8 @@ namespace Avalonia.Rendering.Composition.Server
{
var effectiveChar = c is >= FirstChar and <= LastChar ? c : ' ';
var run = _runs[effectiveChar - FirstChar];
width += run.Size.Width;
height = Math.Max(height, run.Size.Height);
width += run.Bounds.Width;
height = Math.Max(height, run.Bounds.Height);
}
return new Size(width, height);
@ -69,7 +69,7 @@ namespace Avalonia.Rendering.Composition.Server
var run = _runs[effectiveChar - FirstChar];
context.Transform = originalTransform * Matrix.CreateTranslation(offset, 0.0);
context.DrawGlyphRun(foreground, run.PlatformImpl);
offset += run.Size.Width;
offset += run.Bounds.Width;
}
context.Transform = originalTransform;

5
src/Avalonia.Base/Rendering/SceneGraph/GlyphRunNode.cs

@ -16,12 +16,11 @@ namespace Avalonia.Rendering.SceneGraph
/// <param name="transform">The transform.</param>
/// <param name="foreground">The foreground brush.</param>
/// <param name="glyphRun">The glyph run to draw.</param>
/// <param name="aux">Auxiliary data required to draw the brush.</param>
public GlyphRunNode(
Matrix transform,
IImmutableBrush foreground,
IRef<IGlyphRunImpl> glyphRun)
: base(new Rect(glyphRun.Item.BaselineOrigin, glyphRun.Item.Size), transform, foreground)
: base(glyphRun.Item.Bounds, transform, foreground)
{
GlyphRun = glyphRun.Clone();
}
@ -54,7 +53,7 @@ namespace Avalonia.Rendering.SceneGraph
}
/// <inheritdoc/>
public override bool HitTest(Point p) => new Rect(GlyphRun.Item.Size).ContainsExclusive(p);
public override bool HitTest(Point p) => GlyphRun.Item.Bounds.ContainsExclusive(p);
public override void Dispose()
{

4
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@ -118,7 +118,7 @@ namespace Avalonia.Headless
public IGeometryImpl BuildGlyphRunGeometry(GlyphRun glyphRun)
{
return new HeadlessGeometryStub(new Rect(glyphRun.Size));
return new HeadlessGeometryStub(glyphRun.Bounds);
}
public IGlyphRunImpl CreateGlyphRun(
@ -132,7 +132,7 @@ namespace Avalonia.Headless
class HeadlessGlyphRunStub : IGlyphRunImpl
{
public Size Size => new Size(8, 12);
public Rect Bounds => new Rect(new Size(8, 12));
public Point BaselineOrigin => new Point(0, 8);

2
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -516,7 +516,7 @@ namespace Avalonia.Skia
return;
}
using (var paintWrapper = CreatePaint(_fillPaint, foreground, glyphRun.Item.Size))
using (var paintWrapper = CreatePaint(_fillPaint, foreground, glyphRun.Item.Bounds.Size))
{
var glyphRunImpl = (GlyphRunImpl)glyphRun.Item;

4
src/Skia/Avalonia.Skia/GlyphRunImpl.cs

@ -11,7 +11,7 @@ namespace Avalonia.Skia
{
TextBlob = textBlob ?? throw new ArgumentNullException(nameof(textBlob));
Size = size;
Bounds = new Rect(new Point(baselineOrigin.X, 0), size);
BaselineOrigin = baselineOrigin;
}
@ -21,7 +21,7 @@ namespace Avalonia.Skia
/// </summary>
public SKTextBlob TextBlob { get; }
public Size Size { get; }
public Rect Bounds { get; }
public Point BaselineOrigin { get; }

4
src/Windows/Avalonia.Direct2D1/Media/GlyphRunImpl.cs

@ -9,12 +9,12 @@ namespace Avalonia.Direct2D1.Media
{
public GlyphRunImpl(GlyphRun glyphRun, Size size, Point baselineOrigin)
{
Size = size;
Bounds = new Rect(new Point(baselineOrigin.X, 0), size);
BaselineOrigin = baselineOrigin;
GlyphRun = glyphRun;
}
public Size Size { get; }
public Rect Bounds{ get; }
public Point BaselineOrigin { get; }

2
tests/Avalonia.Benchmarks/NullGlyphRun.cs

@ -5,7 +5,7 @@ namespace Avalonia.Benchmarks
{
internal class NullGlyphRun : IGlyphRunImpl
{
public Size Size => default;
public Rect Bounds => default;
public Point BaselineOrigin => default;

4
tests/Avalonia.UnitTests/MockGlyphRun.cs

@ -16,10 +16,10 @@ namespace Avalonia.UnitTests
width += glyphInfos[i].GlyphAdvance;
}
Size = new Size(width, 10);
Bounds = new Rect(new Size(width, 10));
}
public Size Size { get; }
public Rect Bounds { get; }
public Point BaselineOrigin => new Point(0, 8);

Loading…
Cancel
Save