From 5a8e6179da4f961413f3cdea89e037a93e4bee3e Mon Sep 17 00:00:00 2001 From: BobLd <38405645+BobLd@users.noreply.github.com> Date: Sat, 4 May 2024 17:13:43 +0100 Subject: [PATCH] Add AndroidSystemFontLister --- .../SystemFonts/AndroidSystemFontLister.cs | 52 +++++++++++++++++++ .../SystemFonts/LinuxSystemFontLister.cs | 2 +- .../SystemFonts/MacSystemFontLister.cs | 2 +- .../SystemFonts/SystemFontFinder.cs | 6 +++ .../SystemFonts/WindowsSystemFontLister.cs | 2 +- 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/UglyToad.PdfPig.Fonts/SystemFonts/AndroidSystemFontLister.cs diff --git a/src/UglyToad.PdfPig.Fonts/SystemFonts/AndroidSystemFontLister.cs b/src/UglyToad.PdfPig.Fonts/SystemFonts/AndroidSystemFontLister.cs new file mode 100644 index 00000000..da574dba --- /dev/null +++ b/src/UglyToad.PdfPig.Fonts/SystemFonts/AndroidSystemFontLister.cs @@ -0,0 +1,52 @@ +namespace UglyToad.PdfPig.Fonts.SystemFonts +{ +#if NET + using System.Collections.Generic; + using System.IO; + + internal sealed class AndroidSystemFontLister : ISystemFontLister + { + public IEnumerable GetAllFonts() + { + var directories = new List + { + "/system/fonts", + }; + + foreach (var directory in directories) + { + try + { + if (!Directory.Exists(directory)) + { + continue; + } + } + catch + { + continue; + } + + string[] files; + + try + { + files = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories); + } + catch + { + continue; + } + + foreach (var file in files) + { + if (SystemFontRecord.TryCreate(file, out var record)) + { + yield return record; + } + } + } + } + } +#endif +} diff --git a/src/UglyToad.PdfPig.Fonts/SystemFonts/LinuxSystemFontLister.cs b/src/UglyToad.PdfPig.Fonts/SystemFonts/LinuxSystemFontLister.cs index 0c7edcbb..ee8a4ec1 100644 --- a/src/UglyToad.PdfPig.Fonts/SystemFonts/LinuxSystemFontLister.cs +++ b/src/UglyToad.PdfPig.Fonts/SystemFonts/LinuxSystemFontLister.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.IO; - internal class LinuxSystemFontLister : ISystemFontLister + internal sealed class LinuxSystemFontLister : ISystemFontLister { public IEnumerable GetAllFonts() { diff --git a/src/UglyToad.PdfPig.Fonts/SystemFonts/MacSystemFontLister.cs b/src/UglyToad.PdfPig.Fonts/SystemFonts/MacSystemFontLister.cs index 47c22430..b074f757 100644 --- a/src/UglyToad.PdfPig.Fonts/SystemFonts/MacSystemFontLister.cs +++ b/src/UglyToad.PdfPig.Fonts/SystemFonts/MacSystemFontLister.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.IO; - internal class MacSystemFontLister : ISystemFontLister + internal sealed class MacSystemFontLister : ISystemFontLister { public IEnumerable GetAllFonts() { diff --git a/src/UglyToad.PdfPig.Fonts/SystemFonts/SystemFontFinder.cs b/src/UglyToad.PdfPig.Fonts/SystemFonts/SystemFontFinder.cs index 1720fe43..8482ef79 100644 --- a/src/UglyToad.PdfPig.Fonts/SystemFonts/SystemFontFinder.cs +++ b/src/UglyToad.PdfPig.Fonts/SystemFonts/SystemFontFinder.cs @@ -89,6 +89,12 @@ namespace UglyToad.PdfPig.Fonts.SystemFonts { lister = new LinuxSystemFontLister(); } +#if NET + else if (OperatingSystem.IsAndroid()) + { + lister = new AndroidSystemFontLister(); + } +#endif else { throw new NotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}."); diff --git a/src/UglyToad.PdfPig.Fonts/SystemFonts/WindowsSystemFontLister.cs b/src/UglyToad.PdfPig.Fonts/SystemFonts/WindowsSystemFontLister.cs index 8740a8ac..a8dc6b8c 100644 --- a/src/UglyToad.PdfPig.Fonts/SystemFonts/WindowsSystemFontLister.cs +++ b/src/UglyToad.PdfPig.Fonts/SystemFonts/WindowsSystemFontLister.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.IO; - internal class WindowsSystemFontLister : ISystemFontLister + internal sealed class WindowsSystemFontLister : ISystemFontLister { public IEnumerable GetAllFonts() {