From 9204b8f82efb739d645a3cac4b9f5039a98fb6c8 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Thu, 19 Jan 2023 14:28:03 -0500 Subject: [PATCH] fix(reg): Include explicitly specified fonts in info.plist for backward compatibilty --- .../Assets/RetargetAssets.Fonts.cs | 23 +++++++++++++++++-- .../Uno.UI.Tasks/Assets/RetargetAssets.cs | 4 +++- .../Uno.UI.Tasks/Content/Uno.UI.Tasks.targets | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.Fonts.cs b/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.Fonts.cs index e26ef18fa54d..003eacee85ba 100644 --- a/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.Fonts.cs +++ b/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.Fonts.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Xml; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Uno.UI.Tasks.Helpers; @@ -31,10 +32,15 @@ public partial class RetargetAssets_v0 """; - private ITaskItem[] GenerateFontPartialManifest(List fontAssets) + private ITaskItem[] GenerateFontPartialManifest(List fontAssets, string iOSAppManifest) { if (TargetPlatform == "ios") { + // For compatibility measures, get the fonts from the iOS app manifest + // and merge them with the generated ones, so existing apps don't lose + // explicitly specified ones. + var existingFonts = EnumerateFontsFromPList(IosAppManifest); + var outputManifestFile = Path.Combine(IntermediateOutputPath, "FontsPartialInfo.plist"); using var writer = File.CreateText(outputManifestFile); @@ -46,7 +52,7 @@ private ITaskItem[] GenerateFontPartialManifest(List fontAssets) writer.WriteLine(" UIAppFonts"); writer.WriteLine(" "); - foreach (var font in fontAssets) + foreach (var font in fontAssets.Concat(existingFonts)) { writer.WriteLine(" " + font + ""); } @@ -63,4 +69,17 @@ private ITaskItem[] GenerateFontPartialManifest(List fontAssets) return Array.Empty(); } } + + private string[] EnumerateFontsFromPList(string iosAppManifest) + { + XmlDocument doc = new(); + doc.Load(iosAppManifest); + + // Get the list of registered fonts in the info.plist + return doc + .SelectNodes("//key[text()='UIAppFonts']/following-sibling::array[1]/string") + .OfType() + .Select(n => n.InnerText) + .ToArray(); + } } diff --git a/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs b/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs index 2135ade975dd..398b4973169c 100644 --- a/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs +++ b/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs @@ -31,6 +31,8 @@ public partial class RetargetAssets_v0 : Task public string AndroidAssetsPrefix { get; set; } + public string IosAppManifest { get; set; } + [Required] public string DefaultLanguage { get; set; } @@ -169,7 +171,7 @@ private void ProcessContentItems(ITaskItem[] assets, Func