Welcome Guest! You need to login or register to make posts.



Go to last post Go to first unread
#1 Posted : Friday, May 26, 2017 7:05:32 AM(UTC)

Rank: Advanced Member

Groups: Member
Joined: 10/12/2015(UTC)
Posts: 44

I'm having a problem loading a custom font (attached). The exact same code works with other font files, but this one in particular throws an exception...and it's the only one we have that has numbers in the font name (maybe that is the problem). Not numbers in the file name, but the name of the font is "1942 Report".

Error I get is:

"FontMissingException", "Additional information: 1942 Report"


public static byte[] TransparentText(string txt, int width, int height) {

	using (var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb, RgbColor.Transparent))
	using (var graphics = bitmap.GetAdvancedGraphics())
	using (var customFont = new CustomFontRegistry()) {
		graphics.FontRegistry = customFont;

		var font = graphics.CreateFont(customFont.Families[0], 58);
		var bounded = new BoundedText(txt, font, new System.Drawing.Rectangle(0, 0, width, height));
		bounded.Brush = new SolidBrush(RgbColor.Blue);
		bounded.Alignment = TextAlignment.Center;


		return imageToByteArray(bitmap);



3047.zip (28kb) downloaded 9 time(s).
#2 Posted : Monday, May 29, 2017 4:49:06 AM(UTC)

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,656

Thanks: 5 times
Was thanked: 75 time(s) in 73 post(s)
The Graphics.CreateFont method requires either a font PostScript name or font family and style to be specified as parameters

Here is your font information:

customFont.Fonts[0]	{Aurigma.GraphicsMill.AdvancedDrawing.FontInfo}	
		Family	"1942 report"	string
		FullName	"1942 report"	string
		PostscriptName	"1942report"	string
		Style	"1942 report"	string

The values of the PostscriptName and Family properties differ, and that's why your code doesn't work as you pass a font family where a PostScript name is required.

So you should use one of these approaches to fix the problem:

var font = graphics.CreateFont(customFont.Fonts[0].PostscriptName, 58);

var font = graphics.CreateFont(customFont.Fonts[0].Family, customFont.Fonts[0].Style, 58);

Edited by user Monday, May 29, 2017 4:51:37 AM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.