Skip to content

Commit d5fb935

Browse files
authored
Update SkiaSharp to v3 (major) (#71)
2 parents 9ba6dfb + 2011db5 commit d5fb935

File tree

10 files changed

+23
-20
lines changed

10 files changed

+23
-20
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ jobs:
3333
- name: Process test results
3434
if: ${{ success() || failure() }}
3535
shell: pwsh
36-
run: ./eng/process-test-results.ps1
36+
run: ./eng/process-test-results.ps1 -Branch "${{ github.head_ref || github.ref_name }}"
3737
env:
3838
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

eng/process-test-results.ps1

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[CmdletBinding(PositionalBinding=$false)]
22
param (
3+
$branch = $null,
34
[switch]$dry = $false
45
)
56

@@ -8,7 +9,8 @@ $ErrorActionPreference = "Stop"
89

910
# If snapshots are changed, create a pull request.
1011
if (git status --porcelain) {
11-
$currentBranch = $(git branch --show-current)
12+
$currentBranch = $branch ?? $(git branch --show-current)
13+
Write-Output "Branch: '$currentBranch'"
1214

1315
# Avoid making new PR against snapshot-updating PR.
1416
if ($currentBranch.StartsWith("update-snapshots")) {
@@ -23,14 +25,10 @@ if (git status --porcelain) {
2325

2426
git branch -D update-snapshots/$currentBranch
2527
git checkout -b update-snapshots/$currentBranch
26-
try {
27-
git commit -am "Update snapshots"
28-
git push -f origin update-snapshots/$currentBranch
29-
gh pr create --base $currentBranch --title "Update snapshots" `
30-
--body "Generate automatically by script ``process-test-results.ps1``."
31-
} finally {
32-
git checkout $currentBranch
33-
}
28+
git commit -am "Update snapshots"
29+
git push -f origin update-snapshots/$currentBranch
30+
gh pr create --base $currentBranch --title "Update snapshots" `
31+
--body "Generated automatically by script ``process-test-results.ps1``."
3432
} else {
3533
Write-Output "No changes in snapshots"
3634
}

src/KnowledgePicker.WordCloud/Drawing/SkGraphicEngine.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ public sealed class SkGraphicEngine : IGraphicEngine<SKBitmap>
1212
private readonly SKCanvas canvas;
1313
private readonly SKColor defaultColor;
1414
private readonly SKPaint textPaint;
15+
private readonly SKTypeface? typeface;
16+
private readonly SKFont font;
1517
private readonly WordCloudInput wordCloud;
1618
private bool bitmapExtracted;
1719

1820
private SkGraphicEngine(ISizer sizer, WordCloudInput wordCloud,
19-
SKPaint textPaint)
21+
SKPaint textPaint, SKTypeface? typeface = null)
2022
{
2123
Sizer = sizer;
2224
this.wordCloud = wordCloud;
2325
defaultColor = textPaint.Color;
2426
this.textPaint = textPaint;
27+
this.typeface = typeface;
28+
font = typeface is null ? new SKFont() : new SKFont(typeface);
2529
Bitmap = new SKBitmap(wordCloud.Width, wordCloud.Height);
2630
canvas = new SKCanvas(Bitmap);
2731
}
@@ -36,9 +40,10 @@ public SkGraphicEngine(ISizer sizer, WordCloudInput wordCloud,
3640
textPaint = new SKPaint
3741
{
3842
Color = defaultColor,
39-
Typeface = font,
4043
IsAntialias = antialias
4144
};
45+
typeface = font;
46+
this.font = font is null ? new SKFont() : new SKFont(font);
4247
this.wordCloud = wordCloud;
4348
}
4449

@@ -48,9 +53,8 @@ public SkGraphicEngine(ISizer sizer, WordCloudInput wordCloud,
4853

4954
public RectangleD Measure(string text, int count)
5055
{
51-
textPaint.TextSize = (float)Sizer.GetFontSize(count);
52-
SKRect rect = new SKRect();
53-
textPaint.MeasureText(text, ref rect);
56+
font.Size = (float)Sizer.GetFontSize(count);
57+
font.MeasureText(text, out SKRect rect);
5458
var m = wordCloud.ItemMargin;
5559
return new RectangleD(rect.Left + m, rect.Top + m, rect.Width + 2 * m, rect.Height + 2 * m);
5660
}
@@ -59,7 +63,7 @@ public void Draw(PointD location, RectangleD measured, string text, int count, s
5963
{
6064
// For computation explanation, see
6165
// https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/text.
62-
textPaint.TextSize = (float)Sizer.GetFontSize(count);
66+
font.Size = (float)Sizer.GetFontSize(count);
6367
if (colorHex != null)
6468
{
6569
textPaint.Color = SKColor.Parse(colorHex);
@@ -69,14 +73,14 @@ public void Draw(PointD location, RectangleD measured, string text, int count, s
6973
textPaint.Color = defaultColor;
7074
}
7175
canvas.DrawText(text, (float)(location.X - measured.Left),
72-
(float)(location.Y - measured.Top), textPaint);
76+
(float)(location.Y - measured.Top), font, textPaint);
7377
}
7478

7579
public IGraphicEngine<SKBitmap> Clone()
7680
{
7781
var clonedTextPaint = textPaint.Clone();
7882
clonedTextPaint.Color = defaultColor;
79-
return new SkGraphicEngine(Sizer, wordCloud, clonedTextPaint);
83+
return new SkGraphicEngine(Sizer, wordCloud, clonedTextPaint, typeface);
8084
}
8185

8286
public SKBitmap ExtractBitmap()
@@ -87,6 +91,7 @@ public SKBitmap ExtractBitmap()
8791

8892
public void Dispose()
8993
{
94+
font.Dispose();
9095
textPaint.Dispose();
9196
canvas.Dispose();
9297
if (!bitmapExtracted)

src/KnowledgePicker.WordCloud/KnowledgePicker.WordCloud.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</PropertyGroup>
2929

3030
<ItemGroup>
31-
<PackageReference Include="SkiaSharp" Version="2.88.9" />
31+
<PackageReference Include="SkiaSharp" Version="3.116.0" />
3232
</ItemGroup>
3333

3434
<ItemGroup>
2.62 KB
Loading
2.36 KB
Loading
6.22 KB
Loading
1.15 KB
Loading
3.73 KB
Loading

test/KnowledgePicker.WordCloud.Tests/KnowledgePicker.WordCloud.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<ItemGroup>
2525
<ProjectReference Include="..\..\src\KnowledgePicker.WordCloud\KnowledgePicker.WordCloud.csproj" />
26-
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.9" />
26+
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.116.0" />
2727
</ItemGroup>
2828

2929
</Project>

0 commit comments

Comments
 (0)