Skip to content

Commit

Permalink
8305667: Some fonts installed in user directory are not detected on W…
Browse files Browse the repository at this point in the history
…indows

Reviewed-by: avu, prr
  • Loading branch information
YaaZ authored and Alexey Ushakov committed Jun 29, 2023
1 parent 690d626 commit f842ec4
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/java.desktop/windows/native/libfontmanager/fontpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <windows.h>
#include <strsafe.h>
#include <stdio.h>
#include <malloc.h>

#include <jni.h>
#include <jni_util.h>
Expand Down Expand Up @@ -516,15 +517,9 @@ static void populateFontFileNameFromRegistryKey(HKEY regKey,
GdiFontMapInfo *fmi,
jobject fontToFileMap)
{
#define MAX_BUFFER (FILENAME_MAX+1)
const wchar_t wname[MAX_BUFFER];
const char data[MAX_BUFFER];

DWORD type;
LONG ret;
HKEY hkeyFonts;
DWORD dwNameSize;
DWORD dwDataValueSize;
DWORD nval;
DWORD dwNumValues, dwMaxValueNameLen, dwMaxValueDataLen;

Expand All @@ -539,16 +534,17 @@ static void populateFontFileNameFromRegistryKey(HKEY regKey,
&dwNumValues, &dwMaxValueNameLen,
&dwMaxValueDataLen, NULL, NULL);

if (ret != ERROR_SUCCESS ||
dwMaxValueNameLen >= MAX_BUFFER ||
dwMaxValueDataLen >= MAX_BUFFER) {
if (ret != ERROR_SUCCESS) {
RegCloseKey(hkeyFonts);
return;
}
dwMaxValueNameLen++; /* Account for NULL-terminator */
wchar_t *wname = (wchar_t*)malloc(dwMaxValueNameLen * sizeof(wchar_t));
wchar_t *data = (wchar_t*)malloc(dwMaxValueDataLen);
for (nval = 0; nval < dwNumValues; nval++ ) {
dwNameSize = MAX_BUFFER;
dwDataValueSize = MAX_BUFFER;
ret = RegEnumValueW(hkeyFonts, nval, (LPWSTR)wname, &dwNameSize,
DWORD dwNameSize = dwMaxValueNameLen;
DWORD dwDataValueSize = dwMaxValueDataLen;
ret = RegEnumValueW(hkeyFonts, nval, wname, &dwNameSize,
NULL, &type, (LPBYTE)data, &dwDataValueSize);

if (ret != ERROR_SUCCESS) {
Expand All @@ -558,20 +554,22 @@ static void populateFontFileNameFromRegistryKey(HKEY regKey,
continue;
}

if (!RegistryToBaseTTNameW((LPWSTR)wname) ) {
if (!RegistryToBaseTTNameW(wname) ) {
/* If the filename ends with ".ttf" or ".otf" also accept it.
* Not expecting to need to do this for .ttc files.
* Also note this code is not mirrored in the "A" (win9x) path.
*/
LPWSTR dot = wcsrchr((LPWSTR)data, L'.');
LPWSTR dot = wcsrchr(data, L'.');
if (dot == NULL || ((wcsicmp(dot, L".ttf") != 0)
&& (wcsicmp(dot, L".otf") != 0))) {
continue; /* not a TT font... */
}
}
registerFontW(fmi, fontToFileMap, (LPWSTR)wname, (LPWSTR)data);
registerFontW(fmi, fontToFileMap, wname, data);
}

free(wname);
free(data);
RegCloseKey(hkeyFonts);
}

Expand Down

1 comment on commit f842ec4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.