public FontWidths(Document doc, IntPtr hdc, WinGdi.OUTLINETEXTMETRIC otm) : base(doc) { _widths = new uint[otm.TextMetrics.LastChar - otm.TextMetrics.FirstChar + 1]; WinGdi.ABC[] abcWidths = new WinGdi.ABC[otm.TextMetrics.LastChar - otm.TextMetrics.FirstChar + 1]; bool b = WinGdi.GetCharABCWidths(hdc, otm.TextMetrics.FirstChar, otm.TextMetrics.LastChar, ref abcWidths[0]); for (int i = 0; i < abcWidths.Length; i++) { _widths[i] = (uint)(abcWidths[i].abcA + (int)abcWidths[i].abcB + abcWidths[i].abcC); } }
public Font(Document doc, string fontName, System.Drawing.Font winFont) : base(doc) { _fontName = fontName; //TBD - I have no idea why 720 seems to work. I don't understand the relationship // between windows font coordinates and PDF glyph coordinates. It seems like this // should be 1000, but that doesn't work. System.Drawing.Font f = new System.Drawing.Font(winFont.FontFamily, 720, winFont.Style, GraphicsUnit.Point); IntPtr hDC = WinGdi.GetDC(IntPtr.Zero); //Screen DC IntPtr hObjOld = WinGdi.SelectObject(hDC, f.ToHfont()); uint cbSize = WinGdi.GetOutlineTextMetrics(hDC, 0, IntPtr.Zero); if (cbSize == 0) { throw new Exception(); } StringBuilder sb = new StringBuilder(50); WinGdi.GetTextFace(hDC, 50, sb); IntPtr buffer = Marshal.AllocHGlobal((int)cbSize); try { if (WinGdi.GetOutlineTextMetrics(hDC, cbSize, buffer) != 0) { _otm = (WinGdi.OUTLINETEXTMETRIC)Marshal.PtrToStructure(buffer, typeof(WinGdi.OUTLINETEXTMETRIC)); _faceName = Marshal.PtrToStringAnsi((IntPtr)((long)buffer + _otm.pFaceName)); _faceName = _faceName.Replace(" ", "-"); _otm.EMSquare = (uint)(_otm.EMSquare / winFont.SizeInPoints); } } finally { Marshal.FreeHGlobal(buffer); } _fw = new FontWidths(doc, hDC, _otm); _fd = new FontDescriptor(doc, _faceName, _otm); WinGdi.SelectObject(hDC, hObjOld); WinGdi.ReleaseDC(IntPtr.Zero, hDC); }
public FontDescriptor(Document doc, string fontName, WinGdi.OUTLINETEXTMETRIC otm) : base(doc) { _fontName = fontName; _otm = otm; }