Browse Source

Support intercepts for all location but TextDecorationLocation.Strikethrough

pull/9896/head
Benedikt Stebner 3 years ago
parent
commit
74bbfd8509
  1. 19
      src/Avalonia.Base/Media/TextDecoration.cs
  2. 8
      tests/Avalonia.Benchmarks/NullGlyphRun.cs

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

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Avalonia.Collections;
using Avalonia.Collections.Pooled;
using Avalonia.Media.TextFormatting;
@ -200,26 +201,24 @@ namespace Avalonia.Media
break;
}
var strokeOffset = 0.0;
switch (StrokeOffsetUnit)
{
case TextDecorationUnit.FontRenderingEmSize:
strokeOffset = StrokeOffset * textMetrics.FontRenderingEmSize;
origin += new Point(0, StrokeOffset * textMetrics.FontRenderingEmSize);
break;
case TextDecorationUnit.Pixel:
strokeOffset = StrokeOffset;
origin += new Point(0, StrokeOffset);
break;
}
origin += new Point(0, strokeOffset);
var pen = new Pen(Stroke ?? defaultBrush, thickness,
new DashStyle(StrokeDashArray, StrokeDashOffset), StrokeLineCap);
if (Location == TextDecorationLocation.Underline && MathUtilities.IsZero(strokeOffset))
if (Location != TextDecorationLocation.Strikethrough)
{
var intersections = glyphRun.GlyphRunImpl.GetIntersections((float)(thickness * 0.5d + strokeOffset), (float)(thickness * 1.5d + strokeOffset));
var offsetY = glyphRun.BaselineOrigin.Y - origin.Y;
var intersections = glyphRun.GlyphRunImpl.GetIntersections((float)(thickness * 0.5d - offsetY), (float)(thickness * 1.5d - offsetY));
if (intersections != null && intersections.Count > 0)
{
@ -257,7 +256,7 @@ namespace Avalonia.Media
}
return;
}
}
}
drawingContext.DrawLine(pen, origin, origin + new Point(glyphRun.Metrics.Width, 0));

8
tests/Avalonia.Benchmarks/NullGlyphRun.cs

@ -1,4 +1,5 @@
using Avalonia.Platform;
using System.Collections.Generic;
using Avalonia.Platform;
namespace Avalonia.Benchmarks
{
@ -7,5 +8,10 @@ namespace Avalonia.Benchmarks
public void Dispose()
{
}
public IReadOnlyList<float> GetIntersections(float lowerBound, float upperBound)
{
return null;
}
}
}

Loading…
Cancel
Save