How do I get a font filename (*.ttf) from a font name? (C++/Windows)

Asked 5 months ago, Updated 5 months ago, 24 views

I would like to get the font filename (*.ttf) from the font name.
Example: Times New Roman→times.ttf

(The font name here is the name that can be obtained by the LOGFONT structure lfFaceName.)

in the registry, referring to the following: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts
You are attempting to browse to the .


Generally speaking, English fonts match lfFaceName with the font name in the registry, but for Japanese fonts, lfFaceName is in Japanese (for example, Mario) and the font name used in the registry is in English (for example, Meiryo).

In order to resolve the issue, I would appreciate it if you could tell me how to obtain the English font name from the Japanese font name that lfFaceName can provide.

The original purpose is not to obtain an English font name, but to obtain a font file name (*.ttf), so if you can achieve it in a completely different way, please let me know how to do it.

c++ windows font

2022-09-30 11:58

1 Answers

I don't know how to get a file name, so I'll answer how to get an English name.

GDI+'s FontFamily.GetFamilyName allows you to obtain names in other languages.There is a provisional argument for specifying the language ID, so if it is in English, you can pass MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US).

# include <windows.h>
# include <gdiplus.h>

using namespace std;

int main()

    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);

    Gdiplus::FontFamily f(L "Mario");

    WCHAR name [LF_FACESIZE] {};

    // Gdiplus::GdiplusShutdown(gdiplusToken);

Running this program produces the output Meiryo.

However, there is also one problem with this method.Even if you specify L "Microsoft YaHei" (Microsoft YaHei Simplified Chinese), it will not become Microsoft YaHei.In that way, it doesn't seem to work outside of the language you are using.I didn't know how to get around here.

2022-09-30 11:58

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.