C++ - DirectWrite: Load font from file at runtime
<p>I'm trying to load a font from a file at runtime and display it with DirectWrite. The following code should initialize a IDWriteTextFormat object with that font:</p>

<pre><code>hr = pDWriteFactory-&gt;CreateTextFormat(
            L"Font Family",    // Font family name
            NULL,              // Font collection (NULL sets it to use the system font collection)
                               // Somehow, a custom font collection should be used here, but I don't know how to do that
            DWRITE_FONT_WEIGHT_REGULAR,
            DWRITE_FONT_STYLE_NORMAL,
            DWRITE_FONT_STRETCH_NORMAL,
            16.0f,
            L"en-us",
            &amp;pTextFormat       // IDWriteTextFormat object
        );
</code></pre>

<p>It works perfectly with system fonts but I don't know how to load a custom font file. I would appreciate any examples on how to achieve that.</p>

<p>What I tried so far:<br>
&bull; I read <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ee264312%28v=vs.85%29.aspx" rel="nofollow noreferrer">this article</a> and <a href="https://stackoverflow.com/questions/21814876/trying-to-use-a-custom-font-file-using-directx-what-is-the-collection-key">this question on Stackoverflow</a> but I don't see where one should pass the file path of the font file (therefore, I completely failed to implement any of the code provided on those two pages)<br>
&bull; I also read <a href="http://www.codeproject.com/Articles/42041/How-to-Use-a-Font-Without-Installing-it" rel="nofollow noreferrer">this article</a> but if I'm right, it has nothing to do with DirectWrite (?) (I tried to implement the AddFontResourceEx-method, but to no avail)<br>
&bull; Finally, the answer to <a href="https://stackoverflow.com/questions/31112857/use-specified-font-with-directx-11">this question</a> suggested using ResourceFontContext::CreateFontCollection could solve the problem but after reading <a href="https://msdn.microsoft.com/de-de/library/windows/desktop/dd941710(v=vs.85).aspx" rel="nofollow noreferrer">this page</a> (it's in German but the screenshot is in English) I believe that it can only be used with fonts embedded as resources (which is not an option in my case)</p>