internal GdiFontMetrics(GdiDeviceContent dc, GdiFont currentFont) { if (dc.Handle == IntPtr.Zero) { throw new ArgumentNullException("dc", "Handle to device context cannot be null"); } if (dc.GetCurrentObject(GdiDcObject.Font) == IntPtr.Zero) { throw new ArgumentException("dc", "No font selected into supplied device context"); } this.dc = dc; this.currentFont = currentFont; // FontFileReader requires the font facename because the font may exist in // a TrueType collection. StringBuilder builder = new StringBuilder(255); LibWrapper.GetTextFace(dc.Handle, builder.Capacity, builder); faceName = builder.ToString(); ranges = new GdiUnicodeRanges(dc); reader = new FontFileReader(new MemoryStream(GetFontData()), faceName); converter = new PdfUnitConverter(EmSquare); // After we have cached the font data, we can safely delete the resource currentFont.Dispose(); }
/// <summary> /// Creates a <see cref="GdiFontMetrics"/> object from <b>baseFontName</b> /// </summary> private void ObtainFontMetrics() { dc = new GdiDeviceContent(); GdiFont font = GdiFont.CreateDesignFont( properties.FaceName, properties.IsBold, properties.IsItalic, dc); unicodeRanges = new GdiUnicodeRanges(dc); metrics = font.GetMetrics(dc); }