The CPFont class allows control of the fonts used for displaying text anywhere on the screen. The primary method for getting a particular font is through one of the class methods that take a name and/or size as arguments, and return the appropriate CPFont.
System fonts
When you create a font using -systemFontOfSize
: or -boldSystemFontOfSize
:, a proxy font is created that always refers to the current system font face and size. By default the system font face/size is Arial 12px, with a fallback to sans-serif 12px. You may configure this at runtime in two ways:
- By sending [CPFont setSystemFontFace:<face>] and/or [CPFont setSystemFontSize:<size>]. Note that if you change the system font face or size during runtime, the next time any view using a system font is redrawn, it will show the new font.
- By configuring Info.plist for your application or for AppKit. You can set the font face by adding a CPSystemFontFace string item to the Info.plist, and you can set the font size by adding a CPSystemFontSize integer item to the Info.plist.
Note that in either case, you can specify a comma-delimited list of fonts as the font face. Do not quote enclose font faces that contain spaces, that is done automatically when a CSS representation of a font is requested.
The browser will use the first available font in the list you supply. CPFont always ensures that Arial and sans-serif are in the CSS representation of a font as a fallback, so there is no need to add them to the end of your font list.
nib2cib conversion
Fonts are converted by nib2cib according to the following algorithm:
- If the font family is Lucida Grande, then a system font will be created.
- If the font is Lucida Grande 13 (plain), the "default" font will be used at runtime. The default font is taken from the "font" theme attribute if one exists, otherwise from the current system font face and size.
- Lucida Grande of any size other than 13 will retain its size.
- Fonts using any family other than Lucida Grande will be used as is, including the size.
Using custom web fonts
The configurability of CPFont makes it easy to use a custom web font as the system font. For example, if you want to use the google font Asap as the system font, you would do the following:
- Add a <link> to the <head> of index-debug.html and index.html:
<link href='http://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
- Specify Asap as the system font in Info.plist by adding the following item:
<key>CPSystemFontFace</key>
<string>Asap</string>
Definition at line 2 of file CPFont.h.