Graphics IGraphicsProvider.GetGraphics() { if (_measurer == null) { _measurer = SafeGraphics.CreateReferenceGraphics(); } return(_measurer); }
private static Image CreateMetafile(MemoryStream ms, SizeF size) { using (Graphics gTemp = SafeGraphics.CreateReferenceGraphics()) { var mf = new Metafile(ms, gTemp.GetHdc(), new RectangleF(Point.Empty, size), MetafileFrameUnit.Pixel, EmfType.EmfPlusDual); gTemp.ReleaseHdc(); return(mf); } }
private static byte[] GetFontBytes(string fontName, System.Drawing.FontStyle fontStyle, int table, int size = 0) { using (Font font = new Font(fontName, 80, fontStyle)) using (Graphics gTemp = SafeGraphics.CreateReferenceGraphics()) { IntPtr hFont = font.ToHfont(); IntPtr hdc = gTemp.GetHdc(); IntPtr oldHFont = SelectObject(hdc, hFont); try { var fontDataSize = size == 0 ? GetFontDataSize(hdc, table, 0, IntPtr.Zero, 0) : (uint)size; if (fontDataSize == 0 || fontDataSize == 0xFFFFFFFF) { return(null); } var fontData = new byte[fontDataSize]; var result = GetFontData(hdc, table, 0, fontData, (int)fontDataSize); if (result == 0xFFFFFFFF) { return(null); } return(fontData); } catch { return(null); } finally { SelectObject(hdc, oldHFont); DeleteObject(hFont); gTemp.ReleaseHdc(hdc); } } }