TLDNR: It is 2017. How can I set font weight when using System.Drawing.createfont
Longer version: Under GDI32 I would create a device context, fill in a LOGFONT structure including a weight value like 400,500,600 etc, and have the font created. The font mapper would run an algorithm to match my request to the best available matching font on the system and return a handle to it.
Under system.drawing the font constructor has 13 overloads but none take an obvious weight. There is a FontFamily param but the only weight effect this has is to add a binary 'bold' option which is not the same as setting the desired font weight.
Why does this matter: Fonts come in families and weight variants. Weight is liek thickness or darkness of the letters. In typesetting, if I need a Semi-bold font then I really must get a semi-bold version of the font assuming it is installed on the machine the code runs on.
What have I done so far? A lot of web-based research via google, SO and MSDN.And looked at all the suggested questions as I wrote this. As yet I have not found a way forward and I am at that point where you know you are asking the wrong questions and looking for someone to point me back in the right direction.
It was possible under GDI - what is the system.drawing equiv.
EDIT: This question came up from a current project which is actually using directWrite (dw), not system.drawing. But one of the requirements is to know that a requested font is available. With a GDI32-mindset there seemed no obvious solution in dw hence we turned to system.drawing, and the question came up.
After some more research triggered by initial response comments to the question we had a revealing moment. This was that the way fonts are requested in dw is entirely different to GDI32. Dw uses the font family / weight / width / slope font model for font matching. It also makes font family variant enumeration easy.
We are coming from a legacy use case where our data includes the GDI32 font name. This is usually the family name, but various font foundaries use this in different ways, you can observe this if you have a font internals tool like TypeTool - one foundary might call their bold italic version 'MyFont Bold Italic' whilst another calls theirs 'MyFont' and leaves the bold italic specifiers to be set in the other font parameters.
Meanwhile Windows (at least Windows 10) seems to have updated the way it maps fonts on install, recognises the crappy names and presents then as a family. MS Office seems not to have joined this approach (witness the crappy names in PowerPoint font selection list, for example), but you can see it if you browse Windows/fonts folder.
Now, this is all very nice but if you just take a legacy GDI32 font name and try to instantiate a font in dw it will fail. The solution appears to be pre-processing the GDI32 font name to chop out the weight, width and slope enum words. Once you have that done then dw will match your font.
This approach seems to be quite viable in initial testing, plus we can easily return some ugly default such as 'Courier' when a font is truly not present, plus we can cheaply get a list of the font family members so could if we wanted select another member if the desired one is not present (I know we lean toward re-inventing the font mapper if we go down that road).
Conclusion: dw font naming is different to GDI32. The more exotic font names you might have used with GDI32 are not guaranteed to work with dw, and need massaging into a dw format, but it IS do-able.
I will update later the result of the above approach.