AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.75k stars 2.14k forks source link

Remove HarfBuzzSharp dependency for Avalonia.Direct2D1 #5990

Open ThomasGoulet73 opened 3 years ago

ThomasGoulet73 commented 3 years ago

Is your feature request related to a problem? Please describe. I think the title is pretty self-explanatory. I think it would be good if Avalonia.Direct2D1 didn't depend on HarfBuzzSharp. SharpDX.Direct2D1 already has a text renderer (DirectWrite), which led me to think that HarfBuzzSharp was not used a lot and it turns out that there are only two file that uses it: TextShaperImpl.cs GlyphTypefaceImpl.cs

Describe the solution you'd like Replace the uses of HarfBuzzSharp with their DirectWrite counterpart (If said counterpart exists).

Additional context One of the benefit would be to remove the last native dependency for a Win32 and Direct2D1 application. libHarfBuzzSharp.dll is the last native file in a self-contained single-file .Net 6 app (You can remove it using by setting IncludeNativeLibrariesForSelfExtract to true but I don't think it's the right solution).

Gillibald commented 3 years ago

Feel free to change the implementation to use https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritetextanalyzer-getglyphs

Gillibald commented 3 years ago

SharpDX isn't covering everything we need and many parts don't work with Spans etc. so we need to allocate extra memory. I prefer HarfBuzzSharp over additional API's that are exposed via SharpDX.

ThomasGoulet73 commented 3 years ago

@Gillibald I understand that one might be better than the other. But if one supports everything Avalonia.Direct2D1 needs (Which I think SharpDX.Direct2D1 does), I think we should take it. The reason I wanted to only have SharpDX.Direct2D1 is because it's already used in a lot of place in Avalonia.Direct2D1 while HarfBuzzSharp is used in 2 files.

Gillibald commented 3 years ago

The moment there is a modern maintained Direct2D1 binding I am willing to remove the HarfBuzz dependency from the Direct2D1 backend.