committed by
GitHub
42 changed files with 681 additions and 576 deletions
@ -0,0 +1,58 @@ |
|||
namespace Avalonia.Media |
|||
{ |
|||
/// <summary>
|
|||
/// The font metrics is holding information about a font's ascent, descent, etc. in design em units.
|
|||
/// </summary>
|
|||
public readonly struct FontMetrics |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the font design units per em.
|
|||
/// </summary>
|
|||
public short DesignEmHeight { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// A <see cref="bool"/> value indicating whether all glyphs in the font have the same advancement.
|
|||
/// </summary>
|
|||
public bool IsFixedPitch { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance above the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Ascent { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance under the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Descent { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended additional space between two lines of text in design em size.
|
|||
/// </summary>
|
|||
public int LineGap { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended line spacing of a formed text line.
|
|||
/// </summary>
|
|||
public int LineSpacing => Descent - Ascent + LineGap; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the underline from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlinePosition { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlineThickness { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the strikethrough from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughPosition { get; init; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughThickness { get; init; } |
|||
} |
|||
} |
|||
@ -1,125 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
public sealed class GlyphTypeface : IDisposable |
|||
{ |
|||
public GlyphTypeface(Typeface typeface) |
|||
: this(FontManager.Current.PlatformImpl.CreateGlyphTypeface(typeface)) |
|||
{ |
|||
} |
|||
|
|||
public GlyphTypeface(IGlyphTypefaceImpl platformImpl) |
|||
{ |
|||
PlatformImpl = platformImpl; |
|||
} |
|||
|
|||
public IGlyphTypefaceImpl PlatformImpl { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the font design units per em.
|
|||
/// </summary>
|
|||
public short DesignEmHeight => PlatformImpl.DesignEmHeight; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance above the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Ascent => PlatformImpl.Ascent; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended distance under the baseline in design em size.
|
|||
/// </summary>
|
|||
public int Descent => PlatformImpl.Descent; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended additional space between two lines of text in design em size.
|
|||
/// </summary>
|
|||
public int LineGap => PlatformImpl.LineGap; |
|||
|
|||
/// <summary>
|
|||
/// Gets the recommended line height.
|
|||
/// </summary>
|
|||
public int LineHeight => Descent - Ascent + LineGap; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the underline from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlinePosition => PlatformImpl.UnderlinePosition; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int UnderlineThickness => PlatformImpl.UnderlineThickness; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the distance of the strikethrough from the baseline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughPosition => PlatformImpl.StrikethroughPosition; |
|||
|
|||
/// <summary>
|
|||
/// Gets a value that indicates the thickness of the underline in design em size.
|
|||
/// </summary>
|
|||
public int StrikethroughThickness => PlatformImpl.StrikethroughThickness; |
|||
|
|||
/// <summary>
|
|||
/// A <see cref="bool"/> value indicating whether all glyphs in the font have the same advancement.
|
|||
/// </summary>
|
|||
public bool IsFixedPitch => PlatformImpl.IsFixedPitch; |
|||
|
|||
/// <summary>
|
|||
/// Returns an glyph index for the specified codepoint.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Returns a replacement glyph if a glyph isn't found.
|
|||
/// </remarks>
|
|||
/// <param name="codepoint">The codepoint.</param>
|
|||
/// <returns>
|
|||
/// A glyph index.
|
|||
/// </returns>
|
|||
public ushort GetGlyph(uint codepoint) => PlatformImpl.GetGlyph(codepoint); |
|||
|
|||
/// <summary>
|
|||
/// Tries to get an glyph index for specified codepoint.
|
|||
/// </summary>
|
|||
/// <param name="codepoint">The codepoint.</param>
|
|||
/// <param name="glyph">A glyph index.</param>
|
|||
/// <returns>
|
|||
/// <c>true</c> if an glyph index was found, <c>false</c> otherwise.
|
|||
/// </returns>
|
|||
public bool TryGetGlyph(uint codepoint, out ushort glyph) |
|||
{ |
|||
glyph = PlatformImpl.GetGlyph(codepoint); |
|||
|
|||
return glyph != 0; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns an array of glyph indices. Codepoints that are not represented by the font are returned as <code>0</code>.
|
|||
/// </summary>
|
|||
/// <param name="codepoints">The codepoints to map.</param>
|
|||
/// <returns></returns>
|
|||
public ushort[] GetGlyphs(ReadOnlySpan<uint> codepoints) => PlatformImpl.GetGlyphs(codepoints); |
|||
|
|||
/// <summary>
|
|||
/// Returns the glyph advance for the specified glyph.
|
|||
/// </summary>
|
|||
/// <param name="glyph">The glyph.</param>
|
|||
/// <returns>
|
|||
/// The advance.
|
|||
/// </returns>
|
|||
public int GetGlyphAdvance(ushort glyph) => PlatformImpl.GetGlyphAdvance(glyph); |
|||
|
|||
/// <summary>
|
|||
/// Returns an array of glyph advances in design em size.
|
|||
/// </summary>
|
|||
/// <param name="glyphs">The glyph indices.</param>
|
|||
/// <returns></returns>
|
|||
public int[] GetGlyphAdvances(ReadOnlySpan<ushort> glyphs) => PlatformImpl.GetGlyphAdvances(glyphs); |
|||
|
|||
void IDisposable.Dispose() |
|||
{ |
|||
PlatformImpl?.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,33 +1,33 @@ |
|||
namespace Avalonia.Media.TextFormatting |
|||
{ |
|||
/// <summary>
|
|||
/// A metric that holds information about font specific measurements.
|
|||
/// A metric that holds information about text specific measurements.
|
|||
/// </summary>
|
|||
public readonly struct FontMetrics |
|||
public readonly struct TextMetrics |
|||
{ |
|||
public FontMetrics(Typeface typeface, double fontRenderingEmSize) |
|||
public TextMetrics(Typeface typeface, double fontRenderingEmSize) |
|||
{ |
|||
var glyphTypeface = typeface.GlyphTypeface; |
|||
var fontMetrics = typeface.GlyphTypeface.Metrics; |
|||
|
|||
var scale = fontRenderingEmSize / glyphTypeface.DesignEmHeight; |
|||
var scale = fontRenderingEmSize / fontMetrics.DesignEmHeight; |
|||
|
|||
FontRenderingEmSize = fontRenderingEmSize; |
|||
|
|||
Ascent = glyphTypeface.Ascent * scale; |
|||
Ascent = fontMetrics.Ascent * scale; |
|||
|
|||
Descent = glyphTypeface.Descent * scale; |
|||
Descent = fontMetrics.Descent * scale; |
|||
|
|||
LineGap = glyphTypeface.LineGap * scale; |
|||
LineGap = fontMetrics.LineGap * scale; |
|||
|
|||
LineHeight = Descent - Ascent + LineGap; |
|||
|
|||
UnderlineThickness = glyphTypeface.UnderlineThickness * scale; |
|||
UnderlineThickness = fontMetrics.UnderlineThickness * scale; |
|||
|
|||
UnderlinePosition = glyphTypeface.UnderlinePosition * scale; |
|||
UnderlinePosition = fontMetrics.UnderlinePosition * scale; |
|||
|
|||
StrikethroughThickness = glyphTypeface.StrikethroughThickness * scale; |
|||
StrikethroughThickness = fontMetrics.StrikethroughThickness * scale; |
|||
|
|||
StrikethroughPosition = glyphTypeface.StrikethroughPosition * scale; |
|||
StrikethroughPosition = fontMetrics.StrikethroughPosition * scale; |
|||
} |
|||
|
|||
/// <summary>
|
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using System.Drawing; |
|||
|
|||
namespace Avalonia.Platform |
|||
{ |
|||
public interface IGlyphRunBuffer |
|||
{ |
|||
Span<ushort> GlyphIndices { get; } |
|||
|
|||
IGlyphRunImpl Build(); |
|||
} |
|||
|
|||
public interface IHorizontalGlyphRunBuffer : IGlyphRunBuffer |
|||
{ |
|||
Span<float> GlyphPositions { get; } |
|||
} |
|||
|
|||
public interface IPositionedGlyphRunBuffer : IGlyphRunBuffer |
|||
{ |
|||
Span<PointF> GlyphPositions { get; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue