3
3
using System . Diagnostics ;
4
4
using System . IO ;
5
5
using System . Linq ;
6
+ using System . Xml ;
6
7
using Microsoft . Build . Framework ;
7
8
using Microsoft . Build . Utilities ;
8
9
using Uno . UI . Tasks . Helpers ;
@@ -31,10 +32,15 @@ public partial class RetargetAssets_v0
31
32
</plist>
32
33
""" ;
33
34
34
- private ITaskItem [ ] GenerateFontPartialManifest ( List < string > fontAssets )
35
+ private ITaskItem [ ] GenerateFontPartialManifest ( List < string > fontAssets , string iOSAppManifest )
35
36
{
36
37
if ( TargetPlatform == "ios" )
37
38
{
39
+ // For compatibility measures, get the fonts from the iOS app manifest
40
+ // and merge them with the generated ones, so existing apps don't lose
41
+ // explicitly specified ones.
42
+ var existingFonts = EnumerateFontsFromPList ( IosAppManifest ) ;
43
+
38
44
var outputManifestFile = Path . Combine ( IntermediateOutputPath , "FontsPartialInfo.plist" ) ;
39
45
40
46
using var writer = File . CreateText ( outputManifestFile ) ;
@@ -46,7 +52,7 @@ private ITaskItem[] GenerateFontPartialManifest(List<string> fontAssets)
46
52
writer . WriteLine ( " <key>UIAppFonts</key>" ) ;
47
53
writer . WriteLine ( " <array>" ) ;
48
54
49
- foreach ( var font in fontAssets )
55
+ foreach ( var font in fontAssets . Concat ( existingFonts ) )
50
56
{
51
57
writer . WriteLine ( " <string>" + font + "</string>" ) ;
52
58
}
@@ -63,4 +69,17 @@ private ITaskItem[] GenerateFontPartialManifest(List<string> fontAssets)
63
69
return Array . Empty < ITaskItem > ( ) ;
64
70
}
65
71
}
72
+
73
+ private string [ ] EnumerateFontsFromPList ( string iosAppManifest )
74
+ {
75
+ XmlDocument doc = new ( ) ;
76
+ doc . Load ( iosAppManifest ) ;
77
+
78
+ // Get the list of registered fonts in the info.plist
79
+ return doc
80
+ . SelectNodes ( "//key[text()='UIAppFonts']/following-sibling::array[1]/string" )
81
+ . OfType < XmlNode > ( )
82
+ . Select ( n => n . InnerText )
83
+ . ToArray ( ) ;
84
+ }
66
85
}
0 commit comments