Skip to content
Closed
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 SixLabors.Fonts.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ VisualStudioVersion = 17.2.32519.379
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}"
ProjectSection(SolutionItems) = preProject
standards\.editorconfig = standards\.editorconfig
ci-build.ps1 = ci-build.ps1
ci-pack.ps1 = ci-pack.ps1
ci-test.ps1 = ci-test.ps1
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
NuGet.config = NuGet.config
README.md = README.md
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}"
Expand Down
18 changes: 9 additions & 9 deletions samples/DrawWithImageSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static class Program
{
public static void Main(string[] args)
{
var fonts = new FontCollection();
var woffFonts = new FontCollection();
FontCollection fonts = new();
FontCollection woffFonts = new();
FontFamily font = fonts.Add(IOPath.Combine("Fonts", "SixLaborsSampleAB.ttf"));
FontFamily fontWoff = woffFonts.Add(IOPath.Combine("Fonts", "SixLaborsSampleAB.woff"));
FontFamily fontWoff2 = woffFonts.Add(IOPath.Combine("Fonts", "OpenSans-Regular.woff2"));
Expand Down Expand Up @@ -186,7 +186,7 @@ public static void Main(string[] args)
RenderText(jhengHei, " ,;:!¥()?{}-=+\|~!@#%&", 16);
RenderText(arial, "ìíîï", 72);
#endif
var sb = new StringBuilder();
StringBuilder sb = new();
for (char c = 'a'; c <= 'z'; c++)
{
sb.Append(c);
Expand Down Expand Up @@ -215,7 +215,7 @@ public static void RenderText(Font font, string text, int width, int height)
string path = IOPath.GetInvalidFileNameChars().Aggregate(text, (x, c) => x.Replace($"{c}", "-"));
string fullPath = IOPath.GetFullPath(IOPath.Combine("Output", IOPath.Combine(path)));

using var img = new Image<Rgba32>(width, height);
using Image<Rgba32> img = new(width, height);
img.Mutate(x => x.Fill(Color.White));

IPathCollection shapes = TextBuilder.GenerateGlyphs(text, new RichTextOptions(font) { Origin = new Vector2(50f, 4f) });
Expand Down Expand Up @@ -274,7 +274,7 @@ public static void RenderTextProcessor(
FontRectangle textSize = TextMeasurer.MeasureAdvance(text, textOptions);
textOptions.Origin = new PointF(5, 5);

using var img = new Image<Rgba32>((int)Math.Ceiling(textSize.Width) + 20, (int)Math.Ceiling(textSize.Height) + 20);
using Image<Rgba32> img = new((int)Math.Ceiling(textSize.Width) + 20, (int)Math.Ceiling(textSize.Height) + 20);
img.Mutate(x => x.Fill(Color.White).ApplyProcessor(new DrawTextProcessor(x.GetDrawingOptions(), textOptions, text, new SolidBrush(Color.Black), null)));

string fullPath = CreatePath(font.Name, text + ".caching.png");
Expand Down Expand Up @@ -306,7 +306,7 @@ public static void RenderTextProcessorWithAlignment(
}

FontRectangle textSize = TextMeasurer.MeasureSize(text, textOptions);
using var img = new Image<Rgba32>(((int)textSize.Width * 2) + 20, ((int)textSize.Height * 2) + 20);
using Image<Rgba32> img = new(((int)textSize.Width * 2) + 20, ((int)textSize.Height * 2) + 20);
Size size = img.Size;
textOptions.Origin = new PointF(size.Width / 2F, size.Height / 2F);

Expand Down Expand Up @@ -345,7 +345,7 @@ private static void SaveImage(
{
string fullPath = CreatePath(path);

using var img = new Image<Rgba32>(width, height);
using Image<Rgba32> img = new(width, height);
img.Mutate(x => x.Fill(Color.Black));

img.Mutate(x => x.DrawText(options, text, Color.White));
Expand All @@ -363,7 +363,7 @@ public static void SaveImage(this IEnumerable<IPath> shapes, params string[] pat
shape = shape.Translate(shape.Bounds.Location * -1) // touch top left
.Translate(new Vector2(10)); // move in from top left

var sb = new StringBuilder();
StringBuilder sb = new();
IEnumerable<ISimplePath> converted = shape.Flatten();
converted.Aggregate(sb, (s, p) =>
{
Expand Down Expand Up @@ -399,7 +399,7 @@ public static void SaveImage(this IEnumerable<IPath> shapes, params string[] pat
height = 1;
}

using var img = new Image<Rgba32>(width, height);
using Image<Rgba32> img = new(width, height);
img.Mutate(x => x.Fill(Color.DarkBlue));
img.Mutate(x => x.Fill(Color.HotPink, shape));

Expand Down
6 changes: 3 additions & 3 deletions samples/DrawWithImageSharp/TextAlignmentSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class TextAlignmentSample
{
public static void Generate(Font font)
{
using var img = new Image<Rgba32>(1000, 1000);
using Image<Rgba32> img = new(1000, 1000);
img.Mutate(x => x.Fill(Color.White));

foreach (VerticalAlignment v in Enum.GetValues(typeof(VerticalAlignment)))
Expand Down Expand Up @@ -63,9 +63,9 @@ public static void Draw(Image<Rgba32> img, Font font, VerticalAlignment vert, Ho
break;
}

var glyphBuilder = new CustomGlyphBuilder();
CustomGlyphBuilder glyphBuilder = new();

var renderer = new TextRenderer(glyphBuilder);
TextRenderer renderer = new(glyphBuilder);

TextOptions textOptions = new(font)
{
Expand Down
6 changes: 3 additions & 3 deletions samples/DrawWithImageSharp/TextAlignmentWrapped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Generate(Font font)
const int wrappingWidth = 400;
const int size = (wrappingWidth + (wrappingWidth / 3)) * 3;

using var img = new Image<Rgba32>(size, size);
using Image<Rgba32> img = new(size, size);
img.Mutate(x => x.Fill(Color.White));

foreach (VerticalAlignment v in Enum.GetValues(typeof(VerticalAlignment)))
Expand Down Expand Up @@ -66,9 +66,9 @@ public static void Draw(Image<Rgba32> img, Font font, VerticalAlignment vert, Ho
break;
}

var glyphBuilder = new CustomGlyphBuilder();
CustomGlyphBuilder glyphBuilder = new();

var renderer = new TextRenderer(glyphBuilder);
TextRenderer renderer = new(glyphBuilder);

TextOptions textOptions = new(font)
{
Expand Down
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 = new();
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/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public bool TryGetGlyphs(
List<Glyph> g = new();
foreach (GlyphMetrics metric in metrics)
{
g.Add(new(metric.CloneForRendering(textRun), this.Size));
g.Add(new Glyph(metric.CloneForRendering(textRun), this.Size));
}

glyphs = g;
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 = new();
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
4 changes: 2 additions & 2 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
6 changes: 3 additions & 3 deletions src/SixLabors.Fonts/GlyphPositioningCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public bool TryUpdate(Font font, GlyphSubstitutionCollection collection)
maxAdvancedHeight = Math.Max(maxAdvancedHeight, metrics[k].AdvanceHeight);
}

this.glyphs.Insert(i += replacementCount, new(offset, new(shape, true) { Bounds = new(0, 0, maxAdvancedWidth, maxAdvancedHeight) }, pointSize, metrics.ToArray()));
this.glyphs.Insert(i += replacementCount, new GlyphPositioningData(offset, new GlyphShapingData(shape, true) { Bounds = new GlyphShapingBounds(0, 0, maxAdvancedWidth, maxAdvancedHeight) }, pointSize, metrics.ToArray()));
replacementCount++;
}
}
Expand Down Expand Up @@ -279,11 +279,11 @@ public bool TryAdd(Font font, GlyphSubstitutionCollection collection)
GlyphMetrics[] gm = metrics.ToArray();
if (isVertical)
{
this.glyphs.Add(new(offset, new(data, true) { Bounds = new(0, 0, 0, gm[0].AdvanceHeight) }, font.Size, gm));
this.glyphs.Add(new GlyphPositioningData(offset, new GlyphShapingData(data, true) { Bounds = new GlyphShapingBounds(0, 0, 0, gm[0].AdvanceHeight) }, font.Size, gm));
}
else
{
this.glyphs.Add(new(offset, new(data, true) { Bounds = new(0, 0, gm[0].AdvanceWidth, 0) }, font.Size, gm));
this.glyphs.Add(new GlyphPositioningData(offset, new GlyphShapingData(data, true) { Bounds = new GlyphShapingBounds(0, 0, gm[0].AdvanceWidth, 0) }, font.Size, gm));
}
}
}
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
6 changes: 3 additions & 3 deletions src/SixLabors.Fonts/GlyphSubstitutionCollection.cs
Original file line number Diff line number Diff line change
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
28 changes: 14 additions & 14 deletions src/SixLabors.Fonts/StreamFontMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ 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, bool IsVerticalLayout), GlyphMetrics[]>();
if (tables.Colr is not null)
{
this.colorGlyphCache = new();
this.colorGlyphCache = new ConcurrentDictionary<(int CodePoint, ushort Id, TextAttributes Attributes, bool IsVerticalLayout), GlyphMetrics[]>();
}

(HorizontalMetrics HorizontalMetrics, VerticalMetrics VerticalMetrics) metrics = this.Initialize(tables);
Expand All @@ -83,12 +83,12 @@ 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, bool IsVerticalLayout), GlyphMetrics[]>();
if (tables.Colr is not null)
{
this.colorGlyphCache = new();
this.colorGlyphCache = new ConcurrentDictionary<(int CodePoint, ushort Id, TextAttributes Attributes, bool IsVerticalLayout), GlyphMetrics[]>();
}

(HorizontalMetrics HorizontalMetrics, VerticalMetrics VerticalMetrics) metrics = this.Initialize(tables);
Expand Down Expand Up @@ -356,7 +356,7 @@ internal override void UpdatePositions(GlyphPositioningCollection collection)
public static StreamFontMetrics LoadFont(string path)
{
using FileStream fs = File.OpenRead(path);
using var reader = new FontReader(fs);
using FontReader reader = new(fs);
return LoadFont(reader);
}

Expand All @@ -380,7 +380,7 @@ public static StreamFontMetrics LoadFont(string path, long offset)
/// <returns>a <see cref="StreamFontMetrics"/>.</returns>
public static StreamFontMetrics LoadFont(Stream stream)
{
using var reader = new FontReader(stream);
using FontReader reader = new(stream);
return LoadFont(reader);
}

Expand Down Expand Up @@ -482,7 +482,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 Expand Up @@ -546,9 +546,9 @@ public static StreamFontMetrics[] LoadFontCollection(string path)
public static StreamFontMetrics[] LoadFontCollection(Stream stream)
{
long startPos = stream.Position;
var reader = new BigEndianBinaryReader(stream, true);
var ttcHeader = TtcHeader.Read(reader);
var fonts = new StreamFontMetrics[(int)ttcHeader.NumFonts];
BigEndianBinaryReader reader = new(stream, true);
TtcHeader ttcHeader = TtcHeader.Read(reader);
StreamFontMetrics[] fonts = new StreamFontMetrics[(int)ttcHeader.NumFonts];

for (int i = 0; i < ttcHeader.NumFonts; ++i)
{
Expand Down
Loading