Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reading fonts from files #14783

Merged
merged 2 commits into from
Apr 26, 2023
Merged

Support reading fonts from files #14783

merged 2 commits into from
Apr 26, 2023

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Apr 26, 2023

Description of Change

This PR contains the maui changes to allow loading font files in unpackaged apps.

This will require a Win2D update after this issue is fixed: https://dev.azure.com/microsoft/OS/_workitems/edit/43890883

This can be merged today without the Win2D changes as the code for packaged is unchanged. Unpackaged will still fail to work, and magically start working with the new version.

Issues Fixed

Fixes #9104

@mattleibow mattleibow marked this pull request as ready for review April 26, 2023 15:08
Comment on lines +154 to +156
var path = fontUri.AbsolutePath.TrimStart('/');
if (FileSystemUtils.TryGetAppPackageFileUri(path, out var uri))
fontUri = new Uri(uri, UriKind.RelativeOrAbsolute);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real change for unpackaged, we determine the full path to the font and use that. Packaged still uses the same ms-appx://. Technically the full path also works in packaged, but no need to change what works.

@Eilon Eilon added the area-fonts Custom fonts and Font related API's label Apr 26, 2023
@mattleibow mattleibow enabled auto-merge (squash) April 26, 2023 19:09
Copy link
Member

@mandel-macaque mandel-macaque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the bcl to get the full uri of a local path rather than write my own logic.

if (AppInfoUtils.IsPackagedApp)
uri = $"ms-appx:///{filename.Replace('\\', '/')}";
else
uri = $"file:///{path.Replace('\\', '/')}";
Copy link
Member

@mandel-macaque mandel-macaque Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be handled by the bcl in a much nicer way:

var uri = new Uri("c:\\foo");
var converted = uri.AbsoluteUri;

Example:

var r = new Uri ("C:\\foo\\bar")                                                                                                                                                                r.AbsoluteUri                                                                                                                                                                "file:///C:/foo/bar"                                                                                                                                                                 

No need to worry about corner cases etc

@mattleibow mattleibow merged commit 55091d4 into main Apr 26, 2023
@mattleibow mattleibow deleted the dev/fonts-unpackaged branch April 26, 2023 23:02
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.4.8333 Look for this fix in 8.0.0-preview.4.8333! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-fonts Custom fonts and Font related API's fixed-in-8.0.0-preview.4.8333 Look for this fix in 8.0.0-preview.4.8333!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Label:[WinUI] FontFamily is not recognized in Unpackaged application.
4 participants