CPFont now supports multiple font families. Closes #255.

This commit is contained in:
luddep
2010-01-08 18:05:33 +01:00
parent b675adbbb0
commit 34a6389a92
2 changed files with 49 additions and 5 deletions
+8 -5
View File
@@ -20,10 +20,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
var _CPFonts = {};
_CPFontSystemFontFace = @"Arial";
var _CPFonts = {},
_CPFontSystemFontFace = @"Arial, sans-serif",
_CPWrapRegExp = new RegExp("\\s*,\\s*", "g");
#define _CPCachedFont(aName, aSize, isBold) _CPFonts[(isBold ? @"bold " : @"") + ROUND(aSize) + @"px '" + aName + @"'"]
#define _CPCreateCSSString(aName, aSize, isBold) (isBold ? @"bold " : @"") + ROUND(aSize) + @"px " + ((aName === _CPFontSystemFontFace) ? aName : (@"\"" + aName.replace(_CPWrapRegExp, '", "') + @"\", " + _CPFontSystemFontFace))
#define _CPCachedFont(aName, aSize, isBold) _CPFonts[_CPCreateCSSString(aName, aSize, isBold)]
/*!
@ingroup appkit
@@ -95,7 +98,7 @@ var _CPFonts = {};
_size = aSize;
_isBold = isBold;
_cssString = (_isBold ? @"bold " : @"") + ROUND(aSize) + @"px '" + aName + @"'";
_cssString = _CPCreateCSSString(_name, _size, _isBold);
_CPFonts[_cssString] = self;
}
@@ -158,4 +161,4 @@ var CPFontNameKey = @"CPFontNameKey",
[aCoder encodeBool:_isBold forKey:CPFontIsBoldKey];
}
@end
@end
+41
View File
@@ -0,0 +1,41 @@
@import <AppKit/AppKit.j>
@implementation CPFontTest : OJTestCase
{
CPFont _systemFont;
CPFont _boldSystemFont;
CPFont _customFont;
CPFont _boldCustomFont;
}
- (void)setUp
{
_systemFont = [CPFont systemFontOfSize:15];
_boldSystemFont = [CPFont boldSystemFontOfSize:15];
_customFont = [CPFont fontWithName:@"Marker Felt, Lucida Grande, Helvetica" size:30];
_boldCustomFont = [CPFont boldFontWithName:@"Helvetica" size:30];
}
- (void)testSystemFontCSSString
{
[self assert:[_systemFont cssString] equals:@"15px Arial, sans-serif"];
}
- (void)testBoldSystemFontCSSString
{
[self assert:[_boldSystemFont cssString] equals:@"bold 15px Arial, sans-serif"];
}
- (void)testCustomFontCSSString
{
[self assert:[_customFont cssString] equals:@"30px \"Marker Felt\", \"Lucida Grande\", \"Helvetica\", Arial, sans-serif"];
}
- (void)testBoldCustomFontCSSString
{
[self assert:[_boldCustomFont cssString] equals:@"bold 30px \"Helvetica\", Arial, sans-serif"];
}
@end