Windowsで日本語フォント名から英語フォント名を取得する方法

GDI+の機能を使用する。

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

#pragma comment(lib, "gdiplus.lib")

int main(int ac, char **av)
{
    if (ac > 1) {
        Gdiplus::GdiplusStartupInput gdiplusStartupInput;
        ULONG_PTR gdiplusToken;
        Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
        WCHAR name[100];
        MultiByteToWideChar(CP_ACP, 0, av[1], strlen(av[1]), name, LF_FACESIZE);
        Gdiplus::FontFamily f(name);
        int r = f.GetFamilyName(name, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
        if (r == 0) {
            char tmp[100];
            WideCharToMultiByte(CP_ACP, 0, name, wcslen(name), tmp, sizeof(tmp), 0, 0);
            puts(tmp);
        }
    }
}

出典:http://ja.stackoverflow.com/questions/17741/

カテゴリー: 備忘録   パーマリンク

コメントを残す

メールアドレスが公開されることはありません。

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA(画像認証)

上の画像の最初と最後を除いた3桁の数字を入力して、送信ボタンを押してください。