public void Dispose() { FontServices.DeleteObject(_hFont); _graphics.ReleaseHdc(_hDC); _hFont = _hDC = IntPtr.Zero; }
public FontToHDCBinder(Graphics g, Font font) { _graphics = g; _hDC = g.GetHdc(); _hFont = font.ToHfont(); _hPrevFont = FontServices.SelectObject(_hDC, _hFont); }
public static void TextOut(Graphics graphics, Font font, Color color, int x, int y, string str) { using (FontToHDCBinder binder = FontServices.BindFontToHDC(graphics, font)) { UInt32 prevColor = GetTextColor(binder.HDC); SetTextColor(binder.HDC, ToColorRef(color)); int prevBkMode = SetBkMode(binder.HDC, TRANSPARENT); TextOut(binder.HDC, x, y, str, str.Length); SetBkMode(binder.HDC, prevBkMode); SetTextColor(binder.HDC, prevColor); } }
int CountKerningsWithFirstChar( FontServices.KerningPair[] kerningPairs, Char ch ) { int total = 0; for ( int i=0; i < kerningPairs.Length; i++ ) { if ( kerningPairs[i].wFirst == (Int16)ch ) ++total; } return total; }
// // NOTE: This is currently unused. This would seem to be the right way to do it, // but the results that we get back don't match what you get if you call Graphics.DrawString. // Instead, see CalculateSpacingInfo. // public CharacterKerningInfo( CharacterInfo character, FontServices.KerningPair[] kerningPairs, CharacterInfo[] validCharacters ) { this.Character = character; // Add a kerning pair for anything that we're the first character in (and has a valid second character). for ( int i=0; i < kerningPairs.Length; i++ ) { if ( kerningPairs[i].wFirst == (short)this.Character.Character ) { CharacterInfo second = FindCharacter( (Char)kerningPairs[i].wSecond, validCharacters ); // Find the second kerning character in validCharacters. if ( second != null ) { KerningPair pair = new KerningPair() { SecondCharacter = second, KernAmount = kerningPairs[i].iKernAmount }; this.Kernings.Add( pair ); } } } }