This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

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

Rank: Advanced Member

Groups: Guest
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"

Code:

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()) {
                
		customFont.Add(@"C:\Users\blind\Desktop\3047.ttf");                
		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;

		graphics.DrawText(bounded);

		return imageToByteArray(bitmap);

	}

}

3047.zip (28kb) downloaded 10 time(s).

Fedor  
#2 Posted : Monday, May 29, 2017 4:49:06 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 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:

Code:
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:

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

Code:
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
Guest
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.