Skip to content

How to create custom font and use? #353

Answered by qwerty1874
qwerty1874 asked this question in Q&A
Discussion options

You must be logged in to vote

When I read msdn again, I found that I should use the created font collection, not system font collection. I used to think CreateTextFormat could search all font collection, only need to AddFontFile.

Correct about this:

var pWriteFactory = DWrite.DWriteCreateFactory<IDWriteFactory5>();

var pFontSetBuilder = pWriteFactory.CreateFontSetBuilder();

var pFontFile = pWriteFactory.CreateFontFileReference(fontPath);

pFontSetBuilder.AddFontFile(pFontFile);

var pFontSet = pFontSetBuilder.CreateFontSet();

var pFontCollection = pWriteFactory.CreateFontCollectionFromFontSet(pFontSet);

var textFormat = pWriteFactory.CreateTextFormat(fontName
    , pFontCollection
    , FontWeight.Normal
    , Fon…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by qwerty1874
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant