Browse Source
Merge pull request #4833 from Gillibald/fixes/GlyphRunRendering
Make sure a GlyphRun's bounds are properly calculated
pull/4852/head
Jumar Macato
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
14 additions and
3 deletions
-
src/Avalonia.Visuals/Media/GlyphRun.cs
-
src/Avalonia.Visuals/Media/TextFormatting/TextLineImpl.cs
|
|
|
@ -18,7 +18,7 @@ namespace Avalonia.Media |
|
|
|
private double _fontRenderingEmSize; |
|
|
|
private Size? _size; |
|
|
|
private int _biDiLevel; |
|
|
|
private Point _baselineOrigin; |
|
|
|
private Point? _baselineOrigin; |
|
|
|
|
|
|
|
private ReadOnlySlice<ushort> _glyphIndices; |
|
|
|
private ReadOnlySlice<double> _glyphAdvances; |
|
|
|
@ -97,7 +97,9 @@ namespace Avalonia.Media |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return _baselineOrigin; |
|
|
|
_baselineOrigin ??= CalculateBaselineOrigin(); |
|
|
|
|
|
|
|
return _baselineOrigin.Value; |
|
|
|
} |
|
|
|
set => Set(ref _baselineOrigin, value); |
|
|
|
} |
|
|
|
@ -538,6 +540,15 @@ namespace Avalonia.Media |
|
|
|
return GlyphAdvances[index]; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Calculates the default baseline origin of the <see cref="GlyphRun"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The baseline origin.</returns>
|
|
|
|
private Point CalculateBaselineOrigin() |
|
|
|
{ |
|
|
|
return new Point(0, -GlyphTypeface.Ascent * Scale); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Calculates the size of the <see cref="GlyphRun"/>.
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
@ -39,7 +39,7 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
|
|
|
|
foreach (var textRun in _textRuns) |
|
|
|
{ |
|
|
|
var offsetY = LineMetrics.TextBaseline; |
|
|
|
var offsetY = LineMetrics.TextBaseline - textRun.GlyphRun.BaselineOrigin.Y; |
|
|
|
|
|
|
|
using (drawingContext.PushPostTransform(Matrix.CreateTranslation(currentX, offsetY))) |
|
|
|
{ |
|
|
|
|