Skip to content

Commit a42f9ee

Browse files
Fix feedback
1 parent 000fb64 commit a42f9ee

File tree

4 files changed

+58
-51
lines changed

4 files changed

+58
-51
lines changed

codecov.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
# Documentation: https://docs.codecov.io/docs/codecov-yaml
2+
13
codecov:
2-
branch: develop
3-
notify:
4-
require_ci_to_pass: true
5-
comment:off
4+
# Avoid "Missing base report"
5+
# https://github.com/codecov/support/issues/363
6+
# https://docs.codecov.io/docs/comparing-commits
7+
allow_coverage_offsets: true
8+
9+
# Avoid Report Expired
10+
# https://docs.codecov.io/docs/codecov-yaml#section-expired-reports
11+
max_report_age: off
12+
613
coverage:
7-
precision: 2
8-
range:
9-
- 70.0
10-
- 100.0
11-
round: down
14+
# Use integer precision
15+
# https://docs.codecov.com/docs/codecovyml-reference#coverageprecision
16+
precision: 0
17+
18+
# Explicitly control coverage status checks
19+
# https://docs.codecov.com/docs/commit-status#disabling-a-status
1220
status:
13-
changes: false
14-
patch: true
15-
project: true
16-
parsers:
17-
gcov:
18-
branch_detection:
19-
conditional: true
20-
loop: true
21-
macro: false
22-
method: false
21+
project: on
22+
patch: off

src/SixLabors.Fonts/TextOptions.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Numerics;
67

@@ -14,6 +15,7 @@ public sealed class TextOptions
1415
private float tabWidth = 4F;
1516
private float dpi = 72F;
1617
private float lineSpacing = 1F;
18+
private Font? font;
1719

1820
/// <summary>
1921
/// Initializes a new instance of the <see cref="TextOptions"/> class.
@@ -29,11 +31,7 @@ public sealed class TextOptions
2931
public TextOptions(TextOptions options)
3032
{
3133
this.Font = options.Font;
32-
foreach (FontFamily family in options.FallbackFontFamilies)
33-
{
34-
this.FallbackFontFamilies.Add(family);
35-
}
36-
34+
this.FallbackFontFamilies = new List<FontFamily>(options.FallbackFontFamilies);
3735
this.TabWidth = options.TabWidth;
3836
this.ApplyHinting = options.ApplyHinting;
3937
this.Dpi = options.Dpi;
@@ -53,13 +51,21 @@ public TextOptions(TextOptions options)
5351
/// <summary>
5452
/// Gets or sets the font.
5553
/// </summary>
56-
public Font Font { get; set; }
54+
public Font Font
55+
{
56+
get => this.font!;
57+
set
58+
{
59+
Guard.NotNull(value, nameof(this.Font));
60+
this.font = value;
61+
}
62+
}
5763

5864
/// <summary>
5965
/// Gets or sets the collection of fallback font families to use when
6066
/// a specific glyph is missing from <see cref="Font"/>.
6167
/// </summary>
62-
public ICollection<FontFamily> FallbackFontFamilies { get; set; } = new HashSet<FontFamily>();
68+
public IReadOnlyList<FontFamily> FallbackFontFamilies { get; set; } = Array.Empty<FontFamily>();
6369

6470
/// <summary>
6571
/// Gets or sets the DPI (Dots Per Inch) to render/measure the text at.
@@ -72,7 +78,7 @@ public float Dpi
7278

7379
set
7480
{
75-
Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.dpi));
81+
Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Dpi));
7682
this.dpi = value;
7783
}
7884
}

tests/SixLabors.Fonts.Tests/FontLoaderTests.cs

+19-19
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public void LoadFontMetadataWoff()
3737
[Fact]
3838
public void LoadFont_WithTtfFormat()
3939
{
40-
FontMetrics font = StreamFontMetrics.LoadFont(TestFonts.OpenSansFile);
40+
Font font = new FontCollection().Add(TestFonts.OpenSansFile).CreateFont(12);
4141

42-
GlyphMetrics glyph = font.GetGlyphMetrics(new CodePoint('A'), ColorFontSupport.None).First();
42+
GlyphMetrics glyph = font.FontMetrics.GetGlyphMetrics(new CodePoint('A'), ColorFontSupport.None).First();
4343
var r = new GlyphRenderer();
44-
glyph.RenderTo(r, 12, System.Numerics.Vector2.Zero, new TextOptions((Font)null));
44+
glyph.RenderTo(r, font.Size, System.Numerics.Vector2.Zero, new TextOptions(font));
4545

4646
Assert.Equal(37, r.ControlPoints.Count);
4747
Assert.Single(r.GlyphKeys);
@@ -51,11 +51,11 @@ public void LoadFont_WithTtfFormat()
5151
[Fact]
5252
public void LoadFont_WithWoff1Format()
5353
{
54-
FontMetrics font = StreamFontMetrics.LoadFont(TestFonts.OpenSansFileWoff1);
54+
Font font = new FontCollection().Add(TestFonts.OpenSansFileWoff1).CreateFont(12);
5555

56-
GlyphMetrics glyph = font.GetGlyphMetrics(new CodePoint('A'), ColorFontSupport.None).First();
56+
GlyphMetrics glyph = font.FontMetrics.GetGlyphMetrics(new CodePoint('A'), ColorFontSupport.None).First();
5757
var r = new GlyphRenderer();
58-
glyph.RenderTo(r, 12, System.Numerics.Vector2.Zero, new TextOptions((Font)null));
58+
glyph.RenderTo(r, font.Size, System.Numerics.Vector2.Zero, new TextOptions(font));
5959

6060
Assert.Equal(37, r.ControlPoints.Count);
6161
Assert.Single(r.GlyphKeys);
@@ -84,11 +84,11 @@ public void LoadFontMetadata_WithWoff2Format()
8484
[Fact]
8585
public void LoadFont_WithWoff2Format()
8686
{
87-
FontMetrics font = StreamFontMetrics.LoadFont(TestFonts.OpensSansWoff2Data());
87+
Font font = new FontCollection().Add(TestFonts.OpensSansWoff2Data()).CreateFont(12);
8888

89-
GlyphMetrics glyph = font.GetGlyphMetrics(new CodePoint('A'), ColorFontSupport.None).First();
89+
GlyphMetrics glyph = font.FontMetrics.GetGlyphMetrics(new CodePoint('A'), ColorFontSupport.None).First();
9090
var r = new GlyphRenderer();
91-
glyph.RenderTo(r, 12, System.Numerics.Vector2.Zero, new TextOptions((Font)null));
91+
glyph.RenderTo(r, font.Size, System.Numerics.Vector2.Zero, new TextOptions(font));
9292

9393
Assert.Equal(37, r.ControlPoints.Count);
9494
Assert.Single(r.GlyphKeys);
@@ -99,14 +99,14 @@ public void LoadFont_WithWoff2Format()
9999
[Fact]
100100
public void LoadFont()
101101
{
102-
FontMetrics font = StreamFontMetrics.LoadFont(TestFonts.SimpleFontFileData());
102+
Font font = new FontCollection().Add(TestFonts.SimpleFontFileData()).CreateFont(12);
103103

104-
Assert.Equal("SixLaborsSampleAB regular", font.Description.FontNameInvariantCulture);
105-
Assert.Equal("Regular", font.Description.FontSubFamilyNameInvariantCulture);
104+
Assert.Equal("SixLaborsSampleAB regular", font.FontMetrics.Description.FontNameInvariantCulture);
105+
Assert.Equal("Regular", font.FontMetrics.Description.FontSubFamilyNameInvariantCulture);
106106

107-
GlyphMetrics glyph = font.GetGlyphMetrics(new CodePoint('a'), ColorFontSupport.None).First();
107+
GlyphMetrics glyph = font.FontMetrics.GetGlyphMetrics(new CodePoint('a'), ColorFontSupport.None).First();
108108
var r = new GlyphRenderer();
109-
glyph.RenderTo(r, 12, System.Numerics.Vector2.Zero, new TextOptions((Font)null));
109+
glyph.RenderTo(r, font.Size, System.Numerics.Vector2.Zero, new TextOptions(font));
110110

111111
// the test font only has characters .notdef, 'a' & 'b' defined
112112
Assert.Equal(6, r.ControlPoints.Distinct().Count());
@@ -115,14 +115,14 @@ public void LoadFont()
115115
[Fact]
116116
public void LoadFontWoff()
117117
{
118-
FontMetrics font = StreamFontMetrics.LoadFont(TestFonts.SimpleFontFileWoffData());
118+
Font font = new FontCollection().Add(TestFonts.SimpleFontFileWoffData()).CreateFont(12);
119119

120-
Assert.Equal("SixLaborsSampleAB regular", font.Description.FontNameInvariantCulture);
121-
Assert.Equal("Regular", font.Description.FontSubFamilyNameInvariantCulture);
120+
Assert.Equal("SixLaborsSampleAB regular", font.FontMetrics.Description.FontNameInvariantCulture);
121+
Assert.Equal("Regular", font.FontMetrics.Description.FontSubFamilyNameInvariantCulture);
122122

123-
GlyphMetrics glyph = font.GetGlyphMetrics(new CodePoint('a'), ColorFontSupport.None).First();
123+
GlyphMetrics glyph = font.FontMetrics.GetGlyphMetrics(new CodePoint('a'), ColorFontSupport.None).First();
124124
var r = new GlyphRenderer();
125-
glyph.RenderTo(r, 12, System.Numerics.Vector2.Zero, new TextOptions((Font)null));
125+
glyph.RenderTo(r, 12, System.Numerics.Vector2.Zero, new TextOptions(font));
126126

127127
// the test font only has characters .notdef, 'a' & 'b' defined
128128
Assert.Equal(6, r.ControlPoints.Distinct().Count());

tests/SixLabors.Fonts.Tests/GlyphTests.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ public void RenderToPointAndSingleDPI()
2323
{
2424
const string text = "A";
2525
CodePoint codePoint = this.AsCodePoint(text);
26-
var font = (StreamFontMetrics)CreateFont(text).FontMetrics;
26+
Font font = CreateFont(text);
27+
FontMetrics metrics = font.FontMetrics;
2728
var glyph = new Glyph(
2829
new GlyphMetrics(
29-
font,
30+
(StreamFontMetrics)metrics,
3031
codePoint,
31-
new GlyphVector(new Vector2[0], new bool[0], new ushort[0], new Bounds(0, font.UnitsPerEm, 0, font.UnitsPerEm), Array.Empty<byte>()),
32+
new GlyphVector(new Vector2[0], new bool[0], new ushort[0], new Bounds(0, metrics.UnitsPerEm, 0, metrics.UnitsPerEm), Array.Empty<byte>()),
3233
0,
3334
0,
3435
0,
3536
0,
36-
font.UnitsPerEm,
37+
metrics.UnitsPerEm,
3738
0),
3839
10);
3940

4041
Vector2 locationInFontSpace = new Vector2(99, 99) / 72; // glyph ends up 10px over due to offset in fake glyph
41-
glyph.RenderTo(this.renderer, locationInFontSpace, new TextOptions((Font)null));
42+
glyph.RenderTo(this.renderer, locationInFontSpace, new TextOptions(font));
4243

4344
Assert.Equal(new FontRectangle(99, 89, 0, 0), this.renderer.GlyphRects.Single());
4445
}

0 commit comments

Comments
 (0)