uno.toolkit.ui icon indicating copy to clipboard operation
uno.toolkit.ui copied to clipboard

Cross-platform API to get all system font families

Open hungnd1475 opened this issue 5 years ago • 8 comments

What would you like to be added:

A cross-platform API that can be used to retrieve all system font families.

Why is this needed:

Right now there is no easy way for developers to get all system font families across all platforms. This enhancement might be very useful for LOB applications with rich text editing capabilities.

For which Platform:

  • [x] iOS
  • [x] Android
  • [x] WebAssembly
  • [x] WebAssembly renderers for Xamarin.Forms
  • [x] macOS
  • [x] Skia
    • [x] WPF
    • [x] GTK (Linux)
    • [x] Tizen
  • [x] Windows
  • [ ] Build tasks
  • [ ] Solution Templates

Anything else we need to know?

hungnd1475 avatar Jan 23 '21 01:01 hungnd1475

For Windows, you can use that: http://microsoft.github.io/Win2D/html/M_Microsoft_Graphics_Canvas_Text_CanvasTextFormat_GetSystemFontFamilies.htm (from the Win2D.uwp NuGet package.

But it's not part of the UWP/WinUI contract, so not available right now on Uno. But...

  • On WASM, you can use the document.fonts javscript API
  • On Android, I'm not sure if there's an API for that. I think there's very few fonts available for apps and you need to supply those you want with your app.
  • On iOS 12+, there's the UIFont.FamilyNames
  • For Skia, you can call SKFontManager.FontFamilies
Gets a list of font families available.

carldebilly avatar Jan 24 '21 21:01 carldebilly

@carldebilly I am aware of using platform-specific code, but it would be nicer if we have a single API handling this use case. Right now we need to stick with this workaround I guess. Anyway thanks for pointing me to those links, it would save me some time searching for them.

hungnd1475 avatar Jan 25 '21 06:01 hungnd1475

I agree it would be a good idea to create a unified API for that. But since it's not present in UWP/WinUI, it would need to be in the Uno toolkit.

carldebilly avatar Jan 25 '21 13:01 carldebilly

For me, System.Drawing.Font is not working on a droid project.... I also tried to add System.Drawing.Common package to project, but it didn't help. Is this problem relates to this issue?

LeftTwixWand avatar Mar 11 '21 14:03 LeftTwixWand

Guys, unless I do not understand something, it should not be very difficult to create a platform independent way of getting the fonts. Why has not it been done?

c-npolyak avatar Jun 14 '23 19:06 c-npolyak

@c-npolyak we mostly work by priorities on our customers, and this has not been requested yet.

That being said, at the time this question was asked, UWP was not providing this and while WinAppSDK does not, Uno.Toolkit may be good place to provide an API for such a feature that could be available for more platforms, WinAppSDK included.

jeromelaban avatar Jun 14 '23 20:06 jeromelaban

I think Uno Extensions would be a better place for this - can we move this issue there @jeromelaban ?

MartinZikmund avatar Jul 10 '23 07:07 MartinZikmund

This looks like a toolkit feature rather than extensions, I'll move it there.

jeromelaban avatar Jul 11 '23 12:07 jeromelaban