Browse Source

Skia - Correctly translate current position when multiple glyphs are added to a path

pull/8313/head
Benedikt Stebner 4 years ago
parent
commit
73c06b323e
  1. 15
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  2. 27
      tests/Avalonia.RenderTests/Media/GlyphRunTests.cs
  3. BIN
      tests/TestFiles/Direct2D1/Media/GlyphRun/Should_Render_GlyphRun_Geometry.expected.png
  4. BIN
      tests/TestFiles/Skia/Media/GlyphRun/Should_Render_GlyphRun_Geometry.expected.png

15
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs

@ -70,7 +70,6 @@ namespace Avalonia.Skia
}
var fontRenderingEmSize = (float)glyphRun.FontRenderingEmSize;
var glyphs = glyphRun.GlyphIndices.ToArray();
var skFont = new SKFont(glyphTypeface.Typeface, fontRenderingEmSize)
{
Size = fontRenderingEmSize,
@ -79,15 +78,19 @@ namespace Avalonia.Skia
LinearMetrics = true
};
SKPath path = null;
SKPath path = new SKPath();
var matrix = SKMatrix.Identity;
skFont.GetGlyphPaths(glyphs, (p, m) =>
var currentX = 0f;
foreach (var glyph in glyphRun.GlyphIndices)
{
matrix = m;
var p = skFont.GetGlyphPath(glyph);
path.AddPath(p, currentX, 0);
path = p;
});
currentX += p.Bounds.Right;
}
scale = Matrix.CreateScale(matrix.ScaleX, matrix.ScaleY);

27
tests/Avalonia.RenderTests/Media/GlyphRunTests.cs

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Shapes;
using Avalonia.Media;
using Avalonia.Media.Imaging;
@ -25,9 +26,21 @@ namespace Avalonia.Direct2D1.RenderTests.Media
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 80,
Height = 90,
Child = new GlyphRunGeometryControl()
Width = 200,
Height = 100,
Child = new GlyphRunGeometryControl
{
[TextElement.ForegroundProperty] = new LinearGradientBrush
{
StartPoint = new RelativePoint(0, 0.5, RelativeUnit.Relative),
EndPoint = new RelativePoint(1, 0.5, RelativeUnit.Relative),
GradientStops =
{
new GradientStop { Color = Colors.Red, Offset = 0 },
new GradientStop { Color = Colors.Blue, Offset = 1 }
}
}
}
};
await RenderToFile(target);
@ -43,9 +56,9 @@ namespace Avalonia.Direct2D1.RenderTests.Media
{
var glyphTypeface = Typeface.Default.GlyphTypeface;
var glyphIndices = new[] { glyphTypeface.GetGlyph('A') };
var glyphIndices = new[] { glyphTypeface.GetGlyph('A'), glyphTypeface.GetGlyph('B'), glyphTypeface.GetGlyph('C') };
var characters = new[] { 'A' };
var characters = new[] { 'A', 'B', 'C' };
var glyphRun = new GlyphRun(glyphTypeface, 100, characters, glyphIndices);
@ -59,7 +72,9 @@ namespace Avalonia.Direct2D1.RenderTests.Media
public override void Render(DrawingContext context)
{
context.DrawGeometry(Brushes.Green, null, _geometry);
var foreground = TextElement.GetForeground(this);
context.DrawGeometry(foreground, null, _geometry);
}
}
}

BIN
tests/TestFiles/Direct2D1/Media/GlyphRun/Should_Render_GlyphRun_Geometry.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
tests/TestFiles/Skia/Media/GlyphRun/Should_Render_GlyphRun_Geometry.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Loading…
Cancel
Save