0

I have a LOGFONT structure that I convert to an IDWriteFont using CreateFontFromLOGFONT():

IDWriteFont* dWriteFont = nullptr;
if (FAILED(dWriteGdiInterop->CreateFontFromLOGFONT(&logFont, &dWriteFont))) return;

If the LOGFONT describes a Tw Cen MT Condensed font, I would like to have the DirectWrite's font have the DWRITE_FONT_STRETCH_CONDENSED attribute assigned.

The LOGFONT has width '0', whatever stretch I choose (condensend, wide, etcetera). It seems the stretch can only be deducted from the font name, and DirectWrite's method fails to do so. Is this a bug?

How can I create a DirectWrite font with a certain stretch, based on a LOGFONT structure?

Jaap Scheper
  • 67
  • 11

1 Answers1

0

I don't think it's necessarily a bug, for example dwrite_3.h has comment for this method saying that only some of fields are considered: lfFaceName, lfCharSet, lfWeight, lfItalic. No lfWidth here.

You can still try to ask for condensed one going through family:

  • call GetFontFamily() on font returned from CreateFontFromLOGFONT();
  • use GetFirstMatchingFont() on this family with parameters you want.

That should work if Tw Cen MT family has in fact condensed variant, from DirectWrite point of view.

bunglehead
  • 1,104
  • 1
  • 14
  • 22