个人学习笔记存放地
修改字体的方法
上一篇 /
下一篇 2008-03-04 15:30:29
/ 个人分类:MAC
不很完善,没有错误处理
- (NSFont*) changeUsrFont:(NSFont*)usrFont
sFontName:(NSString*) fontName
bBold:(BOOL) bold
bItalic:(BOOL) italic
size:(double) dFontSize
{
NSFontManager* FM = [NSFontManager sharedFontManager];
dFontSize = (dFontSize < 1.0) ? 1.0 : dFontSize;
NSFontTraitMask s = 0;
if (italic)
{
s |= NSItalicFontMask;
}
else
{
s |= NSUnitalicFontMask;
}
if (bold)
{
s |= NSBoldFontMask;
}
else
{
s |= NSUnboldFontMask;
}
if (!usrFont)
{
usrFont = [FM fontWithFamily:fontName traits:s weight:5 size:dFontSize];
if (!usrFont) // this is bad; the wrong font name ends up in the font popups - FIXME please!
{
/* Oops! We don't have that font here.
* first try "Times New Roman", which should be sensible, and should
* be there unless the user fidled with the installation
*/
NSLog (@"Unable to find font \"%s\".", fontName);
usrFont = [[NSFontManager sharedFontManager] fontWithFamily:@"Times" traits:s weight:5 size:dFontSize];
}
}
else
{
usrFont = [FM convertFont:usrFont toFamily:fontName];
usrFont = [FM convertFont:usrFont toHaveTrait:s];
usrFont = [FM convertFont:usrFont toSize:dFontSize];
}
return usrFont;
}
导入论坛
收藏
分享给好友
管理
举报
TAG:
字体
dFontSize
BOOL
NSFont
double