Reputation: 527
With DirectWrite, I am trying to get this font named Copyduck.
On my Windows 11 (10.0.22631.2861) machine, the code I provided doesn't found the font, BUT on my Windows 10 (10.0.19045.4046) machine it founds it. Important to note, in my Windows 11 machine, in many apps that use directwrite, I can use the font without any problem. Also, I can see the font in C:\Windows\Fonts
.
Important to note. To install this fonts, I used fontbase and activate Copyduck in it. I suppose it use AddFontResource and it seems to add the font in HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Fonts
. Directwrite isn't able to query any fonts activated by fontbase which is weird, but I am able to query any "system" font.
Why is it happening and why all the applications like Word, Photoshop, Aegisub, libass are able to see the fonts installed by fontbase, but my little program isn't able to do so.
Here is my code (PS: I run it in Visual Studio 2022):
#include <iostream>
#include <dwrite_3.h>
#pragma comment(lib, "Dwrite.lib")
int main() {
IDWriteFactory3* dwrite_factory;
if (FAILED(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(dwrite_factory), reinterpret_cast<IUnknown**>(&dwrite_factory))))
return 1;
IDWriteFontSet* font_set;
if (FAILED(dwrite_factory->GetSystemFontSet(&font_set)))
return 1;
std::wcout << L"There is " << font_set->GetFontCount() << L" fonts installed." << std::endl;
DWRITE_FONT_PROPERTY_ID property_ids[] = {
DWRITE_FONT_PROPERTY_ID_WIN32_FAMILY_NAME,
DWRITE_FONT_PROPERTY_ID_FULL_NAME,
DWRITE_FONT_PROPERTY_ID_POSTSCRIPT_NAME,
};
for (int i = 0; i < sizeof property_ids / sizeof * property_ids; i++) {
DWRITE_FONT_PROPERTY property = {
property_ids[i],
L"Copyduck",
L"",
};
IDWriteFontSet* filtered_set;
HRESULT hr = font_set->GetMatchingFonts(&property, 1, &filtered_set);
if (FAILED(hr) || !filtered_set)
continue;
std::wcout << L"GetFontCount " << filtered_set->GetFontCount() << std::endl;
filtered_set->Release();
}
font_set->Release();
dwrite_factory->Release();
return 0;
}
In my Windows 11 machine I don't see the Copyduck font in the newer gui (BUT, like I said, I can see it in the older GUI at C:\Windows\Fonts
)
That's strange. I asked a user that installed windows 11 by upgrading windows 10 to 11 and he is able to use directwrite to query the font installed by fontbase.
On Windows 10, if I had an entry to HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Fonts
, I can directly query it with directwrite. But, on windows 11, if I had an entry to HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Fonts
, directwrite doesn't detect the font!. Important to note, GDI is able to detect it, so it create inconsistency between GDI and Directwrite.
At this point, I am pretty sure it is a bug in windows 11. I will try to report it to microsoft even if I don't really know how I can do it.
Upvotes: 0
Views: 161
Reputation: 139167
When you use FontBase and activate a font (file) it does two things
c:\users\simon\fontbase
).HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Fonts
:Once that is done, you can see this font in the "old" Windows UI where the font is marked with a link/shortcut overlay:
But you can't see it in the newer Windows UI:
Some programs can use it, I guess because they manually read the registry setting and load the pointed font file directly.
But DirectWrite can't read it either, probably because it doesn't like the custom folder, this may be (I guess, can't find any official doc about this) a security thing as this relatively new feature Font Settings and Fonts in the Microsoft Store allows to install fonts directly from the app store.
So, to make it work you can configure FontBase to point to a folder below the %LOCALAPPDATA%\Microsoft\Windows\Fonts
, like this:
PS: Note the folder can be a sub folder of the Fonts folder
Now once activated, DirectWrite will see it and the newer Windows UI too:
BTW, now that this feature exists, installing a font is pretty simple, you can also just change the registry and put the file in the Fonts folder by yourself, you don't need tools such as FontBase.
Otherwise, if you really want to use FontBase w/o reconfiguring it, you can also write a DirectWrite custom font file loader, read the registry and load the font "manually" (but DirectWrite won't enumerate it).
Upvotes: 1