Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to SkiaSharp.Harfbuzz for getting shaped text paths #2513

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ScrubN
Copy link

@ScrubN ScrubN commented Jun 28, 2023

Description of Change

Add a class and set of new methods to SkiaSharp.Harfbuzz for shaping a text input and returning an SKPath of said text input

Features Resolved

API Changes

Added:

  • SKPath FontExtensions.GetShapedTextPath(this SKFont paint, string text, SKPoint p, SKTextAlign textAlign)
  • SKPath FontExtensions.GetShapedTextPath(this SKFont paint, string text, float x, float y, SKTextAlign textAlign)
  • SKPath FontExtensions.GetShapedTextPath(this SKFont paint, SKShaper shaper, string text, float x, float y, SKTextAlign textAlign)

Behavioral Changes

None.

Required skia PR

None.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation

Additional Notes

If this PR is wanted, I can create a documentation PR as well.

@ScrubN
Copy link
Author

ScrubN commented Jun 28, 2023

@dotnet-policy-service agree

@ScrubN
Copy link
Author

ScrubN commented Jun 28, 2023

I should also mention that the choice to use SKFont.GetGlyphPath() over SKFont.GetGlyphPaths() was deliberate. In my testing, GetGlyphPaths() tended to be 2-5% slower and allocated up to 50% more memory (.NET 7).

BenchmarkDotNet=v0.13.5, OS=Windows 10 (10.0.19045.3086/22H2/2022Update)
AMD Ryzen 7 5800X, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.304
  [Host]     : .NET 7.0.7 (7.0.723.27404), X64 RyuJIT AVX2
  DefaultJob : .NET 7.0.7 (7.0.723.27404), X64 RyuJIT AVX2

Method StringLength Mean Error StdDev Gen0 Gen1 Gen2 Allocated
GetShapedTextPath_GetGlyphPath 41 297.2 μs 5.72 μs 4.78 μs - - - 6.33 KB
GetShapedTextPath_GetGlyphPaths 41 304.0 μs 5.98 μs 9.65 μs 0.4883 - - 9.16 KB
GetShapedTextPath_GetGlyphPath 410 627.2 μs 8.06 μs 6.30 μs 2.9297 - - 55.99 KB
GetShapedTextPath_GetGlyphPaths 410 648.6 μs 12.84 μs 12.01 μs 4.8828 3.9063 - 83.43 KB
GetShapedTextPath_GetGlyphPath 4,100 5,035.4 μs 97.87 μs 133.96 μs 31.2500 - - 552.75 KB
GetShapedTextPath_GetGlyphPaths 4,100 4,603.0 μs 90.81 μs 114.84 μs 46.8750 39.0625 - 826.29 KB
GetShapedTextPath_GetGlyphPath 41,000 49,409.5 μs 973.14 μs 1,543.50 μs 636.3636 454.5455 454.5455 5520.5 KB
GetShapedTextPath_GetGlyphPaths 41,000 51,697.9 μs 979.89 μs 1,663.93 μs 750.0000 750.0000 500.0000 8255.01 KB

Notes

  • These results are from the final benchmark run (3 runs total). This was the only run where GetGlyphPaths() was faster with a string length of 4,100.
  • The string used was الثعلب البني السريع يقفز فوق الكلب الكسول. The length was increased by appending the string to itself multiple times within the benchmark global setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add function to SkiaSharp.Harfbuzz for getting shaped text paths
1 participant