Created
March 7, 2014 07:59
-
-
Save makotokato/9407295 to your computer and use it in GitHub Desktop.
Access Color Emoji Font on Windows 8.1 with DirectWrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dwrite.h> | |
#include <dwrite_2.h> | |
#include <stdio.h> | |
#pragma comment(lib, "dwrite.lib") | |
int main() | |
{ | |
HRESULT hr; | |
IDWriteFactory* dwriteFactory; | |
hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&dwriteFactory)); | |
if (FAILED(hr)) { | |
printf("%d\n", hr); | |
return -1; | |
} | |
IDWriteFontFile* fontFiles; | |
WCHAR path[MAX_PATH]; | |
// Segoe UI Emoji | |
wcscpy(path, L"C:\\windows\\fonts\\seguiemj.ttf"); | |
hr = dwriteFactory->CreateFontFileReference(path, NULL, &fontFiles); | |
if (FAILED(hr)) { | |
printf("%d\n", hr); | |
return -1; | |
} | |
IDWriteFontFile* file[] = {fontFiles}; | |
IDWriteFontFace* fontface; | |
hr = dwriteFactory->CreateFontFace(DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, file, 0, DWRITE_FONT_SIMULATIONS_NONE, &fontface); | |
fontFiles->Release(); | |
if (FAILED(hr)) { | |
printf("%d\n", hr); | |
return -1; | |
} | |
IDWriteFontFace2* fontface2; | |
hr = fontface->QueryInterface(reinterpret_cast<IDWriteFontFace2**>(&fontface2)); | |
fontface->Release(); | |
if (FAILED(hr)) { | |
printf("%d\n", hr); | |
return -1; | |
} | |
printf("IsColorFont: %d\n", fontface2->IsColorFont()); | |
printf("GetColorPaletteCount: %d\n", fontface2->GetColorPaletteCount()); | |
printf("palette\n"); | |
DWRITE_COLOR_F palette[256]; | |
hr = fontface2->GetPaletteEntries(0, 0, fontface2->GetPaletteEntryCount(), palette); | |
if (FAILED(hr)) { | |
printf("%d\n", hr); | |
return -1; | |
} | |
for (size_t i = 0; i < fontface2->GetPaletteEntryCount(); i++) { | |
printf("%f %f %f %f\n", palette[i].r, palette[i].g, palette[i].b, palette[i].a); | |
} | |
fontface2->Release(); | |
dwriteFactory->Release(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment