private WindowsFont(IntNativeMethods.LOGFONT lf, bool createHandle)
 {
     this.fontSize = -1f;
     this.logFont = lf;
     if (this.logFont.lfFaceName == null)
     {
         this.logFont.lfFaceName = "Microsoft Sans Serif";
     }
     this.style = FontStyle.Regular;
     if (lf.lfWeight == 700)
     {
         this.style |= FontStyle.Bold;
     }
     if (lf.lfItalic == 1)
     {
         this.style |= FontStyle.Italic;
     }
     if (lf.lfUnderline == 1)
     {
         this.style |= FontStyle.Underline;
     }
     if (lf.lfStrikeOut == 1)
     {
         this.style |= FontStyle.Strikeout;
     }
     if (createHandle)
     {
         this.CreateFont();
     }
 }
示例#2
0
        public static int GetObject(HandleRef hFont, IntNativeMethods.LOGFONT lp)
        {
            int retVal = IntGetObject(hFont, System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntNativeMethods.LOGFONT)), lp);

            DbgUtil.AssertWin32(retVal != 0, "GetObject(hObj=[0x{0:X8}], [LOGFONT]) failed.", hFont.Handle);
            return(retVal);
        }
示例#3
0
        /// <summary>
        ///     Contructor to construct font from a LOGFONT structure.
        ///     Pass false in the createHandle param to create a 'compatible' font (handle-less, to be used for measuring/comparing) or
        ///     when the handle has already been created.
        /// </summary>


        private WindowsFont(IntNativeMethods.LOGFONT lf, bool createHandle)
        {
            Debug.Assert(lf != null, "lf is null");

            logFont = lf;

            if (logFont.lfFaceName == null)
            {
                logFont.lfFaceName = defaultFaceName;
            }

            style = FontStyle.Regular;
            if (lf.lfWeight == IntNativeMethods.FW_BOLD)
            {
                style |= FontStyle.Bold;
            }
            if (lf.lfItalic == 1)
            {
                style |= FontStyle.Italic;
            }
            if (lf.lfUnderline == 1)
            {
                style |= FontStyle.Underline;
            }
            if (lf.lfStrikeOut == 1)
            {
                style |= FontStyle.Strikeout;
            }

            if (createHandle)
            {
                CreateFont();
            }
        }
示例#4
0
        /// <devdoc>
        ///     Creates a WindowsFont from the handle to a native GDI font and optionally takes ownership of managing
        ///     the lifetime of the handle.
        /// </devdoc>


        public static WindowsFont FromHfont(IntPtr hFont, bool takeOwnership)
        {
            IntNativeMethods.LOGFONT lf = new IntNativeMethods.LOGFONT();
            IntUnsafeNativeMethods.GetObject(new HandleRef(null, hFont), lf);

            WindowsFont wf = new WindowsFont(lf, /*createHandle*/ false);

            wf.hFont     = hFont;
            wf.ownHandle = takeOwnership; // if true, hFont will be deleted on dispose.

            return(wf);
        }
 public WindowsFont(string faceName, float size, FontStyle style, byte charSet, WindowsFontQuality fontQuality)
 {
     this.fontSize = -1f;
     this.logFont = new IntNativeMethods.LOGFONT();
     int num = (int) Math.Ceiling((double) ((WindowsGraphicsCacheManager.MeasurementGraphics.DeviceContext.DpiY * size) / 72f));
     this.logFont.lfHeight = -num;
     this.logFont.lfFaceName = (faceName != null) ? faceName : "Microsoft Sans Serif";
     this.logFont.lfCharSet = charSet;
     this.logFont.lfOutPrecision = 4;
     this.logFont.lfQuality = (byte) fontQuality;
     this.logFont.lfWeight = ((style & FontStyle.Bold) == FontStyle.Bold) ? 700 : 400;
     this.logFont.lfItalic = ((style & FontStyle.Italic) == FontStyle.Italic) ? ((byte) 1) : ((byte) 0);
     this.logFont.lfUnderline = ((style & FontStyle.Underline) == FontStyle.Underline) ? ((byte) 1) : ((byte) 0);
     this.logFont.lfStrikeOut = ((style & FontStyle.Strikeout) == FontStyle.Strikeout) ? ((byte) 1) : ((byte) 0);
     this.style = style;
     this.CreateFont();
 }
示例#6
0
        /// <summary>
        ///     Contructor to construct font from a face name, a desired size in points and with the specified style
        ///     and character set. The screen dc is used for calculating the font em height.
        /// </summary>>


        public WindowsFont(string faceName, float size, FontStyle style, byte charSet, WindowsFontQuality fontQuality)
        {
            Debug.Assert(size > 0.0f, "size has a negative value.");
            const byte True  = 1;
            const byte False = 0;

            logFont = new IntNativeMethods.LOGFONT();

            //
            // Get the font height from the specified size.  size is in point units and height in logical
            // units (pixels when using MM_TEXT) so we need to make the conversion using the number of
            // pixels per logical inch along the screen height.
            //
            int pixelsY = (int)Math.Ceiling(WindowsGraphicsCacheManager.MeasurementGraphics.DeviceContext.DpiY * size / 72); // 1 point = 1/72 inch.;

            //
            // The lfHeight represents the font cell height (line spacing) which includes the internal
            // leading; we specify a negative size value (in pixels) for the height so the font mapper
            // provides the closest match for the character height rather than the cell height (MSDN).
            //
            logFont.lfHeight       = -pixelsY;
            logFont.lfFaceName     = faceName ?? defaultFaceName;
            logFont.lfCharSet      = charSet;
            logFont.lfOutPrecision = IntNativeMethods.OUT_TT_PRECIS;
            logFont.lfQuality      = (byte)fontQuality;
            logFont.lfWeight       = (style & FontStyle.Bold) == FontStyle.Bold ? IntNativeMethods.FW_BOLD : IntNativeMethods.FW_NORMAL;
            logFont.lfItalic       = (style & FontStyle.Italic) == FontStyle.Italic ? True : False;
            logFont.lfUnderline    = (style & FontStyle.Underline) == FontStyle.Underline ? True : False;
            logFont.lfStrikeOut    = (style & FontStyle.Strikeout) == FontStyle.Strikeout ? True : False;

            // Let the Size be recomputed to be consistent with the Height (there may be some precision loss coming from size to height).
            // this.fontSize = size;
            this.style = style;

            CreateFont();
        }
示例#7
0
 public static extern int IntGetObject(HandleRef hFont, int nSize, [In, Out] IntNativeMethods.LOGFONT lf);
        public static WindowsFont FromHfont( IntPtr hFont, bool takeOwnership )
        {
            IntNativeMethods.LOGFONT lf = new IntNativeMethods.LOGFONT();
            IntUnsafeNativeMethods.GetObject(new HandleRef(null, hFont), lf);
            
            WindowsFont wf = new WindowsFont( lf, /*createHandle*/ false );
            wf.hFont = hFont;
            wf.ownHandle = takeOwnership; // if true, hFont will be deleted on dispose.

            return wf;
        }
        private WindowsFont( IntNativeMethods.LOGFONT lf, bool createHandle )
        {
            Debug.Assert( lf != null, "lf is null" );

            this.logFont = lf;

            if (this.logFont.lfFaceName == null)
            {
                this.logFont.lfFaceName = defaultFaceName;
            }

            this.style = FontStyle.Regular;
            if (lf.lfWeight == IntNativeMethods.FW_BOLD)
            {
                this.style |= FontStyle.Bold;
            }
            if (lf.lfItalic == 1)
            {
                this.style |= FontStyle.Italic;
            }
            if (lf.lfUnderline == 1)
            {
                this.style |= FontStyle.Underline;
            }
            if (lf.lfStrikeOut == 1)
            {
                this.style |= FontStyle.Strikeout;
            }

            if( createHandle )
            {
                CreateFont();
            }
        }
示例#10
0
        public WindowsFont( string faceName, float size, FontStyle style, byte charSet, WindowsFontQuality fontQuality )
        {   
            Debug.Assert( size > 0.0f, "size has a negative value." );
            const byte True  = 1;
            const byte False = 0;
            this.logFont = new IntNativeMethods.LOGFONT();

            //
            // Get the font height from the specified size.  size is in point units and height in logical 
            // units (pixels when using MM_TEXT) so we need to make the conversion using the number of 
            // pixels per logical inch along the screen height.
            //
            int pixelsY = (int) Math.Ceiling( WindowsGraphicsCacheManager.MeasurementGraphics.DeviceContext.DpiY * size / 72); // 1 point = 1/72 inch.;

            //
            // The lfHeight represents the font cell height (line spacing) which includes the internal 
            // leading; we specify a negative size value (in pixels) for the height so the font mapper 
            // provides the closest match for the character height rather than the cell height (MSDN).
            //
            this.logFont.lfHeight       = -pixelsY;
            this.logFont.lfFaceName     = faceName != null ? faceName : defaultFaceName;
            this.logFont.lfCharSet      = charSet;
            this.logFont.lfOutPrecision = IntNativeMethods.OUT_TT_PRECIS;
            this.logFont.lfQuality      = (byte) fontQuality;
            this.logFont.lfWeight       = (style & FontStyle.Bold)      == FontStyle.Bold      ? IntNativeMethods.FW_BOLD : IntNativeMethods.FW_NORMAL;
            this.logFont.lfItalic       = (style & FontStyle.Italic)    == FontStyle.Italic    ? True : False;
            this.logFont.lfUnderline    = (style & FontStyle.Underline) == FontStyle.Underline ? True : False;
            this.logFont.lfStrikeOut    = (style & FontStyle.Strikeout) == FontStyle.Strikeout ? True : False;

            // Let the Size be recomputed to be consistent with the Height (there may be some precision loss coming from size to height).
            // this.fontSize = size;
            this.style    = style;

            CreateFont();
        }
 public static WindowsFont FromHfont(IntPtr hFont, bool takeOwnership)
 {
     IntNativeMethods.LOGFONT lp = new IntNativeMethods.LOGFONT();
     IntUnsafeNativeMethods.GetObject(new HandleRef(null, hFont), lp);
     return new WindowsFont(lp, false) { hFont = hFont, ownHandle = takeOwnership };
 }