開発環境 |
Microsoft Visual Studio Community 2017 |
実行環境 |
Windows 10 Home (64bit) |
プロジェクトの種類 |
Visual C++/空のプロジェクト |
プロジェクト名 |
dw_glyphcount |
dw_glyphcount.cpp
// Unicode文字セット
#pragma comment(lib, "dwrite")
#include <dwrite.h>
#include <stdio.h>
template <class T> inline void SafeRelease(T **ppT)
{
if (*ppT) {
(*ppT)->Release();
*ppT = NULL;
}
}
int wmain()
{
HRESULT hr;
IDWriteFactory* pDWriteFactory = NULL;
hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&pDWriteFactory));
IDWriteFontCollection* pFontCollection = NULL;
hr = pDWriteFactory->GetSystemFontCollection(&pFontCollection);
int familyCount = pFontCollection->GetFontFamilyCount();
// code point
const int cp_begin = 0;
const int cp_end = 0x10ffff;
static UINT8 cp_count[0x110000];
for (int i = 0; i < familyCount; i++) {
IDWriteFontFamily* pFontFamily = NULL;
hr = pFontCollection->GetFontFamily(i, &pFontFamily);
IDWriteLocalizedStrings* pFamilyNames = NULL;
hr = pFontFamily->GetFamilyNames(&pFamilyNames);
WCHAR name[32];
hr = pFamilyNames->GetString(0, name, _countof(name));
IDWriteFont* pFont = NULL;
hr = pFontFamily->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STYLE_NORMAL, &pFont);
int count = 0;
for (int cp = cp_begin; cp <= cp_end; cp++) {
BOOL exists;
hr = pFont->HasCharacter(cp, &exists);
if (exists) {
cp_count[cp]++;
count++;
}
}
wprintf(L"%u\t\"%s\"\t%d\n", i, name, count);
SafeRelease(&pFont);
SafeRelease(&pFamilyNames);
SafeRelease(&pFontFamily);
}
int count = 0;
int start = -1;
for (int cp = cp_begin; cp <= cp_end; cp++) {
if (cp_count[cp]) {
count++;
if (start == -1) {
start = cp;
}
}
else {
if (start != -1) {
wprintf(L"U+%04X\tU+%04X\t%d\n", start, cp - 1, cp - start);
start = -1;
}
}
}
if (start != -1) {
wprintf(L"U+%04X\tU+%04X\t%d\n", start, cp_end, cp_end + 1 - start);
}
wprintf(L"(%d)\n", count);
SafeRelease(&pFontCollection);
SafeRelease(&pDWriteFactory);
return 0;
}
最終更新:2019年01月28日 21:20