From 6b8f867006ca210e97d467e6fd2c954132305e23 Mon Sep 17 00:00:00 2001 From: Benedikt Schroeder Date: Tue, 12 May 2020 09:56:50 +0200 Subject: [PATCH] Initialize the GlyphRun on render --- src/Avalonia.Visuals/Media/GlyphRun.cs | 22 +++++-------------- .../TextLayoutTests.cs | 2 +- .../Avalonia.UnitTests/MockTextShaperImpl.cs | 3 +-- .../Media/GlyphRunTests.cs | 4 +--- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/Avalonia.Visuals/Media/GlyphRun.cs b/src/Avalonia.Visuals/Media/GlyphRun.cs index 86c6a7bf2d..29c9d93560 100644 --- a/src/Avalonia.Visuals/Media/GlyphRun.cs +++ b/src/Avalonia.Visuals/Media/GlyphRun.cs @@ -44,7 +44,6 @@ namespace Avalonia.Media /// The characters. /// The glyph clusters. /// The bidi level. - /// The bound. public GlyphRun( GlyphTypeface glyphTypeface, double fontRenderingEmSize, @@ -53,8 +52,7 @@ namespace Avalonia.Media ReadOnlySlice glyphOffsets = default, ReadOnlySlice characters = default, ReadOnlySlice glyphClusters = default, - int biDiLevel = 0, - Rect? bounds = null) + int biDiLevel = 0) { GlyphTypeface = glyphTypeface; @@ -71,8 +69,6 @@ namespace Avalonia.Media GlyphClusters = glyphClusters; BiDiLevel = biDiLevel; - - Initialize(bounds); } /// @@ -182,7 +178,7 @@ namespace Avalonia.Media { if (_glyphRunImpl == null) { - Initialize(null); + Initialize(); } return _glyphRunImpl; @@ -517,8 +513,7 @@ namespace Avalonia.Media /// /// Initializes the . /// - /// Optional pre computed bounds. - private void Initialize(Rect? bounds) + private void Initialize() { if (GlyphIndices.Length == 0) { @@ -541,16 +536,9 @@ namespace Avalonia.Media _glyphRunImpl = platformRenderInterface.CreateGlyphRun(this, out var width); - if (bounds.HasValue) - { - _bounds = bounds; - } - else - { - var height = (GlyphTypeface.Descent - GlyphTypeface.Ascent + GlyphTypeface.LineGap) * Scale; + var height = (GlyphTypeface.Descent - GlyphTypeface.Ascent + GlyphTypeface.LineGap) * Scale; - _bounds = new Rect(0, 0, width, height); - } + _bounds = new Rect(0, 0, width, height); } void IDisposable.Dispose() diff --git a/tests/Avalonia.Skia.UnitTests/TextLayoutTests.cs b/tests/Avalonia.Skia.UnitTests/TextLayoutTests.cs index 627b7c2ead..0d9fd31e52 100644 --- a/tests/Avalonia.Skia.UnitTests/TextLayoutTests.cs +++ b/tests/Avalonia.Skia.UnitTests/TextLayoutTests.cs @@ -508,7 +508,7 @@ namespace Avalonia.Skia.UnitTests private const string Text = "日本でTest一番読まれている英字新聞・ジャパンタイムズが発信する国内外ニュースと、様々なジャンルの特集記事。"; - [Fact] + [Fact(Skip= "Only used for profiling.")] public void Should_Wrap() { using (Start()) diff --git a/tests/Avalonia.UnitTests/MockTextShaperImpl.cs b/tests/Avalonia.UnitTests/MockTextShaperImpl.cs index de1842b692..0772e0e9bd 100644 --- a/tests/Avalonia.UnitTests/MockTextShaperImpl.cs +++ b/tests/Avalonia.UnitTests/MockTextShaperImpl.cs @@ -30,8 +30,7 @@ namespace Avalonia.UnitTests width += glyphTypeface.GetGlyphAdvance(glyph); } - return new GlyphRun(glyphTypeface, textFormat.FontRenderingEmSize, glyphIndices, characters: text, - bounds: new Rect(0, 0, width, height)); + return new GlyphRun(glyphTypeface, textFormat.FontRenderingEmSize, glyphIndices, characters: text); } } } diff --git a/tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs b/tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs index 5d6d830a43..028caa35c6 100644 --- a/tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs +++ b/tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs @@ -128,10 +128,8 @@ namespace Avalonia.Visuals.UnitTests.Media var characters = new ReadOnlySlice(new char[count], start, count); - var bounds = new Rect(0, 0, count * 10, 10); - return new GlyphRun(new GlyphTypeface(new MockGlyphTypeface()), 10, glyphIndices, glyphAdvances, - glyphClusters: glyphClusters, characters: characters, biDiLevel: bidiLevel, bounds: bounds); + glyphClusters: glyphClusters, characters: characters, biDiLevel: bidiLevel); } } }