我用PdfSharp创建PDF,有些电脑上面没有我用到的字体,我使用网上的方法加载自定义字体后,如果对该字体做了操作就会出问题。下面是我的代码:
System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
string ttfPath = string.Format("{0}/{1}.TTF", Application.streamingAssetsPath, "Deng");//文本域设置一样的时候替换
pfc.AddFontFile(ttfPath);//字体文件的路径
font = new XFont(pfc.Families[0], 15, XFontStyle.Regular, options);
UnityEngine.Debug.Log(font.Name);
gfx.DrawString("你好,世界(3)!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
//font = null;//本来我以为这里可以释放资源,结果U3D大概过10S后崩溃
//font = new XFont("等线", 15, XFontStyle.Regular, options);//直接替换字体U3D大概过10S后也崩溃
//pfc.Dispose();此外我还尝试使用释放资源的方法,也是崩溃
上面 的崩溃都不是立即崩溃,而是会等待几秒后崩溃。