Browse Source

Initialize the GlyphRun on render

pull/3922/head
Benedikt Schroeder 6 years ago
parent
commit
6b8f867006
  1. 22
      src/Avalonia.Visuals/Media/GlyphRun.cs
  2. 2
      tests/Avalonia.Skia.UnitTests/TextLayoutTests.cs
  3. 3
      tests/Avalonia.UnitTests/MockTextShaperImpl.cs
  4. 4
      tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs

22
src/Avalonia.Visuals/Media/GlyphRun.cs

@ -44,7 +44,6 @@ namespace Avalonia.Media
/// <param name="characters">The characters.</param> /// <param name="characters">The characters.</param>
/// <param name="glyphClusters">The glyph clusters.</param> /// <param name="glyphClusters">The glyph clusters.</param>
/// <param name="biDiLevel">The bidi level.</param> /// <param name="biDiLevel">The bidi level.</param>
/// <param name="bounds">The bound.</param>
public GlyphRun( public GlyphRun(
GlyphTypeface glyphTypeface, GlyphTypeface glyphTypeface,
double fontRenderingEmSize, double fontRenderingEmSize,
@ -53,8 +52,7 @@ namespace Avalonia.Media
ReadOnlySlice<Vector> glyphOffsets = default, ReadOnlySlice<Vector> glyphOffsets = default,
ReadOnlySlice<char> characters = default, ReadOnlySlice<char> characters = default,
ReadOnlySlice<ushort> glyphClusters = default, ReadOnlySlice<ushort> glyphClusters = default,
int biDiLevel = 0, int biDiLevel = 0)
Rect? bounds = null)
{ {
GlyphTypeface = glyphTypeface; GlyphTypeface = glyphTypeface;
@ -71,8 +69,6 @@ namespace Avalonia.Media
GlyphClusters = glyphClusters; GlyphClusters = glyphClusters;
BiDiLevel = biDiLevel; BiDiLevel = biDiLevel;
Initialize(bounds);
} }
/// <summary> /// <summary>
@ -182,7 +178,7 @@ namespace Avalonia.Media
{ {
if (_glyphRunImpl == null) if (_glyphRunImpl == null)
{ {
Initialize(null); Initialize();
} }
return _glyphRunImpl; return _glyphRunImpl;
@ -517,8 +513,7 @@ namespace Avalonia.Media
/// <summary> /// <summary>
/// Initializes the <see cref="GlyphRun"/>. /// Initializes the <see cref="GlyphRun"/>.
/// </summary> /// </summary>
/// <param name="bounds">Optional pre computed bounds.</param> private void Initialize()
private void Initialize(Rect? bounds)
{ {
if (GlyphIndices.Length == 0) if (GlyphIndices.Length == 0)
{ {
@ -541,16 +536,9 @@ namespace Avalonia.Media
_glyphRunImpl = platformRenderInterface.CreateGlyphRun(this, out var width); _glyphRunImpl = platformRenderInterface.CreateGlyphRun(this, out var width);
if (bounds.HasValue) var height = (GlyphTypeface.Descent - GlyphTypeface.Ascent + GlyphTypeface.LineGap) * Scale;
{
_bounds = bounds;
}
else
{
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() void IDisposable.Dispose()

2
tests/Avalonia.Skia.UnitTests/TextLayoutTests.cs

@ -508,7 +508,7 @@ namespace Avalonia.Skia.UnitTests
private const string Text = "日本でTest一番読まれている英字新聞・ジャパンタイムズが発信する国内外ニュースと、様々なジャンルの特集記事。"; private const string Text = "日本でTest一番読まれている英字新聞・ジャパンタイムズが発信する国内外ニュースと、様々なジャンルの特集記事。";
[Fact] [Fact(Skip= "Only used for profiling.")]
public void Should_Wrap() public void Should_Wrap()
{ {
using (Start()) using (Start())

3
tests/Avalonia.UnitTests/MockTextShaperImpl.cs

@ -30,8 +30,7 @@ namespace Avalonia.UnitTests
width += glyphTypeface.GetGlyphAdvance(glyph); width += glyphTypeface.GetGlyphAdvance(glyph);
} }
return new GlyphRun(glyphTypeface, textFormat.FontRenderingEmSize, glyphIndices, characters: text, return new GlyphRun(glyphTypeface, textFormat.FontRenderingEmSize, glyphIndices, characters: text);
bounds: new Rect(0, 0, width, height));
} }
} }
} }

4
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 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, return new GlyphRun(new GlyphTypeface(new MockGlyphTypeface()), 10, glyphIndices, glyphAdvances,
glyphClusters: glyphClusters, characters: characters, biDiLevel: bidiLevel, bounds: bounds); glyphClusters: glyphClusters, characters: characters, biDiLevel: bidiLevel);
} }
} }
} }

Loading…
Cancel
Save