Skip to content
Merged
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
20 changes: 14 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:war
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion
# Expression-level preferences
dotnet_style_object_initializer = true:warning
dotnet_style_collection_initializer = true:warning
dotnet_style_object_initializer = true:error
dotnet_style_collection_initializer = true:error
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
Expand Down Expand Up @@ -135,9 +135,9 @@ csharp_style_prefer_null_check_over_type_check = true:warning
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules
[*.{cs,csx,cake}]
# 'var' preferences
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:error
csharp_style_var_when_type_is_apparent = false:error
csharp_style_var_elsewhere = false:error
# Expression-bodied members
csharp_style_expression_bodied_methods = true:warning
csharp_style_expression_bodied_constructors = true:warning
Expand All @@ -160,7 +160,10 @@ csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_deconstructed_variable_declaration = true:warning
csharp_style_prefer_index_operator = true:warning
csharp_style_prefer_range_operator = true:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:error
# ReSharper inspection severities
resharper_arrange_object_creation_when_type_evident_highlighting = error
resharper_arrange_object_creation_when_type_not_evident_highlighting = error
# "Null" checking preferences
csharp_style_throw_expression = true:warning
csharp_style_conditional_delegate_call = true:warning
Expand All @@ -172,6 +175,11 @@ dotnet_diagnostic.IDE0063.severity = suggestion
csharp_using_directive_placement = outside_namespace:warning
# Modifier preferences
csharp_prefer_static_local_function = true:warning
# Primary constructor preferences
csharp_style_prefer_primary_constructors = false:none
# Collection preferences
dotnet_style_prefer_collection_expression = true:error
resharper_use_collection_expression_highlighting =true:error

##########################################
# Unnecessary Code Rules
Expand Down
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,13 @@
*.pnm filter=lfs diff=lfs merge=lfs -text
*.wbmp filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
*.cur filter=lfs diff=lfs merge=lfs -text
*.ani filter=lfs diff=lfs merge=lfs -text
*.heic filter=lfs diff=lfs merge=lfs -text
*.hif filter=lfs diff=lfs merge=lfs -text
*.avif filter=lfs diff=lfs merge=lfs -text
###############################################################################
# Handle ICC files by git lfs
###############################################################################
*.icc filter=lfs diff=lfs merge=lfs -text
91 changes: 67 additions & 24 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,94 @@ on:
- release/*
types: [ labeled, opened, synchronize, reopened ]
jobs:
# Prime a single LFS cache and expose the exact key for the matrix
WarmLFS:
runs-on: ubuntu-latest
outputs:
lfs_key: ${{ steps.expose-key.outputs.lfs_key }}
steps:
- name: Git Config
shell: bash
run: |
git config --global core.autocrlf false
git config --global core.longpaths true

- name: Git Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

# Deterministic list of LFS object IDs, then compute a portable key:
# - `git lfs ls-files -l` lists all tracked LFS objects with their SHA-256
# - `awk '{print $1}'` extracts just the SHA field
# - `sort` sorts in byte order (hex hashes sort the same everywhere)
# This ensures the file content is identical regardless of OS or locale
- name: Git Create LFS id list
shell: bash
run: git lfs ls-files -l | awk '{print $1}' | sort > .lfs-assets-id

- name: Git Expose LFS cache key
id: expose-key
shell: bash
env:
LFS_KEY: lfs-${{ hashFiles('.lfs-assets-id') }}-v1
run: echo "lfs_key=$LFS_KEY" >> "$GITHUB_OUTPUT"

- name: Git Setup LFS Cache
uses: actions/cache@v4
with:
path: .git/lfs
key: ${{ steps.expose-key.outputs.lfs_key }}

- name: Git Pull LFS
shell: bash
run: git lfs pull

Build:
needs: WarmLFS
strategy:
matrix:
isARM:
- ${{ contains(github.event.pull_request.labels.*.name, 'arch:arm32') || contains(github.event.pull_request.labels.*.name, 'arch:arm64') }}
options:
- os: ubuntu-latest
framework: net7.0
sdk: 7.0.x
framework: net9.0
sdk: 9.0.x
sdk-preview: true
runtime: -x64
codecov: false
- os: macos-latest
framework: net7.0
sdk: 7.0.x
framework: net9.0
sdk: 9.0.x
sdk-preview: true
runtime: -x64
codecov: false
- os: windows-latest
framework: net7.0
sdk: 7.0.x
framework: net9.0
sdk: 9.0.x
sdk-preview: true
runtime: -x64
codecov: false
- os: buildjet-4vcpu-ubuntu-2204-arm
framework: net7.0
sdk: 7.0.x
framework: net9.0
sdk: 9.0.x
sdk-preview: true
runtime: -x64
codecov: false
- os: ubuntu-latest
framework: net6.0
sdk: 6.0.x
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
- os: macos-latest
framework: net6.0
sdk: 6.0.x
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
- os: windows-latest
framework: net6.0
sdk: 6.0.x
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: true
exclude:
Expand All @@ -66,8 +111,10 @@ jobs:

steps:
- name: Install libgdi+, which is required for tests running on ubuntu
if: ${{ matrix.options.os == 'buildjet-4vcpu-ubuntu-2204-arm' }}
run: sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev
if: ${{ contains(matrix.options.os, 'ubuntu') }}
run: |
sudo apt-get update
sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev

- name: Git Config
shell: bash
Expand All @@ -81,16 +128,12 @@ jobs:
fetch-depth: 0
submodules: recursive

# See https://github.com/actions/checkout/issues/165#issuecomment-657673315
- name: Git Create LFS FileList
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

# Use the warmed key from WarmLFS. Do not recompute or recreate .lfs-assets-id here.
- name: Git Setup LFS Cache
uses: actions/cache@v4
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1
key: ${{ needs.WarmLFS.outputs.lfs_key }}

- name: Git Pull LFS
run: git lfs pull
Expand All @@ -111,14 +154,14 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x

- name: DotNet Setup Preview
if: ${{ matrix.options.sdk-preview == true }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
7.0.x
9.0.x

- name: DotNet Build
if: ${{ matrix.options.sdk-preview != true }}
Expand Down
4 changes: 2 additions & 2 deletions samples/DrawWithImageSharp/DrawWithImageSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<Choose>
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand Down
4 changes: 2 additions & 2 deletions samples/ListFonts/ListFonts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<Choose>
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand Down
1 change: 1 addition & 0 deletions src/SixLabors.Fonts/BigEndianBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public int ReadOffset(int size)
/// </summary>
/// <param name="data">Buffer to read into.</param>
/// <param name="size">Number of bytes to read.</param>
/// <exception cref="EndOfStreamException">The end of the stream was reached before reading could complete.</exception>
private void ReadInternal(byte[] data, int size)
{
int index = 0;
Expand Down
19 changes: 9 additions & 10 deletions src/SixLabors.Fonts/FontCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace SixLabors.Fonts;
/// </summary>
public sealed class FontCollection : IFontCollection, IFontMetricsCollection
{
private readonly HashSet<string> searchDirectories = new();
private readonly HashSet<FontMetrics> metricsCollection = new();
private readonly HashSet<string> searchDirectories = [];
private readonly HashSet<FontMetrics> metricsCollection = [];

/// <summary>
/// Initializes a new instance of the <see cref="FontCollection"/> class.
Expand Down Expand Up @@ -208,15 +208,15 @@ private FontFamily AddImpl(Stream stream, CultureInfo culture, out FontDescripti
return ((IFontMetricsCollection)this).AddMetrics(metrics, culture);
}

private IEnumerable<FontFamily> AddCollectionImpl(
private HashSet<FontFamily> AddCollectionImpl(
string path,
CultureInfo culture,
out IEnumerable<FontDescription> descriptions)
{
FileFontMetrics[] fonts = FileFontMetrics.LoadFontCollection(path);

FontDescription[] description = new FontDescription[fonts.Length];
HashSet<FontFamily> families = new();
HashSet<FontFamily> families = [];
for (int i = 0; i < fonts.Length; i++)
{
description[i] = fonts[i].Description;
Expand All @@ -228,7 +228,7 @@ private IEnumerable<FontFamily> AddCollectionImpl(
return families;
}

private IEnumerable<FontFamily> AddCollectionImpl(
private HashSet<FontFamily> AddCollectionImpl(
Stream stream,
CultureInfo culture,
out IEnumerable<FontDescription> descriptions)
Expand All @@ -237,7 +237,7 @@ private IEnumerable<FontFamily> AddCollectionImpl(
using BigEndianBinaryReader reader = new(stream, true);
TtcHeader ttcHeader = TtcHeader.Read(reader);
List<FontDescription> result = new((int)ttcHeader.NumFonts);
HashSet<FontFamily> installedFamilies = new();
HashSet<FontFamily> installedFamilies = [];
for (int i = 0; i < ttcHeader.NumFonts; ++i)
{
stream.Position = startPos + ttcHeader.OffsetTable[i];
Expand All @@ -251,12 +251,11 @@ private IEnumerable<FontFamily> AddCollectionImpl(
return installedFamilies;
}

private IEnumerable<FontFamily> FamiliesByCultureImpl(CultureInfo culture)
=> this.metricsCollection
private FontFamily[] FamiliesByCultureImpl(CultureInfo culture)
=> [.. this.metricsCollection
.Select(x => x.Description.FontFamily(culture))
.Distinct()
.Select(x => new FontFamily(x, this, culture))
.ToArray();
.Select(x => new FontFamily(x, this, culture))];

private bool TryGetImpl(string name, CultureInfo culture, out FontFamily family)
{
Expand Down
7 changes: 2 additions & 5 deletions src/SixLabors.Fonts/IO/ZlibInflateStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ public override void Flush()
/// <inheritdoc/>
public override int Read(byte[] buffer, int offset, int count)
{
if (this.deflateStream is null)
{
throw new ObjectDisposedException("inner stream");
}
ObjectDisposedException.ThrowIf(this.deflateStream is null, this.GetType());

// We don't check CRC on reading
int read = this.deflateStream.Read(buffer, offset, count);
Expand All @@ -135,7 +132,7 @@ public override int Read(byte[] buffer, int offset, int count)
this.crcRead = new byte[4];
for (int i = 0; i < 4; i++)
{
// we dont really check/use this
// we don't really check/use this
this.crcRead[i] = (byte)this.rawStream.ReadByte();
}
}
Expand Down
16 changes: 3 additions & 13 deletions src/SixLabors.Fonts/SixLabors.Fonts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@

<PropertyGroup>
<!--Bump to V2 prior to tagged release.-->
<MinVerMinimumMajorMinor>2.0</MinVerMinimumMajorMinor>
<MinVerMinimumMajorMinor>3.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<Choose>
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</Otherwise>
Expand All @@ -55,15 +55,5 @@
<None Include="..\..\shared-infrastructure\branding\icons\fonts\sixlabors.fonts.128.png" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETStandard' ">
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<Import Project="..\..\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems" Label="Shared" />
</Project>
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/StreamFontMetrics.Cff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static StreamFontMetrics LoadCompactFont(FontReader reader)
return new StreamFontMetrics(tables);
}

private GlyphMetrics CreateCffGlyphMetrics(
private CffGlyphMetrics CreateCffGlyphMetrics(
in CodePoint codePoint,
ushort glyphId,
GlyphType glyphType,
Expand Down
Loading
Loading