Kevmeister68
Kevmeister68

Reputation: 91

DirectWrite lists regular, Oblique, Bold, Bold Oblique versions of Microsoft Sans Serif, but they all point to the same TTF file

So I have used the DirectWrite APIs to query the available fonts in my system. One of the fonts is Microsoft Sans Serif. DirectWrite returns me four faces for this font: Regular, Oblique, Bold and Bold Oblique, but when I obtain the Font File Path they are all pointing to the same TTF file.

I am not a font export, but I know multiple fonts can reside in a TTC file where the font is identified by a font index or similar.

I am embedding the font into a PDF document and so when I need the Bold/Oblique/Bold Oblique versions of the font I simply end up with the regular version (since they all point to the same file).

If I use Microsoft Word as a test and specify some text and select Bold or Italic versions of my text using Microsoft Sans Serif, the text changes face as one would expect.

I understand there is a concept of logical versus physical fonts, so one possibility is that Microsoft Word (or DirectWrite or GDI etc) may have in fact done some kind of substitution of a different physical font to give me a "logical" bold or italic version of Microsoft Sans Serif.

Or this is something different at play, which may have to do with DirectWrite and the font itself.

Can anyone explain what is causing the situation I am seeing?

Upvotes: 0

Views: 138

Answers (3)

Peter Constable
Peter Constable

Reputation: 3650

The Microsoft Sans Serif font is contained in the file MICROSS.TTF. It is not a font collection file (TTC). Microsoft Sans Serif has only one style Regular.

DWrite can simulate bold and oblique styles. In Word, if you select Microsoft Sans Serif and then apply bold or italic formatting, you'll get simulated bold or oblique variants of Microsoft Sans Serif.

If you have an IDWriteFont objection, you can call IDWriteFont::GetSimulations() to determine if that font is a simulated bold, oblique or bold oblique.

Upvotes: 1

jeremie bergeron
jeremie bergeron

Reputation: 527

If it give you an TTC file, then, like you said, a font can contain face.

So, you need to get the right index in this file to get your font face. Use IDWriteFontFace::GetIndex to get it

Upvotes: 0

bunglehead
bunglehead

Reputation: 1179

DirectWrite will provide you with multiple font faces for the same font file, if, like you said it's a TTC collection file, if it's a variable font with several instances, or if it's a simple single font ttf/otf that does not provide bold/italic variants on its own. In the latter case simulated faces will be added. Check what IDWriteFontFace::GetSimulations() returns. In newer API versions there are options to use different family grouping model, but for original versions, it works like I described - when you don't have an italic face, it will be simulated as oblique, same for missing bold, and bold italic - that will use simulated bold and simulated bold oblique respectively.

Upvotes: 0

Related Questions