Exemple #1
0
            public void Dispose()
            {
                FontServices.DeleteObject(_hFont);
                _graphics.ReleaseHdc(_hDC);

                _hFont = _hDC = IntPtr.Zero;
            }
Exemple #2
0
 public FontToHDCBinder(Graphics g, Font font)
 {
     _graphics  = g;
     _hDC       = g.GetHdc();
     _hFont     = font.ToHfont();
     _hPrevFont = FontServices.SelectObject(_hDC, _hFont);
 }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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;
        }
Exemple #5
0
            //
            // 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 );
                        }
                    }
                }
            }