Thursday, January 3, 2008
That was funny. To instantiate Font in .NET 2.0 you call one of many Font's constructors. Basically you provide a font family (either an object of the class FontFamily or a name of one as a string), size and FontStyle. There is a constructor that doesn't take a FontStyle, it assumes the FontStyle.Regular as default.
A FontFamily is a collection of fonts. Arial family will have Arial Regular, Arial Bold, Arial Bold Italic...
Now, in theory there might be a family with only Bold Italic. The requirement is in case there is no style the user requested, give back a font from the family in any available style.
Unfortunatelly in FontFamily object there is no property returning available members of the family, but there is a method for checking if given FontStyle is available.
FontStyle is an enumeration with the following members.
FontStyle.Regular = 0 FontStyle.Bold = 1 FontStyle.Italic = 2 FontStyle.Underline = 4 FontStyle.Strikeout = 8
A font style can be created by bitwise or-ing the values. For example Bold Italic can be defined by FontStyle.Bold | FontStyle.Italic wihich makes 3.
How to generate all possible combinations?
for i in xrange(16):
fontStyle = Enum.ToObject(FontStyle, i)
return Font(fontFamily, fontSize, fontStyle)
Integers from 0 to 15 form all valid combinations of the FontStyle. This sixteen numbers can be represented with 4 bits, 15's binary representation having them all lit (8 + 4 + 2 + 1).
- BHO.CVX Trojan
- Evil locale
- Resolver One - Beta
- Extract variable in Vim
- Distributed build
- Swap parameters script for Vim
- What happens during MessageBox.Show()?
- Beautiful Code: Resolver One
- Debugging memory leaks in IronPython apps
- Why Vim's modes frustrate newbies
- Four-monitor desktop
- Antipattern: static subject to observer map
- August 2007
- September 2007
- October 2007
- November 2007
- December 2007
- January 2008
- February 2008
- March 2008
- April 2008
- August 2008
- January 2009
- May 2009
- June 2009
- February 2010
- March 2010
- August 2010
- January 2011