Skip to content

Commit

Permalink
Merge pull request #113 from SixLabors/af/shared-guard
Browse files Browse the repository at this point in the history
Share Guard code across projects
  • Loading branch information
JimBobSquarePants authored Sep 1, 2019
2 parents 1cb5def + 1278105 commit c756f19
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 8 deletions.
372 changes: 372 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
###############################################################################
# Set default behavior to:
# treat as text and
# normalize to Unix-style line endings
###############################################################################
* text eol=lf

###############################################################################
# Set explicit file behavior to:
# treat as text and
# normalize to Unix-style line endings
###############################################################################
*.asm text eol=lf
*.c text eol=lf
*.clj text eol=lf
*.cmd text eol=lf
*.cpp text eol=lf
*.css text eol=lf
*.cxx text eol=lf
*.config text eol=lf
*.DotSettings text eol=lf
*.erl text eol=lf
*.fs text eol=lf
*.fsx text eol=lf
*.h text eol=lf
*.htm text eol=lf
*.html text eol=lf
*.hs text eol=lf
*.hxx text eol=lf
*.java text eol=lf
*.js text eol=lf
*.json text eol=lf
*.less text eol=lf
*.lisp text eol=lf
*.lua text eol=lf
*.m text eol=lf
*.md text eol=lf
*.php text eol=lf
*.props text eol=lf
*.ps1 text eol=lf
*.py text eol=lf
*.rb text eol=lf
*.resx text eol=lf
*.runsettings text eol=lf
*.ruleset text eol=lf
*.sass text eol=lf
*.scss text eol=lf
*.sh text eol=lf
*.sql text eol=lf
*.svg text eol=lf
*.targets text eol=lf
*.tt text eol=crlf
*.ttinclude text eol=crlf
*.txt text eol=lf
*.vb text eol=lf
*.yml text eol=lf

###############################################################################
# Set explicit file behavior to:
# treat as text
# normalize to Unix-style line endings and
# diff as csharp
###############################################################################
*.cs text eol=lf diff=csharp

###############################################################################
# Set explicit file behavior to:
# treat as text
# normalize to Unix-style line endings and
# use a union merge when resoling conflicts
###############################################################################
*.csproj text eol=lf merge=union
*.dbproj text eol=lf merge=union
*.fsproj text eol=lf merge=union
*.ncrunchproject text eol=lf merge=union
*.vbproj text eol=lf merge=union

###############################################################################
# Set explicit file behavior to:
# treat as text
# normalize to Windows-style line endings and
# use a union merge when resoling conflicts
###############################################################################
*.sln text eol=crlf merge=union

###############################################################################
# Set explicit file behavior to:
# treat as binary
###############################################################################
*.bmp binary
*.dll binary
*.exe binary
*.gif binary
*.jpg binary
*.png binary
*.ttf binary
*.snk binary

###############################################################################
# Set explicit file behavior to:
# diff as plain text
###############################################################################
*.doc diff=astextplain
*.docx diff=astextplain
*.dot diff=astextplain
*.pdf diff=astextplain
*.pptx diff=astextplain
*.rtf diff=astextplain
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "standards"]
path = standards
url = https://github.com/SixLabors/Standards
[submodule "shared-infrastructure"]
path = shared-infrastructure
url = https://github.com/SixLabors/SharedInfrastructure
1 change: 1 addition & 0 deletions shared-infrastructure
Submodule shared-infrastructure added at faf84e
6 changes: 6 additions & 0 deletions src/SixLabors.Fonts/FontDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ internal FontDescription(NameTable nameTable, OS2Table os2, HeadTable head)
/// <returns>a <see cref="FontDescription"/>.</returns>
public static FontDescription LoadDescription(string path)
{
Guard.NotNullOrWhiteSpace(path, nameof(path));

using (FileStream fs = File.OpenRead(path))
{
var reader = new FontReader(fs);
Expand All @@ -74,6 +76,8 @@ public static FontDescription LoadDescription(string path)
/// <returns>a <see cref="FontDescription"/>.</returns>
public static FontDescription LoadDescription(Stream stream)
{
Guard.NotNull(stream, nameof(stream));

// only read the name table
var reader = new FontReader(stream);
return LoadDescription(reader);
Expand All @@ -88,6 +92,8 @@ public static FontDescription LoadDescription(Stream stream)
/// </returns>
internal static FontDescription LoadDescription(FontReader reader)
{
DebugGuard.NotNull(reader, nameof(reader));

// NOTE: These fields are read in their optimized order
// https://docs.microsoft.com/en-gb/typography/opentype/spec/recom#optimized-table-ordering
HeadTable head = reader.GetTable<HeadTable>();
Expand Down
4 changes: 4 additions & 0 deletions src/SixLabors.Fonts/FontFamilyCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public static class FontFamilyCollectionExtensions
/// <returns>Returns instance of the <see cref="Font"/> from the current collection.</returns>
public static Font CreateFont(this FontFamily fontFamily, float size, FontStyle style)
{
Guard.NotNull(fontFamily, nameof(fontFamily));

return new Font(fontFamily, size, style);
}

Expand All @@ -28,6 +30,8 @@ public static Font CreateFont(this FontFamily fontFamily, float size, FontStyle
/// <returns>Returns instance of the <see cref="Font"/> from the current collection.</returns>
public static Font CreateFont(this FontFamily fontFamily, float size)
{
Guard.NotNull(fontFamily, nameof(fontFamily));

return new Font(fontFamily, size);
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/SixLabors.Fonts/SixLabors.Fonts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,34 @@
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<!-- TODO: Include .NETSTANDARD2.1 when released-->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp2')) ">
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp2.1')) ">
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Shared\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\shared-infrastructure\**\*.cs" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>..\..\standards\SixLabors.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>..\..\shared-infrastructure\SixLabors.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\standards\stylecop.json" />
<AdditionalFiles Include="..\..\shared-infrastructure\stylecop.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61" PrivateAssets="All" />
<PackageReference Include="SixLabors.Core" Version="1.0.0-beta0007" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="SixLabors.Core" Version="1.0.0-dev000141" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion standards
Submodule standards deleted from dd83f6
9 changes: 9 additions & 0 deletions tests/SixLabors.Fonts.Tests/SixLabors.Fonts.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="Moq" Version="4.9.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>..\..\shared-infrastructure\SixLabors.Tests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\shared-infrastructure\stylecop.json" />
</ItemGroup>

<ItemGroup>
<None Update="Fonts\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down

0 comments on commit c756f19

Please sign in to comment.