Skip to content

Commit 5bda2df

Browse files
xqxq
authored andcommitted
Update dependencies SkiaSharp and SkiaSharp.HarfBuzz to 3.119.0, and HarfBuzzSharp.NativeAssets to 8.3.1.1. Replace the deprecated methods marked with SkiaSharp3.0 in the project with new ones.
1 parent 2e8a37a commit 5bda2df

9 files changed

Lines changed: 79 additions & 81 deletions

File tree

RichStringSandbox/Form1.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,19 @@ void OnRender(SKCanvas canvas)
108108
_richString.MaxHeight = height;
109109

110110
var state = $"Measured: {_richString.MeasuredWidth} x {_richString.MeasuredHeight} Lines: {_richString.LineCount} Truncated: {_richString.Truncated} Length: {_richString.MeasuredLength} Revision: {_richString.Revision}";
111-
canvas.DrawText(state, margin, 20, new SKPaint()
111+
using (var font = new SKFont(SKTypeface.FromFamilyName("Arial"),12))
112112
{
113-
Typeface = SKTypeface.FromFamilyName("Arial"),
114-
TextSize = 12,
115-
IsAntialias = true,
116-
});
113+
canvas.DrawText(state, margin, 20, font, new SKPaint()
114+
{
115+
IsAntialias = true,
116+
});
117117

118-
state = $"Hit Test: Over {_htr.OverCodePointIndex} Line {_htr.OverLine}. Closest: {_htr.ClosestCodePointIndex} Line {_htr.ClosestLine}";
119-
canvas.DrawText(state, margin, 40, new SKPaint()
120-
{
121-
Typeface = SKTypeface.FromFamilyName("Arial"),
122-
TextSize = 12,
123-
IsAntialias = true,
124-
});
118+
state = $"Hit Test: Over {_htr.OverCodePointIndex} Line {_htr.OverLine}. Closest: {_htr.ClosestCodePointIndex} Line {_htr.ClosestLine}";
119+
canvas.DrawText(state, margin, 40,font, new SKPaint()
120+
{
121+
IsAntialias = true,
122+
});
123+
}
125124

126125
var options = new TextPaintOptions()
127126
{

RichStringSandbox/RichStringSandbox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
</ProjectReference>
9898
</ItemGroup>
9999
<ItemGroup>
100-
<PackageReference Include="SkiaSharp" Version="2.88.7" />
100+
<PackageReference Include="SkiaSharp" Version="3.119.0" />
101101
</ItemGroup>
102102
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
103103
</Project>

Sandbox/Sandbox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</ProjectReference>
102102
</ItemGroup>
103103
<ItemGroup>
104-
<PackageReference Include="SkiaSharp" Version="2.88.7" />
104+
<PackageReference Include="SkiaSharp" Version="3.119.0" />
105105
</ItemGroup>
106106
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
107107
</Project>

SandboxDriver/SandboxDriver.cs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -334,33 +334,29 @@ public void Render(SKCanvas canvas, float canvasWidth, float canvasHeight)
334334
canvas.DrawLine(rect.Right, rect.Top, rect.Left, rect.Bottom, paint);
335335
}
336336
}
337-
338-
var state = $"Size: {width} x {height} Base Direction: {BaseDirection} Alignment: {TextAlignment} Content: {ContentMode} scale: {Scale} time: {elapsed} subpixel: {SubpixelPositioning} hinting: {Hinting} edging: {Edging}";
339-
canvas.DrawText(state, margin, 20, new SKPaint()
340-
{
341-
Typeface = SKTypeface.FromFamilyName("Arial"),
342-
TextSize = 12,
343-
IsAntialias = true,
344-
});
345-
346-
if (options.Selection.HasValue)
347-
state = $"Selection: {options.Selection.Value.Start}-{options.Selection.Value.End} Closest: {(htr.HasValue ? htr.Value.ClosestCodePointIndex.ToString() : "-")}";
348-
else
349-
state = $"Selection: none";
350-
canvas.DrawText(state, margin, 40, new SKPaint()
337+
using (var font = new SKFont(SKTypeface.FromFamilyName("Arial"), 12))
351338
{
352-
Typeface = SKTypeface.FromFamilyName("Arial"),
353-
TextSize = 12,
354-
IsAntialias = true,
355-
});
339+
var state = $"Size: {width} x {height} Base Direction: {BaseDirection} Alignment: {TextAlignment} Content: {ContentMode} scale: {Scale} time: {elapsed} subpixel: {SubpixelPositioning} hinting: {Hinting} edging: {Edging}";
340+
canvas.DrawText(state, margin, 20, font, new SKPaint()
341+
{
342+
IsAntialias = true,
343+
});
356344

357-
state = $"Measured: {_textBlock.MeasuredWidth} x {_textBlock.MeasuredHeight} Lines: {_textBlock.Lines.Count} Truncated: {_textBlock.Truncated}";
358-
canvas.DrawText(state, margin, 60, new SKPaint()
359-
{
360-
Typeface = SKTypeface.FromFamilyName("Arial"),
361-
TextSize = 12,
362-
IsAntialias = true,
363-
});
345+
if (options.Selection.HasValue)
346+
state = $"Selection: {options.Selection.Value.Start}-{options.Selection.Value.End} Closest: {(htr.HasValue ? htr.Value.ClosestCodePointIndex.ToString() : "-")}";
347+
else
348+
state = $"Selection: none";
349+
canvas.DrawText(state, margin, 40, font, new SKPaint()
350+
{
351+
IsAntialias = true,
352+
});
353+
354+
state = $"Measured: {_textBlock.MeasuredWidth} x {_textBlock.MeasuredHeight} Lines: {_textBlock.Lines.Count} Truncated: {_textBlock.Truncated}";
355+
canvas.DrawText(state, margin, 60, font, new SKPaint()
356+
{
357+
IsAntialias = true,
358+
});
359+
}
364360
}
365361

366362
float _hitTestX;

SandboxDriver/SandboxDriver.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="SkiaSharp" Version="2.88.7" />
16+
<PackageReference Include="SkiaSharp" Version="3.119.0" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

Topten.RichTextKit.Test/Topten.RichTextKit.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
1212
<PackageReference Include="xunit" Version="2.4.1" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
13+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="SkiaSharp" Version="2.88.7" />
17+
<PackageReference Include="SkiaSharp" Version="3.119.0" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

Topten.RichTextKit/FontRun.cs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -497,45 +497,49 @@ internal void UpdateOverhang(float right, bool updateTop, bool updateBottom, ref
497497

498498
using (var paint = new SKPaint())
499499
{
500-
float glyphScale = 1;
501-
if (Style.FontVariant == FontVariant.SuperScript)
502-
{
503-
glyphScale = 0.65f;
504-
}
505-
if (Style.FontVariant == FontVariant.SubScript)
500+
using (var font = new SKFont())
506501
{
507-
glyphScale = 0.65f;
508-
}
502+
float glyphScale = 1;
503+
if (Style.FontVariant == FontVariant.SuperScript)
504+
{
505+
glyphScale = 0.65f;
506+
}
507+
if (Style.FontVariant == FontVariant.SubScript)
508+
{
509+
glyphScale = 0.65f;
510+
}
509511

510-
paint.TextEncoding = SKTextEncoding.GlyphId;
511-
paint.Typeface = Typeface;
512-
paint.TextSize = Style.FontSize * glyphScale;
513-
paint.SubpixelText = true;
514-
paint.IsAntialias = true;
515-
paint.LcdRenderText = false;
512+
paint.IsAntialias = true;
513+
font.Typeface = Typeface;
514+
font.Size = Style.FontSize * glyphScale;
515+
font.Subpixel = true;
516+
font.Edging = SKFontEdging.Antialias;
516517

517-
unsafe
518-
{
519-
fixed (ushort* pGlyphs = Glyphs.Underlying)
518+
unsafe
520519
{
521-
paint.GetGlyphWidths((IntPtr)(pGlyphs + Start), sizeof(ushort) * Glyphs.Length, out var bounds);
522-
if (bounds != null)
520+
fixed (ushort* pGlyphs = Glyphs.Underlying)
523521
{
524-
for (int i = 0; i < bounds.Length; i++)
522+
523+
font.GetGlyphWidths((IntPtr)(pGlyphs + Start), sizeof(ushort) * Glyphs.Length, SKTextEncoding.GlyphId, out var bounds, paint);
524+
if (bounds != null)
525525
{
526-
float gx = GlyphPositions[i].X;
526+
for (int i = 0; i < bounds.Length; i++)
527+
{
528+
float gx = GlyphPositions[i].X;
527529

528-
var loh = -(gx + bounds[i].Left);
529-
if (loh > leftOverhang)
530-
leftOverhang = loh;
530+
var loh = -(gx + bounds[i].Left);
531+
if (loh > leftOverhang)
532+
leftOverhang = loh;
531533

532-
var roh = (gx + bounds[i].Right + 1) - right;
533-
if (roh > rightOverhang)
534-
rightOverhang = roh;
534+
var roh = (gx + bounds[i].Right + 1) - right;
535+
if (roh > rightOverhang)
536+
rightOverhang = roh;
537+
}
535538
}
536539
}
537540
}
538541
}
542+
539543
}
540544
}
541545

Topten.RichTextKit/TextShaping/TextShaper.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,20 @@ private TextShaper(SKTypeface typeface)
7575
}
7676

7777
// Get font metrics for this typeface
78-
using (var paint = new SKPaint())
78+
using (var font = new SKFont())
7979
{
80-
paint.Typeface = typeface;
81-
paint.TextSize = overScale;
82-
_fontMetrics = paint.FontMetrics;
80+
font.Typeface = typeface;
81+
font.Size = overScale;
82+
_fontMetrics = font.Metrics;
8383

8484
// This is a temporary hack until SkiaSharp exposes
8585
// a way to check if a font is fixed pitch. For now
8686
// we just measure and `i` and a `w` and see if they're
8787
// the same width.
88-
float[] widths = paint.GetGlyphWidths("iw", out var rects);
88+
float[] widths = font.GetGlyphWidths("iw", out var rects);
8989
_isFixedPitch = widths != null && widths.Length > 1 && widths[0] == widths[1];
9090
if (_isFixedPitch)
9191
_fixedCharacterWidth = widths[0];
92-
9392
}
9493
}
9594

Topten.RichTextKit/Topten.RichTextKit.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.3" />
24-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
23+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.1.1" />
24+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
2525
<PrivateAssets>all</PrivateAssets>
2626
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2727
</PackageReference>
28-
<PackageReference Include="SkiaSharp" Version="2.88.7" />
29-
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.7" />
30-
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
31-
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
28+
<PackageReference Include="SkiaSharp" Version="3.119.0" />
29+
<PackageReference Include="SkiaSharp.HarfBuzz" Version="3.119.0" />
30+
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.119.0" />
31+
<PackageReference Include="System.ValueTuple" Version="4.6.1" />
3232
</ItemGroup>
3333

3434
</Project>

0 commit comments

Comments
 (0)