0

I want to use DirectWrite to stretch a font vertically or horizontally by x percent.

I'm using IDWriteTextFormat::CreateTextFormat and IDWriteFactory::CreateTextLayout and DrawTextLayout.

The DWRITE_FONT_STRETCH enumeration passed into CreateTextFormat is too coarse and doesn't give me enough control. For example, instead of "semi-condensed" I want exactly 71% vertically condensed.

So far I can't figure out how to do this without direct2d scaling transformations or using GDI. I'd rather avoid using GDI's LOGFONT because it will make my application much more complicated.

Peter
  • 1
  • 1

1 Answers1

0

Font stretch specified with DWRITE_FONT_STRETCH is meant to be used for matching process only. Treat it as an input argument for matching logic - you specify desired stretch (and other parameters) and DirectWrite picks "closest" font. Strictly speaking different stretch values do not imply any different visual appearance, it's a metadata that font designer specified. Now what you're asking sounds more like variable fonts, when variable font supports stretch axis you can set it to any value in allowed range and get different rendering results.

Of course you can transform outlines manually, scale along coordinate axis if you wish. But that has its own limitations.

bunglehead
  • 1,104
  • 1
  • 14
  • 22
  • What interface do I use to access variable fonts? Can I do it with Direct2d and/or Direwrite? I realize that not all fonts will support stretching, but that doesn't matter. – Peter Feb 28 '18 at 00:32
  • You'll need latest Windows SDK to access those, for example 10.0.16299.0 has them. Look for IDWriteFactory6 and interfaces it brought in. For some reason MSDN was never updated to provide documentation for those. I think it's implement in Windows 10 only, starting with last major update, some time in Autumn 2017. – bunglehead Feb 28 '18 at 07:05