protected override void OnLoaded() { base.OnLoaded(); if (_window == null || _window.LoadFonts == false) { return; } IList <string> fontUrls = this.GetFontUrls(); if (fontUrls == null || fontUrls.Count == 0) { return; } //TODO: Trying a background run... Task.Factory.StartNew(() => { SvgWindow ownedWindow = _window.CreateOwnedWindow(); ownedWindow.LoadFonts = false; for (int i = 0; i < fontUrls.Count; i++) { var fontUrl = fontUrls[i]; try { // remove any hash (won't work for local files) int hashStart = fontUrl.IndexOf("#", StringComparison.OrdinalIgnoreCase); if (hashStart > -1) { fontUrl = fontUrl.Substring(0, hashStart); } Uri fileUrl = this.ResolveUri(fontUrl); if (fileUrl == null || fileUrl.IsAbsoluteUri == false) { continue; } string scheme = fileUrl.Scheme; if (string.Equals(scheme, "file", StringComparison.OrdinalIgnoreCase)) { this.LoadLocalFont(fileUrl.LocalPath, ownedWindow); } else { //TODO } } catch (Exception ex) { Trace.TraceError(ex.ToString()); //Ignore the exception } } }); }
protected override void OnLoaded() { base.OnLoaded(); if (_window == null || _window.LoadFonts == false) { return; } IList <Tuple <string, SvgFontFaceElement> > fontUrls = this.GetFontUrls(); if (fontUrls == null || fontUrls.Count == 0) { return; } _isFontsLoaded = false; //TODO: Trying a background run... var loadTask = Task.Factory.StartNew(() => { SvgWindow ownedWindow = _window.CreateOwnedWindow(); ownedWindow.LoadFonts = false; for (int i = 0; i < fontUrls.Count; i++) { var fontUrl = fontUrls[i].Item1; var fontFace = fontUrls[i].Item2; try { // remove any hash (won't work for local files) int hashStart = fontUrl.IndexOf("#", StringComparison.OrdinalIgnoreCase); if (hashStart > -1) { fontUrl = fontUrl.Substring(0, hashStart); } Uri fileUrl = this.ResolveUri(fontUrl); if (fileUrl == null || fileUrl.IsAbsoluteUri == false) { continue; } string scheme = fileUrl.Scheme; if (string.Equals(scheme, "file", StringComparison.OrdinalIgnoreCase)) { this.LoadLocalFont(fileUrl.LocalPath, ownedWindow, fontFace); } else { throw new NotSupportedException("Loading fonts from a remote source is not supported."); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); //Ignore the exception } } _isFontsLoaded = true; }); _window.AddTask("SvgDocument", loadTask); }