CPFontManager convertFont:toFace:.

This commit is contained in:
Alexander Ljungberg committed 2012-07-16 03:11:21 +01:00
1 parent 7f1b396ce8
commit 6a67243460
2 files changed
+26

No files matched your search

+14
View File
@@ -189,6 +189,20 @@ var CPSharedFontManager = nil,
return aFont;
}
- (CPFont)convertFont:(CPFont)aFont toFace:(CPString)aTypeface
{
if (!aFont)
return nil;
var shouldBeBold = [aFont isBold],
shouldBeItalic = [aFont isItalic],
shouldBeSize = [aFont size];
aFont = [CPFont _fontWithName:aTypeface size:shouldBeSize bold:shouldBeBold italic:shouldBeItalic] || aFont;
return aFont;
}
- (@action)addFontTrait:(id)sender
{
_activeChange = [CPDictionary dictionaryWithObject:[sender tag] forKey:@"addTraits"];
+12
View File
@@ -108,6 +108,18 @@
[self assert:12.0 equals:[convertedFontB size] message:@"maintain size fontB with CPUnitalicFontMask"];
}
- (void)testConvertFont_toFace_
{
fontB = [CPFont boldFontWithName:@"Helvetica" size:12.0 italic:YES];
convertedFontB = [[CPFontManager sharedFontManager] convertFont:fontB toFace:@"Arial"];
[self assertTrue:[convertedFontB isBold] message:@"maintain bold fontB"];
[self assertTrue:[convertedFontB isItalic] message:@"maintain italic fontB"];
[self assert:12.0 equals:[convertedFontB size] message:@"maintain size fontB"];
[self assert:@"Arial" equals:[convertedFontB familyName] message:@"change face fontB"];
}
- (@action)changeFont:(id)sender
{
convertedFontA = [sender convertFont:fontA];