/// <devdoc> /// Selects the specified object into the dc. If the specified object is the same as the one currently selected /// in the dc, the object is not set and a null value is returned. /// </devdoc> public IntPtr SelectFont(WindowsFont font) { // Fonts are one of the most expensive objects to select in an hdc and in many cases we are passed a Font that is the // same as the one already selected in the dc so to avoid a perf hit we get the hdc font's log font and compare it // with the one passed in before selecting it in the hdc. // Also, we avoid performing GDI operations that if done on an enhanced metafile DC would add an entry to it, hence // reducing the size of the metafile. if (font.Equals(this.Font)) { return(IntPtr.Zero); } IntPtr result = SelectObject(font.Hfont, GdiObjectType.Font); WindowsFont previousFont = selectedFont; selectedFont = font; hCurrentFont = font.Hfont; // the measurement DC always leaves fonts selected for pref reasons. // in this case, we need to diposse the font since the original // creator didn't fully dispose. if (previousFont != null) { #if DEBUG //Disabling this assert until DevDiv Bugs 95968 gets fixed //Debug.Assert(previousFont.Hfont != IntPtr.Zero, "A font has been disposed before it was unselected from the DC. This will leak a GDI handle on Win9x! Call ResetFont()"); #endif if (MeasurementDCInfo.IsMeasurementDC(this)) { previousFont.Dispose(); } } #if OPTIMIZED_MEASUREMENTDC // once we've changed the font, update the last used font. if (MeasurementDCInfo.IsMeasurementDC(this)) { if (result != IntPtr.Zero) { MeasurementDCInfo.LastUsedFont = font; } else { // there was an error selecting the Font into the DC, we dont know anything about it. MeasurementDCInfo.Reset(); } } #endif return(result); }
/// <devdoc> /// Selects the specified object into the dc. If the specified object is the same as the one currently selected /// in the dc, the object is not set and a null value is returned. /// </devdoc> public IntPtr SelectFont( WindowsFont font ) { // Fonts are one of the most expensive objects to select in an hdc and in many cases we are passed a Font that is the // same as the one already selected in the dc so to avoid a perf hit we get the hdc font's log font and compare it // with the one passed in before selecting it in the hdc. // Also, we avoid performing GDI operations that if done on an enhanced metafile DC would add an entry to it, hence // reducing the size of the metafile. if( font.Equals( this.Font )) { return IntPtr.Zero; } IntPtr result = SelectObject( font.Hfont, GdiObjectType.Font); WindowsFont previousFont = selectedFont; selectedFont = font; hCurrentFont = font.Hfont; // the measurement DC always leaves fonts selected for pref reasons. // in this case, we need to diposse the font since the original // creator didn't fully dispose. if (previousFont != null) { #if DEBUG //Disabling this assert until DevDiv Bugs 95968 gets fixed //Debug.Assert(previousFont.Hfont != IntPtr.Zero, "A font has been disposed before it was unselected from the DC. This will leak a GDI handle on Win9x! Call ResetFont()"); #endif if (MeasurementDCInfo.IsMeasurementDC(this)) { previousFont.Dispose(); } } #if OPTIMIZED_MEASUREMENTDC // once we've changed the font, update the last used font. if (MeasurementDCInfo.IsMeasurementDC(this)) { if (result != IntPtr.Zero) { MeasurementDCInfo.LastUsedFont = font; } else { // there was an error selecting the Font into the DC, we dont know anything about it. MeasurementDCInfo.Reset(); } } #endif return result; }