0

I have a class that renders text to an image. It was working fine until I tried to use the Calibri font. Calibri is rendered without any font smoothing. After some research I determined that the cause is that Graphics.DrawString() uses GDI+, and I need to use GDI. The solution presented is to use TextRenderer.DrawText() instead. But, TextRenderer is in the System.Windows.Forms namespace, and mine is not a Windows Forms app.

Should I just reference the System.Windows.Forms.dll in my project? This class should be considered middle-tier. It doesn't care if the application is web-based, windows forms, WPF, or whatever. The output is an Image. In my specific case, I am using it on the web. And I don't like the idea of referencing System.Windows.Forms from an ASP.Net application. Several comments and answers on StackOverflow suggest that ASP.Net applications should not reference windows forms dlls.

So, is there a non-windows-forms way of rendering text via GDI? Or is this case an exception to the rule of not referencing windows forms dlls from ASP.Net?

Community
  • 1
  • 1
gilly3
  • 87,962
  • 25
  • 144
  • 176
  • 1
    Referencing System.Windows.Forms.dll is not a problem. It isn't spontaneously going to try to create desktop windows on your web server. Nothing happens until you create an instance of a class, as normal in .NET. These kind of comments fall in the "don't really know what it does, looks ugly, must be bad" category. TextRenderer is a thin wrapper around DrawTextEx(). – Hans Passant Feb 06 '14 at 20:53
  • That's what I figured. Seems like `TextRenderer` belongs in `System.Graphics`. – gilly3 Feb 06 '14 at 20:59

0 Answers0