Quote:error:- System.Runtime.InteropServices.SEHException: 'External component has thrown an exception
private float MeasureString(string fontName, float fontSize, string text) { const float offSet = -20f; var fontFamily = GetFontFamily(fontName); var font = new Font(fontFamily, fontSize, FontStyle.Regular, GraphicsUnit.Millimeter); var bitmap = new Bitmap(1, 1); bitmap.SetResolution(96.0f, 96.0f); using(var graphic = Graphics.FromImage(bitmap)) { graphic.PageUnit = GraphicsUnit.Millimeter; var size = graphic.MeasureString(text, font, new PointF(0, 0), new StringFormat(StringFormatFlags.FitBlackBox | StringFormatFlags.DirectionRightToLeft)); return size.Width + offSet; } }
private FontFamily GetPrivateFontFamily(string fontName) { PrivateFontCollection privateFonts = new PrivateFontCollection(); var directoryPath = _fontFamilySetting.Value.DirectoryPath; if (!string.IsNullOrEmpty(directoryPath) && Directory.Exists(directoryPath)) { foreach (string file in Directory.EnumerateFiles(_fontFamilySetting.Value.DirectoryPath)) { privateFonts.AddFontFile(file); } return privateFonts.Families.First(f => f.Name == fontName); } return null; }
using(var graphic = Graphics.FromImage(bitmap))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)