Example #1
0
        FontStyle GetFontStyleForFamily( IFontFamily family )
        {
            FontStyle style = 0;

            if ( family.IsStyleAvailable( FontStyle.Regular ) )
                style = FontStyle.Regular;

            foreach ( var ctl in _fontStyleControls )
            {
                if ( ctl.Control.Checked && family.IsStyleAvailable( style & ctl.Style ) )
                    style |= ctl.Style;
            }

            // If we still haven't arrived at a valid style, then let's just set any style this font will support.
            if ( !family.IsStyleAvailable( style ) )
            {
                int numFontStyleBits = 5;
                for ( int i=0; i < (int)Math.Pow( 2, numFontStyleBits ); i++ )
                {
                    style = (FontStyle)i;
                    if ( family.IsStyleAvailable( style ) )
                        break;
                }
            }

            return style;
        }