-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add experimental feature for font list command #4886
Conversation
This comment has been minimized.
This comment has been minimized.
Found myself juggling more than once between |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful as a reviewer if the PR description contained some examples of usage so that I could give feedback on the visual representation.
I also want to ensure that the ISource implementation containing installed items is well thought through to avoid the need to have specialized COM interfaces. It doesn't even have to be a SQLite index, but if we can align the font data to the existing model we can save a lot of work exposing it.
The fun thing we could do with a custom ISource is to have the search results QI into these DWrite interfaces.
src/AppInstallerCommonCore/Fonts.cpp
Outdated
UINT32 fileCount = 0; | ||
THROW_IF_FAILED(fontFace->GetFiles(&fileCount, nullptr)); | ||
|
||
wil::com_ptr<IDWriteFontFile> fontFiles[8]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- static_assert that
sizeof(wil::com_ptr<IDWriteFontFile>) == sizeof(IDWriteFontFile*)
; means that it is a no-overhead smart pointer type and that you can use an array-like of them this way (regardless of the actual array-like type) - vector of
wil::com_ptr<IDWriteFontFile>
- resize to
fileCount
src/AppInstallerCommonCore/Fonts.cpp
Outdated
THROW_IF_FAILED(font->GetFaceNames(faceNames.addressof())); | ||
|
||
wchar_t localeNameBuffer[LOCALE_NAME_MAX_LENGTH]; | ||
const auto localeName = GetUserDefaultLocaleName(localeNameBuffer, LOCALE_NAME_MAX_LENGTH) ? localeNameBuffer : L"en-US"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have some locale functionality for choosing installers and settings around this. Prefer those methods over calling this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to calling AppInstaller::Locale::GetUserPreferredLanguages() for the default locale.
src/AppInstallerCommonCore/Fonts.cpp
Outdated
|
||
UINT32 faceNameIndex; | ||
BOOL faceNameExists; | ||
if (FAILED(faceNames->FindLocaleName(localeName, &faceNameIndex, &faceNameExists)) || !faceNameExists) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like this chooses a "best" locale to use. We have the option of extracting all of the locale names and sorting them for best fit, much like installer selection. Not saying that we should, but a comment may be warranted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment noting that we may need to have better locale selection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the way you've implemented the font families allows for Substring matching. It seems that if --family-name
is present, you're expecting an exact match, which conflicts with the --exact
argument. I presume the behavior should be the same as winget list
where it defaults to a Substring match unless the --exact
argument is specified.
|
||
void ReportInstalledFontsResult(Execution::Context& context) | ||
{ | ||
if (context.Args.Contains(Args::Type::FamilyName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will there be any provision for searching by Face Name? Not sure if it provides value or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, will come out in a later PR when I implement a searchable font source.
This comment has been minimized.
This comment has been minimized.
Once I create a fonts source and implement search functionality, I'll make this --exact argument work as expected. |
src/AppInstallerCommonCore/Fonts.cpp
Outdated
if (FAILED(localizedStringCollection->FindLocaleName(preferredLocale.c_str(), &index, &exists)) || !exists) | ||
for (const auto& locale : preferredLocales) | ||
{ | ||
if (FAILED(localizedStringCollection->FindLocaleName(locale.c_str(), &index, &exists)) || exists) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (FAILED(localizedStringCollection->FindLocaleName(locale.c_str(), &index, &exists)) || exists) | |
if (SUCCEEDED_LOG(localizedStringCollection->FindLocaleName(locale.c_str(), &index, &exists)) && exists) |
Should we exit the search early if one of the lookups fails? I think we would better off logging and continue trying to find a different one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to suggested.
src/AppInstallerCommonCore/Fonts.cpp
Outdated
@@ -10,6 +10,8 @@ namespace AppInstaller::Fonts | |||
{ | |||
namespace | |||
{ | |||
std::vector<std::wstring> preferredLocales = AppInstaller::Locale::GetUserPreferredLanguagesUTF16(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A global static is not how we should be reducing the number of calls to GetUserPreferredLanguagesUTF16
. Global statics bring along several issues, made even worse when they are not statically initialized.
A better approach would be to have the font enumeration functions actually be methods of a type. The caller then controls the lifetime of anything that the font enumeration caches, like a member field of locales.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a struct called FontCatalog
that hold all of these font enumeration methods as well as a private member field for the preferred locales.
Related to:
Changes:
font
winget font
command withlist
subcommand.winget font list --family-name "Vivaldi"
will display all of the face names for the font familyVivalidi
. At this point, this must be an exact match, but eventually this will allow partial search queries once the font index is created (separate PR).