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

Windows font_dir #37

Closed
GustavoPeredo opened this issue Nov 9, 2021 · 6 comments
Closed

Windows font_dir #37

GustavoPeredo opened this issue Nov 9, 2021 · 6 comments

Comments

@GustavoPeredo
Copy link

GustavoPeredo commented Nov 9, 2021

Currently dirs-rs returns always None for a font directory in Windows:

pub fn font_dir()       -> Option<PathBuf> { None }

However, according to this issue, ever since Windows 1809, there has been support for a user font directory.


I have written a fork of dirs-sys-rs with support for the folder here, basically it tries to find the directory %userprofile%\AppData\Local\Microsoft\Windows\Fonts, if it doesn't exist, the function returns None. Is this a good approach for a merge request?

@soc
Copy link
Collaborator

soc commented Nov 9, 2021

Hey Gustavo,

thanks for your contribution!

If Windows made these improvements this would be really great news – I'll try to read through things and try to gain a better understanding.

My first instinct would be to check whether there is a appropriate Win32 API call for it – the general approach of the library is to avoid hitting the file system for various reasons (see second point in https://github.com/dirs-dev/dirs-rs#design-goals).

So I wouldn't try to use the presence or absence of this directory as an indication for anything; I'd probably have a look at whatever the Win32 API does and think whether this is appropriate for this library.

Do you have an idea whether the winapi crate provides an appropriate binding? Otherwise I can check and maybe talk to its maintainer to add support for it, and then we can make use of that.

Cheers,

Simon

@GustavoPeredo
Copy link
Author

Thanks for your answer Simon.
I did some research and there is no win32 api to call for the user's fonts directory.

The general solution seems to be to look at the registry for the directory (matplotlib and r-lib systemfonts), could this perhaps be a fit for dirs-dev/directories?

Pro: Availability of another directory for users
Con: Doesn't make use of the Known Folder API on Windows

@soc
Copy link
Collaborator

soc commented Nov 9, 2021

Ah interesting! I didn't expect that the registry key was the "intended" way to use the folder (in general I have the impression that they want to avoid introducing public-facing registry things as much as possible) – that's why I assumed there was a Win32 API available. I'm really curious why the known folder API wasn't updated. :-/

@GustavoPeredo
Copy link
Author

If I had to guess the API hasn't been update to maintain backwards compatibility...

@soc
Copy link
Collaborator

soc commented Jan 11, 2022

Based on https://stackoverflow.com/questions/70526705/why-was-the-user-font-directory-not-added-to-the-knownfolder-api I'll (sadly) close this.

It appears that this directory is neither required nor sufficient to do anything userfont-wise.

Feel free to reopen if you have more ideas how to tackle this.

@soc soc closed this as completed Jan 11, 2022
@GustavoPeredo
Copy link
Author

Thanks for looking into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants