This commit is contained in:
James Jackson-South 2021-11-16 21:31:46 +11:00
Родитель 000fb648ca
Коммит a42f9eebd9
4 изменённых файлов: 58 добавлений и 51 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
/// <summary>
/// Initializes a new instance of the <see cref="TextOptions"/> 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<FontFamily>(options.FallbackFontFamilies);
this.TabWidth = options.TabWidth;
this.ApplyHinting = options.ApplyHinting;
this.Dpi = options.Dpi;
@ -53,13 +51,21 @@ namespace SixLabors.Fonts
/// <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.
@ -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;
}
}

Просмотреть файл

@ -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());

Просмотреть файл

@ -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<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());
}