Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/ListFonts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class Program
{
public static void Main(string[] args)
{
var pairings = new List<Pairing>();
List<Pairing> pairings = [];
IOrderedEnumerable<FontFamily> ordered = SystemFonts.Families.OrderBy(x => x.Name);
foreach (FontFamily family in ordered)
{
Expand Down
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/ArrayBuilder{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void EnsureCapacity(int min)
newCapacity = (uint)min;
}

var array = new T[newCapacity];
T[] array = new T[newCapacity];

if (this.size > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/ArraySlice{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ArraySlice(T[] data, int start, int length)
/// <summary>
/// Gets an empty <see cref="ArraySlice{T}"/>
/// </summary>
public static ArraySlice<T> Empty => new(Array.Empty<T>());
public static ArraySlice<T> Empty => new([]);

/// <summary>
/// Gets the offset position in the underlying buffer this slice was created from.
Expand Down
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public bool TryGetGlyph(
TextRun textRun = new() { Start = 0, End = 1, Font = this, TextAttributes = textAttributes, TextDecorations = textDecorations };
if (this.FontMetrics.TryGetGlyphMetrics(codePoint, textAttributes, textDecorations, layoutMode, support, out GlyphMetrics? metrics))
{
glyph = new(metrics.CloneForRendering(textRun), this.Size);
glyph = new Glyph(metrics.CloneForRendering(textRun), this.Size);
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/SixLabors.Fonts/FontDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static FontDescription LoadDescription(string path)
Guard.NotNullOrWhiteSpace(path, nameof(path));

using FileStream fs = File.OpenRead(path);
using var reader = new FontReader(fs);
using FontReader reader = new(fs);
return LoadDescription(reader);
}

Expand All @@ -106,7 +106,7 @@ public static FontDescription LoadDescription(Stream stream)
Guard.NotNull(stream, nameof(stream));

// Only read the name tables.
using var reader = new FontReader(stream);
using FontReader reader = new(stream);

return LoadDescription(reader);
}
Expand Down Expand Up @@ -152,14 +152,14 @@ public static FontDescription[] LoadFontCollectionDescriptions(string path)
public static FontDescription[] LoadFontCollectionDescriptions(Stream stream)
{
long startPos = stream.Position;
using var reader = new BigEndianBinaryReader(stream, true);
var ttcHeader = TtcHeader.Read(reader);
using BigEndianBinaryReader reader = new(stream, true);
TtcHeader ttcHeader = TtcHeader.Read(reader);

var result = new FontDescription[(int)ttcHeader.NumFonts];
FontDescription[] result = new FontDescription[(int)ttcHeader.NumFonts];
for (int i = 0; i < ttcHeader.NumFonts; ++i)
{
stream.Position = startPos + ttcHeader.OffsetTable[i];
using var fontReader = new FontReader(stream);
using FontReader fontReader = new(stream);
result[i] = LoadDescription(fontReader);
}

Expand Down
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/FontFamily.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public bool TryGetPaths(out IEnumerable<string> paths)
FontsThrowHelper.ThrowDefaultInstance();
}

var filePaths = new List<string>();
List<string> filePaths = [];
foreach (FontStyle style in this.GetAvailableStyles())
{
if (this.collection.TryGetMetrics(this.Name, this.Culture, style, out FontMetrics? metrics)
Expand Down
10 changes: 5 additions & 5 deletions src/SixLabors.Fonts/FontReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal FontReader(Stream stream, TableLoader loader)
Func<BigEndianBinaryReader, TableHeader> loadHeader = TableHeader.Read;

this.stream = stream;
using var reader = new BigEndianBinaryReader(stream, true);
using BigEndianBinaryReader reader = new(stream, true);

// we should immediately read the table header to learn which tables we have and what order they are in
uint version = reader.ReadUInt32();
Expand Down Expand Up @@ -90,9 +90,9 @@ internal FontReader(Stream stream, TableLoader loader)
this.isOwnedStream = true;

byte[] compressedBuffer = reader.ReadBytes((int)totalCompressedSize);
var decompressedStream = new MemoryStream();
using var input = new MemoryStream(compressedBuffer);
using var decompressor = new BrotliStream(input, CompressionMode.Decompress);
MemoryStream decompressedStream = new();
using MemoryStream input = new(compressedBuffer);
using BrotliStream decompressor = new(input, CompressionMode.Decompress);
decompressor.CopyTo(decompressedStream);
decompressedStream.Position = 0;
this.stream = decompressedStream;
Expand All @@ -111,7 +111,7 @@ internal FontReader(Stream stream, TableLoader loader)
this.CompressedTableData = false;
}

var headers = new Dictionary<string, TableHeader>(tableCount);
Dictionary<string, TableHeader> headers = new(tableCount);
for (int i = 0; i < tableCount; i++)
{
TableHeader tbl = loadHeader(reader);
Expand Down
10 changes: 5 additions & 5 deletions src/SixLabors.Fonts/GlyphMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ internal GlyphMetrics(
{
float units = this.UnitsPerEm;
scaleFactor /= new Vector2(font.SubscriptXSize / units, font.SubscriptYSize / units);
offset = new(font.SubscriptXOffset, font.SubscriptYOffset < 0 ? font.SubscriptYOffset : -font.SubscriptYOffset);
offset = new Vector2(font.SubscriptXOffset, font.SubscriptYOffset < 0 ? font.SubscriptYOffset : -font.SubscriptYOffset);
}
else if ((textAttributes & TextAttributes.Superscript) == TextAttributes.Superscript)
{
float units = this.UnitsPerEm;
scaleFactor /= new Vector2(font.SuperscriptXSize / units, font.SuperscriptYSize / units);
offset = new(font.SuperscriptXOffset, font.SuperscriptYOffset < 0 ? -font.SuperscriptYOffset : font.SuperscriptYOffset);
offset = new Vector2(font.SuperscriptXOffset, font.SuperscriptYOffset < 0 ? -font.SuperscriptYOffset : font.SuperscriptYOffset);
}

this.ScaleFactor = scaleFactor;
Expand Down Expand Up @@ -355,19 +355,19 @@ protected void RenderDecorationsTo(
{
// To ensure that we share the scaling when sharing font metrics we need to
// recalculate the offset and scale factor here using the common font metrics.
scaleFactor = new(fontMetrics.UnitsPerEm * 72F);
scaleFactor = new Vector2(fontMetrics.UnitsPerEm * 72F);
offset = Vector2.Zero;
if ((this.TextAttributes & TextAttributes.Subscript) == TextAttributes.Subscript)
{
float units = this.UnitsPerEm;
scaleFactor /= new Vector2(fontMetrics.SubscriptXSize / units, fontMetrics.SubscriptYSize / units);
offset = new(fontMetrics.SubscriptXOffset, fontMetrics.SubscriptYOffset < 0 ? fontMetrics.SubscriptYOffset : -fontMetrics.SubscriptYOffset);
offset = new Vector2(fontMetrics.SubscriptXOffset, fontMetrics.SubscriptYOffset < 0 ? fontMetrics.SubscriptYOffset : -fontMetrics.SubscriptYOffset);
}
else if ((this.TextAttributes & TextAttributes.Superscript) == TextAttributes.Superscript)
{
float units = this.UnitsPerEm;
scaleFactor /= new Vector2(fontMetrics.SuperscriptXSize / units, fontMetrics.SuperscriptYSize / units);
offset = new(fontMetrics.SuperscriptXOffset, fontMetrics.SuperscriptYOffset < 0 ? -fontMetrics.SuperscriptYOffset : fontMetrics.SuperscriptYOffset);
offset = new Vector2(fontMetrics.SuperscriptXOffset, fontMetrics.SuperscriptYOffset < 0 ? -fontMetrics.SuperscriptYOffset : fontMetrics.SuperscriptYOffset);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/SixLabors.Fonts/GlyphPositioningCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class GlyphPositioningCollection : IGlyphShapingCollection
/// <summary>
/// Contains a map the index of a map within the collection, non-sequential codepoint offsets, and their glyph ids, point size, and mtrics.
/// </summary>
private readonly List<GlyphPositioningData> glyphs = new();
private readonly List<GlyphPositioningData> glyphs = [];

/// <summary>
/// Initializes a new instance of the <see cref="GlyphPositioningCollection"/> class.
Expand Down Expand Up @@ -193,7 +193,7 @@ public bool TryUpdate(Font font, GlyphSubstitutionCollection collection)

// Track the number of inserted glyphs at the offset so we can correctly increment our position.
GlyphShapingBounds bounds = new(0, 0, metrics.AdvanceWidth, metrics.AdvanceHeight);
this.glyphs.Insert(i += replacementCount, new(offset, new(shape, true) { Bounds = bounds }, pointSize, metrics.CloneForRendering(shape.TextRun)));
this.glyphs.Insert(i += replacementCount, new GlyphPositioningData(offset, new GlyphShapingData(shape, true) { Bounds = bounds }, pointSize, metrics.CloneForRendering(shape.TextRun)));
replacementCount++;
}
}
Expand Down Expand Up @@ -260,10 +260,10 @@ public bool TryAdd(Font font, GlyphSubstitutionCollection collection)
}

GlyphShapingBounds bounds = isVertical
? new(0, 0, 0, metrics.AdvanceHeight)
: new(0, 0, metrics.AdvanceWidth, 0);
? new GlyphShapingBounds(0, 0, 0, metrics.AdvanceHeight)
: new GlyphShapingBounds(0, 0, metrics.AdvanceWidth, 0);

this.glyphs.Add(new(offset, new(data, true) { Bounds = bounds }, font.Size, metrics.CloneForRendering(data.TextRun)));
this.glyphs.Add(new GlyphPositioningData(offset, new GlyphShapingData(data, true) { Bounds = bounds }, font.Size, metrics.CloneForRendering(data.TextRun)));
}

return !hasFallBacks;
Expand Down
4 changes: 2 additions & 2 deletions src/SixLabors.Fonts/GlyphShapingData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public GlyphShapingData(GlyphShapingData data, bool clearFeatures = false)
this.IsDecomposed = data.IsDecomposed;
if (data.UniversalShapingEngineInfo != null)
{
this.UniversalShapingEngineInfo = new(
this.UniversalShapingEngineInfo = new UniversalShapingEngineInfo(
data.UniversalShapingEngineInfo.Category,
data.UniversalShapingEngineInfo.SyllableType,
data.UniversalShapingEngineInfo.Syllable);
}

if (data.IndicShapingEngineInfo != null)
{
this.IndicShapingEngineInfo = new(
this.IndicShapingEngineInfo = new IndicShapingEngineInfo(
data.IndicShapingEngineInfo.Category,
data.IndicShapingEngineInfo.Position,
data.IndicShapingEngineInfo.SyllableType,
Expand Down
8 changes: 4 additions & 4 deletions src/SixLabors.Fonts/GlyphSubstitutionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class GlyphSubstitutionCollection : IGlyphShapingCollection
/// <summary>
/// Contains a map the index of a map within the collection, non-sequential codepoint offsets, and their glyph ids.
/// </summary>
private readonly List<OffsetGlyphDataPair> glyphs = new();
private readonly List<OffsetGlyphDataPair> glyphs = [];

/// <summary>
/// Initializes a new instance of the <see cref="GlyphSubstitutionCollection"/> class.
Expand Down Expand Up @@ -101,7 +101,7 @@ public void DisableShapingFeature(int index, Tag feature)
/// <param name="data">The data.</param>
/// <param name="offset">The zero-based index within the input codepoint collection.</param>
public void AddGlyph(GlyphShapingData data, int offset)
=> this.glyphs.Add(new(offset, new(data, false)));
=> this.glyphs.Add(new OffsetGlyphDataPair(offset, new GlyphShapingData(data, false)));

/// <summary>
/// Adds the glyph id and the codepoint it represents to the collection.
Expand All @@ -112,7 +112,7 @@ public void AddGlyph(GlyphShapingData data, int offset)
/// <param name="textRun">The text run this glyph belongs to.</param>
/// <param name="offset">The zero-based index within the input codepoint collection.</param>
public void AddGlyph(ushort glyphId, CodePoint codePoint, TextDirection direction, TextRun textRun, int offset)
=> this.glyphs.Add(new(offset, new(textRun)
=> this.glyphs.Add(new OffsetGlyphDataPair(offset, new GlyphShapingData(textRun)
{
CodePoint = codePoint,
Direction = direction,
Expand Down Expand Up @@ -363,7 +363,7 @@ public void Replace(int index, ReadOnlySpan<ushort> glyphIds, Tag feature)

data.AppliedFeatures.Add(feature);

this.glyphs.Insert(++index, new(pair.Offset, data));
this.glyphs.Insert(++index, new OffsetGlyphDataPair(pair.Offset, data));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/ReadOnlyArraySlice{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ReadOnlyArraySlice(T[] data, int start, int length)
/// <summary>
/// Gets an empty <see cref="ReadOnlyArraySlice{T}"/>
/// </summary>
public static ReadOnlyArraySlice<T> Empty => new(Array.Empty<T>());
public static ReadOnlyArraySlice<T> Empty => new([]);

/// <summary>
/// Gets the offset position in the underlying buffer this slice was created from.
Expand Down
14 changes: 7 additions & 7 deletions src/SixLabors.Fonts/StreamFontMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ internal StreamFontMetrics(TrueTypeFontTables tables)
this.trueTypeFontTables = tables;
this.outlineType = OutlineType.TrueType;
this.description = new FontDescription(tables.Name, tables.Os2, tables.Head);
this.glyphIdCache = new();
this.codePointCache = new();
this.glyphCache = new();
this.glyphIdCache = new ConcurrentDictionary<(int CodePoint, int NextCodePoint), (bool Success, ushort GlyphId, bool SkipNextCodePoint)>();
this.codePointCache = new ConcurrentDictionary<ushort, (bool Success, CodePoint CodePoint)>();
this.glyphCache = new ConcurrentDictionary<(int CodePoint, ushort Id, TextAttributes Attributes, ColorFontSupport ColorSupport, bool IsVerticalLayout), GlyphMetrics>();

(HorizontalMetrics HorizontalMetrics, VerticalMetrics VerticalMetrics) metrics = this.Initialize(tables);
this.horizontalMetrics = metrics.HorizontalMetrics;
Expand All @@ -77,9 +77,9 @@ internal StreamFontMetrics(CompactFontTables tables)
this.compactFontTables = tables;
this.outlineType = OutlineType.CFF;
this.description = new FontDescription(tables.Name, tables.Os2, tables.Head);
this.glyphIdCache = new();
this.codePointCache = new();
this.glyphCache = new();
this.glyphIdCache = new ConcurrentDictionary<(int CodePoint, int NextCodePoint), (bool Success, ushort GlyphId, bool SkipNextCodePoint)>();
this.codePointCache = new ConcurrentDictionary<ushort, (bool Success, CodePoint CodePoint)>();
this.glyphCache = new ConcurrentDictionary<(int CodePoint, ushort Id, TextAttributes Attributes, ColorFontSupport ColorSupport, bool IsVerticalLayout), GlyphMetrics>();

(HorizontalMetrics HorizontalMetrics, VerticalMetrics VerticalMetrics) metrics = this.Initialize(tables);
this.horizontalMetrics = metrics.HorizontalMetrics;
Expand Down Expand Up @@ -465,7 +465,7 @@ private static HorizontalMetrics InitializeHorizontalMetrics(HorizontalHeadTable
advanceWidthMax = (short)hhea.AdvanceWidthMax;
advanceHeightMax = vhea == null ? lineHeight : vhea.AdvanceHeightMax;

return new()
return new HorizontalMetrics
{
Ascender = ascender,
Descender = descender,
Expand Down
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/SystemFontCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ IEnumerator<FontMetrics> IReadOnlyFontMetricsCollection.GetEnumerator()

private static FontCollection CreateSystemFontCollection(IEnumerable<string> paths, IReadOnlyCollection<string> searchDirectories)
{
var collection = new FontCollection(searchDirectories);
FontCollection collection = new(searchDirectories);

foreach (string path in paths)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static ChainedClassSequenceRuleSetTable Load(BigEndianBinaryReader reader
Span<ushort> seqRuleOffsets = seqRuleOffsetsBuffer.GetSpan();
reader.ReadUInt16Array(seqRuleOffsets);

var subRules = new ChainedClassSequenceRuleTable[seqRuleCount];
ChainedClassSequenceRuleTable[] subRules = new ChainedClassSequenceRuleTable[seqRuleCount];
for (int i = 0; i < subRules.Length; i++)
{
subRules[i] = ChainedClassSequenceRuleTable.Load(reader, offset + seqRuleOffsets[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static ChainedSequenceRuleSetTable Load(BigEndianBinaryReader reader, lon
Span<ushort> chainedSeqRuleOffsets = chainedSeqRuleOffsetsBuffer.GetSpan();
reader.ReadUInt16Array(chainedSeqRuleOffsets);

var chainedSequenceRules = new ChainedSequenceRuleTable[chainedSeqRuleCount];
ChainedSequenceRuleTable[] chainedSequenceRules = new ChainedSequenceRuleTable[chainedSeqRuleCount];
for (int i = 0; i < chainedSequenceRules.Length; i++)
{
chainedSequenceRules[i] = ChainedSequenceRuleTable.Load(reader, offset + chainedSeqRuleOffsets[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static ClassSequenceRuleSetTable Load(BigEndianBinaryReader reader, long
Span<ushort> seqRuleOffsets = seqRuleOffsetsBuffer.GetSpan();
reader.ReadUInt16Array(seqRuleOffsets);

var subRules = new ClassSequenceRuleTable[seqRuleCount];
ClassSequenceRuleTable[] subRules = new ClassSequenceRuleTable[seqRuleCount];
for (int i = 0; i < subRules.Length; i++)
{
subRules[i] = ClassSequenceRuleTable.Load(reader, offset + seqRuleOffsets[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static CoverageTable Load(BigEndianBinaryReader reader, long offset)

public static CoverageTable[] LoadArray(BigEndianBinaryReader reader, long offset, ReadOnlySpan<ushort> coverageOffsets)
{
var tables = new CoverageTable[coverageOffsets.Length];
CoverageTable[] tables = new CoverageTable[coverageOffsets.Length];
for (int i = 0; i < tables.Length; i++)
{
tables[i] = Load(reader, offset + coverageOffsets[i]);
Expand Down Expand Up @@ -103,7 +103,7 @@ public static CoverageFormat2Table Load(BigEndianBinaryReader reader)
// | RangeRecord | rangeRecords[rangeCount] | Array of glyph ranges — ordered by startGlyphID. |
// +-------------+--------------------------+--------------------------------------------------+
ushort rangeCount = reader.ReadUInt16();
var records = new CoverageRangeRecord[rangeCount];
CoverageRangeRecord[] records = new CoverageRangeRecord[rangeCount];

for (int i = 0; i < records.Length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static FeatureListTable Load(BigEndianBinaryReader reader, long offset)
reader.Seek(offset, SeekOrigin.Begin);

ushort featureCount = reader.ReadUInt16();
var featureRecords = new FeatureRecord[featureCount];
FeatureRecord[] featureRecords = new FeatureRecord[featureCount];
for (int i = 0; i < featureRecords.Length; i++)
{
// FeatureRecord
Expand All @@ -51,7 +51,7 @@ public static FeatureListTable Load(BigEndianBinaryReader reader, long offset)

// Load the other table features.
// We do this last to avoid excessive seeking.
var featureTables = new FeatureTable[featureCount];
FeatureTable[] featureTables = new FeatureTable[featureCount];
for (int i = 0; i < featureTables.Length; i++)
{
FeatureRecord featureRecord = featureRecords[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ public override AnchorXY GetAnchor(FontMetrics fontMetrics, GlyphShapingData dat
if (this.anchorPointIndex < points.Count)
{
Vector2 point = points[this.anchorPointIndex].Point;
return new((short)point.X, (short)point.Y);
return new AnchorXY((short)point.X, (short)point.Y);
}
}
}
}

return new(this.XCoordinate, this.YCoordinate);
return new AnchorXY(this.XCoordinate, this.YCoordinate);
}
}

Expand Down
Loading