0

I am using Direct2D for some graphics, I have gotten it to draw text with DirectDraw (using the DrawText function on the ID2D1RenderTarget) but for some reason it will not draw with the font I want. When I create a text format for the font I want I do not get any errors. I am compiling with the Multibyte option set.

Font loading code:

std::wstring unicode(name, name + strlen(name));
        HRESULT r = g_writeFactory->CreateTextFormat(unicode.c_str(), NULL, DWRITE_FONT_WEIGHT_NORMAL,
            DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, (float)size, L"en-us", &g_fonts[i]);
        g_fonts[i]->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
        g_fonts[i]->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);

        if (FAILED(r))
        {
            dgSetLastError(dgERROR_CREATIONFAILED);
            return -1;
        }

        return i;

Text drawing:

std::wstring unicode(text, text + strlen(text));
D2D1_RECT_F r = D2D1::RectF(x, y, x + width, y + height);
int len = unicode.size();

if (g_isRenderToTexture)
    g_textureTarget->DrawText(unicode.c_str(), len, g_fonts[fontId], &r, g_solidBrush);
else
    g_bufferTarget->DrawText(unicode.c_str(), len, g_fonts[fontId], &r, g_solidBrush);
Captain Picard
  • 119
  • 4
  • 12

1 Answers1

0

I can't say why Tahoma would yield Arial, given the snippet of code I can see, but Terminal is an old bitmap font only supported by GDI. That font file format is not supported by GDI+/DWrite/WPF/XAML, only OpenType with TrueType glyf table, OpenType with CFF table, or TrueType collections (as of Windows 7..10). Try "Segoe UI" instead.

Dwayne Robinson
  • 2,034
  • 1
  • 24
  • 39