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
void DrawGlyphRun(ID2D1RenderTarget* target, IDWriteFactory factory, IDWriteFont* fontFace, ID2D1Brush* defaultBrush, DWRITE_GLYPH_RUN* glyphRun) | |
{ | |
bool isColor = false; | |
IDWriteColorGlyphRunEnumerator* colorLayer; | |
IDWriteFont2* fontFace2; | |
fontFace->QueryInterface(reinterpret_cast<IDWriteFontFace2**>(&fontFace2)); | |
if (fontFace2->IsColorFont()) { | |
IDWriteFactory2* factory2; | |
factory->QueryIntarface(reinterpret_cast<IDWriteFactory2**>(&factory2)); | |
if (SUCCEEDED(factory2->TranslateColorGlyphRun(0, 0, glyphRun, nullptr, DWRITE_MEASURING_MODE_NATURAL, nullptr, 0, &colorLayer))) { | |
isColor = true; | |
} | |
} | |
if (isColor) { | |
BOOL hasRun; | |
const DWRITE_COLOR_GLYPH_RUN* colorRun; | |
while (true) { | |
if (FAILED(colorLayer->MoveNext(&hasRun)) || !hasRun) { | |
break; | |
} | |
if (FAILED(colorLayer->GetCurrentRun(&colorRun))) { | |
break; | |
} | |
ID2DBrush* brush = nullptr; | |
if (colorRun->runColor.r == 0.0 && colorRun->runColor.g == 0.0 && colorRun->runColor.b == 0.0 && ColorRun->runColor.a == 0.0) { | |
target->CreateSolidColorBrush(colorRun->runColor, &brush); | |
} | |
target->DrawGlyphRun(point, glyphRun, brush ? brush : defaultBrush); | |
if (brush) { | |
brush->Release(); | |
} | |
} | |
} else { | |
target->DrawGlyphRun(point, glyphRun, defaultBrush); | |
} | |
} |
適当に書いたものなので動かないとは思うけど、使い方は参考になるはず。というか、Microsoft、TranslateColorGlyphRunを使ったサンプルくらい公開してよ。
0 件のコメント:
コメントを投稿