dme-compunet/YoloV8

What to do if you can't find a font by its name.

actbit opened this issue · 7 comments

actbit commented

SystemFonts.CreateFont(fontname,fontsize) method cannot be used to find fonts in an environment like Maui Android.
Therefore, the PlottingExtensions.PlotImage method raises a SixLabors.Fonts.FontFamilyNotFoundException.

We believe this can be addressed by allowing Fonts.Font or Stream to specify the font in PlottingOptions. However, we currently cannot resolve this issue without a change to the code.

I thought about sending a pull request for the change, but did not for fear of compromising compatibility.

I would like to know what I need to do and how to address this issue.

Thank you in advance for your help.

Thanks for bringing this to my attention.
I don't exactly understand to which way I should change it, can you show me a code sample that can load a font in Android Maui environment.

actbit commented

Thank you for your response.

I was looking into the SystemFonts.CreateFont method and found that this commit supports loading Android system fonts.
We believe this version will be adapted in the next release.

However, there may be a period of time before the next release,
The YoloV8 project did not support loading external fonts.
So I wrote a program to solve this problem.
https://github.com/binary-number/YOLOv8/tree/MauiFontTest

I had so much fun writing the code that instead of writing sample source code, I actually wrote the improved code. My apologies.

Here is the source description
You can load external fonts by adding them to FontManager.LoadedFontCollection.
Also, we replaced SystemFonts.CreateFont method with FontManager.CreateFont method, and FontManager.CreateFont method looks for fonts from within the LoadedFontCollection as well.
Also, since Arial fonts were not available for Android, Robot fonts were specified.

If there is no problem with this code, I will send a pull request.

Thank you in advance.

Will changing the string FontName property to FontFamily FontFamily in PlottingOptions solve your problem?

actbit commented

If you are not afraid of losing compatibility, I think that solution is fine.

Now I see that in the stable version published a week ago, the problem with the fonts in Android has already been fixed, is it important for you to still use FontFamily or is it fine now?

actbit commented

I updated the version of SixLabors.ImageSharp.Drawing to 1.0.0 and ran it, and it was possible to specify the system font from the fontname, so I think the problem with the error has been resolved.

However, I think it is significant to replace fontname with FontFamily.
By replacing fontname with FontFamily, it will be possible to dynamically load fonts embedded in software, fonts on the web, or font files enclosed in applications from a stream or file. By being able to load arbitrary font files, you no longer need to be aware of differences between environments.

I updated it, now you can use FontFamily.