From a42f9eebd98e5b5ecc1ffa42b6e551f6bab7d999 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 16 Nov 2021 21:31:46 +1100 Subject: [PATCH] Fix feedback --- codecov.yml | 38 +++++++++---------- src/SixLabors.Fonts/TextOptions.cs | 22 +++++++---- .../SixLabors.Fonts.Tests/FontLoaderTests.cs | 38 +++++++++---------- tests/SixLabors.Fonts.Tests/GlyphTests.cs | 11 +++--- 4 files changed, 58 insertions(+), 51 deletions(-) diff --git a/codecov.yml b/codecov.yml index bc7d87c..310eefb 100644 --- a/codecov.yml +++ b/codecov.yml @@ -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 diff --git a/src/SixLabors.Fonts/TextOptions.cs b/src/SixLabors.Fonts/TextOptions.cs index 0a4423f..e2d4c04 100644 --- a/src/SixLabors.Fonts/TextOptions.cs +++ b/src/SixLabors.Fonts/TextOptions.cs @@ -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; @@ -14,6 +15,7 @@ namespace SixLabors.Fonts private float tabWidth = 4F; private float dpi = 72F; private float lineSpacing = 1F; + private Font? font; /// /// Initializes a new instance of the class. @@ -29,11 +31,7 @@ namespace SixLabors.Fonts public TextOptions(TextOptions options) { this.Font = options.Font; - foreach (FontFamily family in options.FallbackFontFamilies) - { - this.FallbackFontFamilies.Add(family); - } - + this.FallbackFontFamilies = new List(options.FallbackFontFamilies); this.TabWidth = options.TabWidth; this.ApplyHinting = options.ApplyHinting; this.Dpi = options.Dpi; @@ -53,13 +51,21 @@ namespace SixLabors.Fonts /// /// Gets or sets the font. /// - public Font Font { get; set; } + public Font Font + { + get => this.font!; + set + { + Guard.NotNull(value, nameof(this.Font)); + this.font = value; + } + } /// /// Gets or sets the collection of fallback font families to use when /// a specific glyph is missing from . /// - public ICollection FallbackFontFamilies { get; set; } = new HashSet(); + public IReadOnlyList FallbackFontFamilies { get; set; } = Array.Empty(); /// /// Gets or sets the DPI (Dots Per Inch) to render/measure the text at. @@ -72,7 +78,7 @@ namespace SixLabors.Fonts set { - Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.dpi)); + Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Dpi)); this.dpi = value; } } diff --git a/tests/SixLabors.Fonts.Tests/FontLoaderTests.cs b/tests/SixLabors.Fonts.Tests/FontLoaderTests.cs index ad79b6f..6f126bb 100644 --- a/tests/SixLabors.Fonts.Tests/FontLoaderTests.cs +++ b/tests/SixLabors.Fonts.Tests/FontLoaderTests.cs @@ -37,11 +37,11 @@ namespace SixLabors.Fonts.Tests [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); @@ -51,11 +51,11 @@ namespace SixLabors.Fonts.Tests [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); @@ -84,11 +84,11 @@ namespace SixLabors.Fonts.Tests [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); @@ -99,14 +99,14 @@ namespace SixLabors.Fonts.Tests [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()); @@ -115,14 +115,14 @@ namespace SixLabors.Fonts.Tests [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()); diff --git a/tests/SixLabors.Fonts.Tests/GlyphTests.cs b/tests/SixLabors.Fonts.Tests/GlyphTests.cs index fffeb82..27410b5 100644 --- a/tests/SixLabors.Fonts.Tests/GlyphTests.cs +++ b/tests/SixLabors.Fonts.Tests/GlyphTests.cs @@ -23,22 +23,23 @@ namespace SixLabors.Fonts.Tests { 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()), + new GlyphVector(new Vector2[0], new bool[0], new ushort[0], new Bounds(0, metrics.UnitsPerEm, 0, metrics.UnitsPerEm), Array.Empty()), 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()); }