Skip to content

Commit

Permalink
Merge pull request #27 from guitarrapc/fix/libskiasharp
Browse files Browse the repository at this point in the history
fix: remove SkiaSharp.NativeAssets.Linux dependency to enable package handle via user
  • Loading branch information
guitarrapc authored Nov 25, 2020
2 parents 7f9b51c + 371996b commit 0d90ae4
Show file tree
Hide file tree
Showing 26 changed files with 477 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- run: dotnet build ./src/SkiaSharp.QrCode/ -c Debug
- run: dotnet build ./samples/ManualGenerate/ -c Debug
- run: dotnet build ./samples/SimpleGenerate/ -c Debug
# tests
- run: dotnet test ./tests/SkiaSharp.QrCode.Tests.net31/ -c Debug
- run: dotnet test ./tests/SkiaSharp.QrCode.Tests.net50/ -c Debug -p:CollectCoverage=true -p:CoverletOutputFormat=opencover
- uses: codecov/codecov-action@v1
Expand All @@ -38,3 +39,11 @@ jobs:
flags: unittests
fail_ci_if_error: true
verbose: true
# run
- run: dotnet run --project ./samples/ManualGenerate/ManualGenerate.csproj -c Debug -f netcoreapp3.1
- run: dotnet run --project ./samples/ManualGenerate/ManualGenerate.csproj -c Debug -f net5.0
- run: dotnet run --project ./samples/SimpleGenerate/SimpleGenerate.csproj -c Debug -f netcoreapp3.1
- run: dotnet run --project ./samples/SimpleGenerate/SimpleGenerate.csproj -c Debug -f net5.0
# todo: add LinuxRunSamples
# - run: docker-compose up
# working-directory: ./samples/LinuxRunSamples
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,5 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd

# custom
output/
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,72 @@ namespace SkiaQrCodeSampleConsole

```

## Build
## TIPS

### Linux support

You have 2 choice to run on Linux. If you don't need font operation, use `SkiaSharp.NativeAssets.Linux.NoDependencies`.

1. Use `SkiaSharp.NativeAssets.Linux` package. In this case, you need to install `libfontconfig1` via apt or others.
1. Use `SkiaSharp.NativeAssets.Linux.NoDependencies` 2.80.2 or above. In this case, you don't need `libfontconfig1`.

SkiaSharp.NativeAssets.Linux.NoDependencies still can draw text, however can't search font cased on character or other fonts.

> Detail: https://github.com/mono/SkiaSharp/issues/964#issuecomment-549385484
**SkiaSharp.NativeAssets.Linux sample**

```shell
sudo apt update && apt install -y libfontconfig1
```

```csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.QrCode" Version="0.4.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
</ItemGroup>
</Project>
```

**SkiaSharp.NativeAssets.Linux.NoDependencies sample**

```csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.QrCode" Version="0.4.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
</ItemGroup>
</Project>
```

### Docker Build & Run

Test Build lib.

```shell
docker build -t skiasharp.qrcode .
```

Test Run on linux.

```shell
cd samples/LinuxRunSamples
docker-compose up
```

## License

MIT
Expand Down
19 changes: 19 additions & 0 deletions samples/LinuxRunSamples/3.1/BuildTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.QrCode" Version="0.4.0" />
<!-- require libfontconfig1 https://github.com/mono/SkiaSharp/issues/964#issuecomment-549385484 -->
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
</ItemGroup>

<ItemGroup>
<None Update="samples\*.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
54 changes: 54 additions & 0 deletions samples/LinuxRunSamples/3.1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using SkiaSharp;
using System;
using System.IO;
using SkiaSharp.QrCode;
using SkiaSharp.QrCode.Models;

namespace SkiaQrCodeSampleConsole
{
class Program
{
static void Main(string[] args)
{
Directory.CreateDirectory("output");

var content = "testtesttest";
using (var generator = new QRCodeGenerator())
{
// Generate QrCode
var qr = generator.CreateQrCode(content, ECCLevel.L);

// Render to canvas
var info = new SKImageInfo(512, 512);
using (var surface = SKSurface.Create(info))
{
var canvas = surface.Canvas;
canvas.Render(qr, info.Width, info.Height);

// gen color
// yellow https://rgb.to/yellow
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.FromHsl(60,100,50));
// red https://rgb.to/red
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.FromHsl(0, 100, 50));

// gen icon
var logo = File.ReadAllBytes("samples/test.png");
var icon = new IconData
{
Icon = SKBitmap.Decode(logo),
IconSizePercent = 10,
};
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.Parse("000000"), icon);

// Output to Stream -> File
using (var image = surface.Snapshot())
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(@"output/hoge.png"))
{
data.SaveTo(stream);
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions samples/LinuxRunSamples/3.1/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -ex

FRAMEWORK=netcoreapp3.1
while [ $# -gt 0 ]; do
case $1 in
-f) FRAMEWORK=$2; shift 2; ;;
*) shift ;;
esac
done

apt update && apt install -y libfontconfig1

dotnet run --csproj BuildTest.csproj -f "${FRAMEWORK}"
Binary file added samples/LinuxRunSamples/3.1/samples/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions samples/LinuxRunSamples/3.1_nodep/BuildTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.QrCode" Version="0.4.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
</ItemGroup>

<ItemGroup>
<None Update="samples\*.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
54 changes: 54 additions & 0 deletions samples/LinuxRunSamples/3.1_nodep/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using SkiaSharp;
using System;
using System.IO;
using SkiaSharp.QrCode;
using SkiaSharp.QrCode.Models;

namespace SkiaQrCodeSampleConsole
{
class Program
{
static void Main(string[] args)
{
Directory.CreateDirectory("output");

var content = "testtesttest";
using (var generator = new QRCodeGenerator())
{
// Generate QrCode
var qr = generator.CreateQrCode(content, ECCLevel.L);

// Render to canvas
var info = new SKImageInfo(512, 512);
using (var surface = SKSurface.Create(info))
{
var canvas = surface.Canvas;
canvas.Render(qr, info.Width, info.Height);

// gen color
// yellow https://rgb.to/yellow
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.FromHsl(60,100,50));
// red https://rgb.to/red
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.FromHsl(0, 100, 50));

// gen icon
var logo = File.ReadAllBytes("samples/test.png");
var icon = new IconData
{
Icon = SKBitmap.Decode(logo),
IconSizePercent = 10,
};
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.Parse("000000"), icon);

// Output to Stream -> File
using (var image = surface.Snapshot())
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(@"output/hoge.png"))
{
data.SaveTo(stream);
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions samples/LinuxRunSamples/3.1_nodep/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -ex

FRAMEWORK=netcoreapp3.1
while [ $# -gt 0 ]; do
case $1 in
-f) FRAMEWORK=$2; shift 2; ;;
*) shift ;;
esac
done

dotnet run --csproj BuildTest.csproj -f "${FRAMEWORK}"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions samples/LinuxRunSamples/5.0/BuildTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.QrCode" Version="0.4.0" />
<!-- require libfontconfig1 https://github.com/mono/SkiaSharp/issues/964#issuecomment-549385484 -->
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
</ItemGroup>

<ItemGroup>
<None Update="samples\*.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
54 changes: 54 additions & 0 deletions samples/LinuxRunSamples/5.0/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using SkiaSharp;
using System;
using System.IO;
using SkiaSharp.QrCode;
using SkiaSharp.QrCode.Models;

namespace SkiaQrCodeSampleConsole
{
class Program
{
static void Main(string[] args)
{
Directory.CreateDirectory("output");

var content = "testtesttest";
using (var generator = new QRCodeGenerator())
{
// Generate QrCode
var qr = generator.CreateQrCode(content, ECCLevel.L);

// Render to canvas
var info = new SKImageInfo(512, 512);
using (var surface = SKSurface.Create(info))
{
var canvas = surface.Canvas;
canvas.Render(qr, info.Width, info.Height);

// gen color
// yellow https://rgb.to/yellow
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.FromHsl(60,100,50));
// red https://rgb.to/red
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.FromHsl(0, 100, 50));

// gen icon
var logo = File.ReadAllBytes("samples/test.png");
var icon = new IconData
{
Icon = SKBitmap.Decode(logo),
IconSizePercent = 10,
};
canvas.Render(qr, info.Width, info.Height, SKColor.Empty, SKColor.Parse("000000"), icon);

// Output to Stream -> File
using (var image = surface.Snapshot())
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(@"output/hoge.png"))
{
data.SaveTo(stream);
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions samples/LinuxRunSamples/5.0/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -ex

FRAMEWORK=netcoreapp3.1
while [ $# -gt 0 ]; do
case $1 in
-f) FRAMEWORK=$2; shift 2; ;;
*) shift ;;
esac
done

apt update && apt install -y libfontconfig1

dotnet run --csproj BuildTest.csproj -f "${FRAMEWORK}"
Binary file added samples/LinuxRunSamples/5.0/samples/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions samples/LinuxRunSamples/5.0_nodep/BuildTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.QrCode" Version="0.4.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
</ItemGroup>

<ItemGroup>
<None Update="samples\*.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Loading

0 comments on commit 0d90ae4

Please sign in to comment.