// Returns whether or not target was changed internal static bool FontToIFont(Font source, UnsafeNativeMethods.IFont target) { bool changed = false; // we need to go through all the pain of the diff here because // it looks like setting them all has different results based on the // order and each individual IFont implementor... // string fontName = target.GetName(); if (!source.Name.Equals(fontName)) { target.SetName(source.Name); changed = true; } // [....], Review: this always seems to come back as // the point size * 10000 (HIMETRIC?), regardless // or ratio or mapping mode, and despite what // the documentation says... // // Either figure out what's going on here or // do the process that the windows forms FONT object does here // or, worse case, just create another Font object // from the handle, but that's pretty heavy... // float fontSize = (float)target.GetSize() / 10000; // size must be in points float winformsSize = source.SizeInPoints; if (winformsSize != fontSize) { target.SetSize((long)(winformsSize * 10000)); changed = true; } NativeMethods.LOGFONT logfont = new NativeMethods.LOGFONT(); IntSecurity.ObjectFromWin32Handle.Assert(); try { source.ToLogFont(logfont); } finally { CodeAccessPermission.RevertAssert(); } short fontWeight = target.GetWeight(); if (fontWeight != logfont.lfWeight) { target.SetWeight((short)logfont.lfWeight); changed = true; } bool fontBold = target.GetBold(); if (fontBold != (logfont.lfWeight >= 700)) { target.SetBold(logfont.lfWeight >= 700); changed = true; } bool fontItalic = target.GetItalic(); if (fontItalic != (0 != logfont.lfItalic)) { target.SetItalic(0 != logfont.lfItalic); changed = true; } bool fontUnderline = target.GetUnderline(); if (fontUnderline != (0 != logfont.lfUnderline)) { target.SetUnderline(0 != logfont.lfUnderline); changed = true; } bool fontStrike = target.GetStrikethrough(); if (fontStrike != (0 != logfont.lfStrikeOut)) { target.SetStrikethrough(0 != logfont.lfStrikeOut); changed = true; } short fontCharset = target.GetCharset(); if (fontCharset != logfont.lfCharSet) { target.SetCharset(logfont.lfCharSet); changed = true; } return changed; }