title: PrivateFontCollection with gdi+ sometimes uses the wrong FontStyle in WIndows 8 or newer
body: <p>If you have a Font which you've created from a PrivateFontCollection and try to draw strings with it using GDI+ it will sometimes use the wrong FontStyle.</p>
  
  <p>I've observed this both with Fonts loaded into a PrivateFontCollection from memory and fonts loaded into PrivateFontCollection from files.</p>
  
  <p>In my following example I'm loading fonts from file. I have them all in a folder called Fonts. if we would load them like below.</p>
  
  <pre><code>    private void loadFontsIntoPrivateCollection()
      {
          _privateFontCollection = new PrivateFontCollection();
          _families = new Dictionary&lt;string, FontFamily&gt;();
  
          var files = Directory.GetFiles("Fonts");
          foreach (var file in files)
              _privateFontCollection.AddFontFile(file);
  
          foreach (var fontFamily in _privateFontCollection.Families)
          {
              _families.Add(fontFamily.Name, fontFamily);
              comboBox1.Items.Add(fontFamily.Name);
          }
  
          comboBox1.Text = "Californian FB";
      }
  </code></pre>
  
  <p>and then try to draw a string OnPaint using the follow code</p>
  
  <pre><code>    private void panelTextArea_Paint(object sender, PaintEventArgs e)
      {
          var familyToUse = _families[comboBox1.Text];
          var fontToUse = new Font(familyToUse, 28, _styleToUse, GraphicsUnit.World);
          e.Graphics.DrawString(textBox1.Text, fontToUse, Brushes.Black, panelTextArea.ClientRectangle);
      }
  </code></pre>
  
  <p>Then the string in most cases would be drawn the font corresponding to the FontStyle.Regular. I've noticed if you take care to load the Regular font first then the FontFamily will fudge any FontStyle other then FontStyle.Regular. regardless of if you've loaded them into the PrivateFontCollection or not.</p>
  
  <p>Here are some of the Fonts I've seen this behaviour in.</p>
  
  <ul>
  <li>Yu Gothic</li>
  <li>Californian FB</li>
  <li>Tw Cen MT</li>
  <li>Gill Sans MT</li>
  <li>Berlin Sans FB</li>
  <li>BrowalliaUPC</li>
  <li>Traditional Arabic</li>
  </ul>
  
  <p>I see this behaviour when doing Graphics.DrawString() and AddString on a graphicsPath. Using TextRenderer.DrawText() will draw the font correctly.</p>
  
  <p>You should be able to recreate this behaviour easily in Windows 8 or 10 just using their sample code for PrivateFontCollection <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms533820(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/desktop/ms533820(v=vs.85).aspx</a></p>
  
  <p>From my correspondance with Microsoft on this Behaviour they believe this is an issue with gdi+.</p>