Any ideas why one of recent Windows updates causes issues with GraphicsPath.AddString()
and some fonts but only for specific characters? How to fix that?
Example font is Thin Pencil Handwriting (it's public domain, so you can try for yourself). It works fine if you use Graphics.DrawString()
with it. It also works fine if you try to use GraphicsPath.AddString()
with it to write Lorem ipsum
, but will fail if you try to use C
character (capital c
) or 5
digit.
It worked perfectly fine just few weeks ago and after recent updates it fails miserably with the infamous and virtually undebuggable Generic GDI+ exception.
Example code:
string textOK = "Lorem ipsum";
string broken = "C"; // Yes, only capital letter 'c'!
FontStyle style = FontStyle.Regular;
Bitmap b = new Bitmap(200, 200, PixelFormat.Format32bppPArgb)
using (Graphics g = Graphics.FromImage(b))
{
g.Clear(Color.White);
g.SmoothingMode = SmoothingMode.HighQuality;
using (StringFormat sf = new StringFormat())
{
RectangleF rect = new RectangleF(0, 0, 200, 200);
float size = 8;
using (Font f = new System.Drawing.Font("Thin Pencil Handwriting", size, style))
{
// Works perfectly fine
g.DrawString(textOK, f, Brushes.Black, rect, sf);
g.DrawString(broken, f, Brushes.Black, rect, sf);
}
using (GraphicsPath path = new GraphicsPath())
{
FontFamily family = new FontFamily("Thin Pencil Handwriting");
// This works fine
path.AddString(textOK, family, (int)style, size, rect, sf);
// This causes Generic GDI+ exception!
path.AddString(broken, family, (int)style, size, rect, sf);
g.FillPath(Brushes.Black, path);
}
}
}
I'm using C# but I don't thing it's particularly C# related. Older machines without recent updates works fine, but I can't tell people not to install system updates :( I've also spotted two other fonts that cause similar issues - both with GraphicsPath.AddString()
method.