Created
March 10, 2014 03:16
-
-
Save makotokato/9458865 to your computer and use it in GitHub Desktop.
Draw Color Glyph with DirectWrite 1.2
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment