Skip to content

Support reading fonts from files - #14783

Merged
mattleibow merged 2 commits into
mainfrom
dev/fonts-unpackaged
Apr 26, 2023
Merged

mattleibow merged 2 commits into
mainfrom
dev/fonts-unpackaged

Conversation

@mattleibow

@mattleibow mattleibow commented Apr 26, 2023 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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

@mandel-macaque mandel-macaque left a comment

Copy link
Copy Markdown
Contributor

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('\\', '/')}";

@mandel-macaque mandel-macaque Apr 26, 2023 •

Copy link
Copy Markdown
Contributor

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