private static string GetScaledPath(string path, HashSet <string> assets, ResolutionScale?scaleOverride) { if (!string.IsNullOrEmpty(path)) { var directory = Path.GetDirectoryName(path); var filename = Path.GetFileNameWithoutExtension(path); var extension = Path.GetExtension(path); var resolutionScale = scaleOverride == null ? (int)DisplayInformation.GetForCurrentView().ResolutionScale : (int)scaleOverride; for (var i = KnownScales.Length - 1; i >= 0; i--) { var probeScale = KnownScales[i]; if (resolutionScale >= probeScale) { var filePath = Path.Combine(directory, $"{filename}.scale-{probeScale}{extension}"); if (assets.Contains(filePath)) { return(AssetsPathBuilder.BuildAssetUri(filePath)); } } } return(AssetsPathBuilder.BuildAssetUri(path)); } return(path); }
private static async Task <HashSet <string> > GetAssets() { var assetsUri = AssetsPathBuilder.BuildAssetUri("uno-assets.txt"); var assets = await WebAssemblyRuntime.InvokeAsync($"fetch('{assetsUri}').then(r => r.text())"); return(new HashSet <string>(Regex.Split(assets, "\r\n|\r|\n"))); }
private protected override bool TryOpenSourceSync(int?targetWidth, int?targetHeight, out ImageData image) { if (WebUri is { } webUri) { image = default; var hasFileScheme = webUri.IsAbsoluteUri && webUri.Scheme == "file"; // Local files are assumed as coming from the remote server var uri = hasFileScheme switch { true => new Uri(webUri.PathAndQuery.TrimStart('/'), UriKind.Relative), _ => webUri }; if (uri.IsAbsoluteUri) { if (uri.Scheme == "http" || uri.Scheme == "https") { image = new ImageData { Kind = ImageDataKind.Url, Value = uri.AbsoluteUri, Source = this }; } // TODO: Implement ms-appdata } else { var path = AssetsPathBuilder.BuildAssetUri(uri.OriginalString); image = new ImageData { Kind = ImageDataKind.Url, Value = path, Source = this }; } return(image.Kind != default); } image = default; return(false); }
private static string GetScaledPath(string path, HashSet <string> assets, ResolutionScale?scaleOverride) { if (!string.IsNullOrEmpty(path)) { var directory = Path.GetDirectoryName(path); var filename = Path.GetFileNameWithoutExtension(path); var extension = Path.GetExtension(path); var resolutionScale = scaleOverride == null ? (int)DisplayInformation.GetForCurrentView().ResolutionScale : (int)scaleOverride; // On Windows, the minimum scale is 100%, however, on Wasm, we can have lower scales. // This condition is to allow Wasm to use the .scale-100 image when the scale is < 100% if (resolutionScale < 100) { resolutionScale = 100; } for (var i = KnownScales.Length - 1; i >= 0; i--) { var probeScale = KnownScales[i]; if (resolutionScale >= probeScale) { var filePath = Path.Combine(directory, $"{filename}.scale-{probeScale}{extension}"); if (assets.Contains(filePath)) { return(AssetsPathBuilder.BuildAssetUri(filePath)); } } } return(AssetsPathBuilder.BuildAssetUri(path)); } return(path); }