| 
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 13 time(s). | 
	
    | 
             | 
            
         | 
    |  | 
        
        
        
         
		   
        
            
            
	
    | 
Rank: Advanced Member
 Groups: Guest
Joined: 7/28/2003(UTC)
 Posts: 1,660
 
 Thanks: 5 timesWas 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
 | 
	
    | 
             | 
            
         | 
    |  | 
        
        
        
    
    
        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.