Browse Source

Merge pull request #3922 from Gillibald/initializeGlyphRunOnRender

Initialize the GlyphRunImpl on render
Steven Kirk 5 years ago
parent
commit
ccc651b9ef

+ 5 - 17
src/Avalonia.Visuals/Media/GlyphRun.cs

@@ -44,7 +44,6 @@ namespace Avalonia.Media
         /// <param name="characters">The characters.</param>
         /// <param name="glyphClusters">The glyph clusters.</param>
         /// <param name="biDiLevel">The bidi level.</param>
-        /// <param name="bounds">The bound.</param>
         public GlyphRun(
             GlyphTypeface glyphTypeface,
             double fontRenderingEmSize,
@@ -53,8 +52,7 @@ namespace Avalonia.Media
             ReadOnlySlice<Vector> glyphOffsets = default,
             ReadOnlySlice<char> characters = default,
             ReadOnlySlice<ushort> 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);
         }
 
         /// <summary>
@@ -182,7 +178,7 @@ namespace Avalonia.Media
             {
                 if (_glyphRunImpl == null)
                 {
-                    Initialize(null);
+                    Initialize();
                 }
 
                 return _glyphRunImpl;
@@ -517,8 +513,7 @@ namespace Avalonia.Media
         /// <summary>
         /// Initializes the <see cref="GlyphRun"/>.
         /// </summary>
-        /// <param name="bounds">Optional pre computed bounds.</param>
-        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()

+ 1 - 1
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())

+ 1 - 2
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);
         }
     }
 }

+ 1 - 3
tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs

@@ -128,10 +128,8 @@ namespace Avalonia.Visuals.UnitTests.Media
 
             var characters = new ReadOnlySlice<char>(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);
         }
     }
 }