Skip to content

Commit 640eec8

Browse files
Add LineMetrics and per-line measurement API
1 parent 9a33f1d commit 640eec8

6 files changed

Lines changed: 432 additions & 26 deletions

File tree

src/SixLabors.Fonts/LineMetrics.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.Fonts;
5+
6+
/// <summary>
7+
/// Encapsulates measured metrics for a single laid-out text line.
8+
/// </summary>
9+
/// <remarks>
10+
/// <para>This type is layout-mode agnostic:</para>
11+
/// <list type="bullet">
12+
/// <item><description>Horizontal layouts: <see cref="Start"/> is the X start position and <see cref="Extent"/> is the width.</description></item>
13+
/// <item><description>Vertical layouts: <see cref="Start"/> is the Y start position and <see cref="Extent"/> is the height.</description></item>
14+
/// </list>
15+
/// </remarks>
16+
public readonly struct LineMetrics
17+
{
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="LineMetrics"/> struct.
20+
/// </summary>
21+
/// <param name="ascender">Distance from the baseline to the ascender line.</param>
22+
/// <param name="baseline">Baseline position within the line box.</param>
23+
/// <param name="descender">Descender line position within the line box.</param>
24+
/// <param name="lineHeight">Total line-box size (includes effective line spacing).</param>
25+
/// <param name="start">Line start position in the primary layout flow direction after alignment.</param>
26+
/// <param name="extent">Line extent in the primary layout flow direction.</param>
27+
public LineMetrics(
28+
float ascender,
29+
float baseline,
30+
float descender,
31+
float lineHeight,
32+
float start,
33+
float extent)
34+
{
35+
this.Ascender = ascender;
36+
this.Baseline = baseline;
37+
this.Descender = descender;
38+
this.LineHeight = lineHeight;
39+
this.Start = start;
40+
this.Extent = extent;
41+
}
42+
43+
/// <summary>
44+
/// Gets the distance from the baseline to the ascender line.
45+
/// </summary>
46+
public float Ascender { get; }
47+
48+
/// <summary>
49+
/// Gets the baseline position within the line box.
50+
/// </summary>
51+
/// <remarks>
52+
/// Use this value as the guide-line position for drawing a baseline relative to the current line origin.
53+
/// </remarks>
54+
public float Baseline { get; }
55+
56+
/// <summary>
57+
/// Gets the descender line position within the line box.
58+
/// </summary>
59+
/// <remarks>
60+
/// This is a position value (not a baseline-relative distance).
61+
/// Use this value to draw the descender guide line relative to the current line origin.
62+
/// </remarks>
63+
public float Descender { get; }
64+
65+
/// <summary>
66+
/// Gets the total line-box size for this line.
67+
/// </summary>
68+
public float LineHeight { get; }
69+
70+
/// <summary>
71+
/// Gets the line start position in the primary layout flow direction.
72+
/// </summary>
73+
public float Start { get; }
74+
75+
/// <summary>
76+
/// Gets the line extent in the primary layout flow direction.
77+
/// </summary>
78+
public float Extent { get; }
79+
}

0 commit comments

Comments
 (0)