Skip to content

Commit

Permalink
Fix feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Nov 16, 2021
1 parent 000fb64 commit a42f9ee
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
38 changes: 19 additions & 19 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Documentation: https://docs.codecov.io/docs/codecov-yaml

codecov:
branch: develop
notify:
require_ci_to_pass: true
comment:off
# Avoid "Missing base report"
# https://github.com/codecov/support/issues/363
# https://docs.codecov.io/docs/comparing-commits
allow_coverage_offsets: true

# Avoid Report Expired
# https://docs.codecov.io/docs/codecov-yaml#section-expired-reports
max_report_age: off

coverage:
precision: 2
range:
- 70.0
- 100.0
round: down
# Use integer precision
# https://docs.codecov.com/docs/codecovyml-reference#coverageprecision
precision: 0

# Explicitly control coverage status checks
# https://docs.codecov.com/docs/commit-status#disabling-a-status
status:
changes: false
patch: true
project: true
parsers:
gcov:
branch_detection:
conditional: true
loop: true
macro: false
method: false
project: on
patch: off
22 changes: 14 additions & 8 deletions src/SixLabors.Fonts/TextOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System;
using System.Collections.Generic;
using System.Numerics;

Expand All @@ -14,6 +15,7 @@ public sealed class TextOptions
private float tabWidth = 4F;
private float dpi = 72F;
private float lineSpacing = 1F;
private Font? font;

/// <summary>
/// Initializes a new instance of the <see cref="TextOptions"/> class.
Expand All @@ -29,11 +31,7 @@ public sealed class TextOptions
public TextOptions(TextOptions options)
{
this.Font = options.Font;
foreach (FontFamily family in options.FallbackFontFamilies)
{
this.FallbackFontFamilies.Add(family);
}

this.FallbackFontFamilies = new List<FontFamily>(options.FallbackFontFamilies);
this.TabWidth = options.TabWidth;
this.ApplyHinting = options.ApplyHinting;
this.Dpi = options.Dpi;
Expand All @@ -53,13 +51,21 @@ public TextOptions(TextOptions options)
/// <summary>
/// Gets or sets the font.
/// </summary>
public Font Font { get; set; }
public Font Font
{
get => this.font!;
set
{
Guard.NotNull(value, nameof(this.Font));
this.font = value;
}
}

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

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

set
{
Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.dpi));
Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Dpi));
this.dpi = value;
}
}
Expand Down
38 changes: 19 additions & 19 deletions tests/SixLabors.Fonts.Tests/FontLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public void LoadFontMetadataWoff()
[Fact]
public void LoadFont_WithTtfFormat()
{
FontMetrics font = StreamFontMetrics.LoadFont(TestFonts.OpenSansFile);
Font font = new FontCollection().Add(TestFonts.OpenSansFile).CreateFont(12);

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

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

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

Assert.Equal(37, r.ControlPoints.Count);
Assert.Single(r.GlyphKeys);
Expand Down Expand Up @@ -84,11 +84,11 @@ public void LoadFontMetadata_WithWoff2Format()
[Fact]
public void LoadFont_WithWoff2Format()
{
FontMetrics font = StreamFontMetrics.LoadFont(TestFonts.OpensSansWoff2Data());
Font font = new FontCollection().Add(TestFonts.OpensSansWoff2Data()).CreateFont(12);

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

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

Assert.Equal("SixLaborsSampleAB regular", font.Description.FontNameInvariantCulture);
Assert.Equal("Regular", font.Description.FontSubFamilyNameInvariantCulture);
Assert.Equal("SixLaborsSampleAB regular", font.FontMetrics.Description.FontNameInvariantCulture);
Assert.Equal("Regular", font.FontMetrics.Description.FontSubFamilyNameInvariantCulture);

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

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

Assert.Equal("SixLaborsSampleAB regular", font.Description.FontNameInvariantCulture);
Assert.Equal("Regular", font.Description.FontSubFamilyNameInvariantCulture);
Assert.Equal("SixLaborsSampleAB regular", font.FontMetrics.Description.FontNameInvariantCulture);
Assert.Equal("Regular", font.FontMetrics.Description.FontSubFamilyNameInvariantCulture);

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

// the test font only has characters .notdef, 'a' & 'b' defined
Assert.Equal(6, r.ControlPoints.Distinct().Count());
Expand Down
11 changes: 6 additions & 5 deletions tests/SixLabors.Fonts.Tests/GlyphTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ public void RenderToPointAndSingleDPI()
{
const string text = "A";
CodePoint codePoint = this.AsCodePoint(text);
var font = (StreamFontMetrics)CreateFont(text).FontMetrics;
Font font = CreateFont(text);
FontMetrics metrics = font.FontMetrics;
var glyph = new Glyph(
new GlyphMetrics(
font,
(StreamFontMetrics)metrics,
codePoint,
new GlyphVector(new Vector2[0], new bool[0], new ushort[0], new Bounds(0, font.UnitsPerEm, 0, font.UnitsPerEm), Array.Empty<byte>()),
new GlyphVector(new Vector2[0], new bool[0], new ushort[0], new Bounds(0, metrics.UnitsPerEm, 0, metrics.UnitsPerEm), Array.Empty<byte>()),
0,
0,
0,
0,
font.UnitsPerEm,
metrics.UnitsPerEm,
0),
10);

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

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

0 comments on commit a42f9ee

Please sign in to comment.