mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 13:07:02 +00:00
Fixed CPFontTest, removed unused RegExp from CPFont
This commit is contained in:
+1
-2
@@ -32,8 +32,7 @@ var _CPFonts = {},
|
||||
_CPFontDefaultSystemFontFace = @"Arial, sans-serif",
|
||||
_CPFontDefaultSystemFontSize = 12,
|
||||
_CPFontFallbackFaces = _CPFontDefaultSystemFontFace.split(", "),
|
||||
_CPFontStripRegExp = new RegExp("(^\\s*[\"']?|[\"']?\\s*$)", "g"),
|
||||
_CPFontStripPropertiesRegExp = new RegExp("^(italic |bold )*\\d+px ");
|
||||
_CPFontStripRegExp = new RegExp("(^\\s*[\"']?|[\"']?\\s*$)", "g");
|
||||
|
||||
|
||||
#define _CPFontNormalizedNames(aName) _CPFontNormalizedNameArray(aName).join(", ")
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
CPFont _systemFont;
|
||||
CPFont _boldSystemFont;
|
||||
|
||||
|
||||
CPFont _customFont;
|
||||
CPFont _boldCustomFont;
|
||||
}
|
||||
@@ -13,29 +13,33 @@
|
||||
{
|
||||
_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"];
|
||||
var font = _CPFontConcatNameWithFallback([CPFont systemFontFace]);
|
||||
|
||||
[self assert:[_systemFont cssString] equals:@"15px " + font];
|
||||
}
|
||||
|
||||
- (void)testBoldSystemFontCSSString
|
||||
{
|
||||
[self assert:[_boldSystemFont cssString] equals:@"bold 15px Arial, sans-serif"];
|
||||
var font = _CPFontConcatNameWithFallback([CPFont systemFontFace]);
|
||||
|
||||
[self assert:[_boldSystemFont cssString] equals:@"bold 15px " + font];
|
||||
}
|
||||
|
||||
- (void)testCustomFontCSSString
|
||||
{
|
||||
[self assert:[_customFont cssString] equals:@"30px \"Marker Felt\", \"Lucida Grande\", \"Helvetica\", Arial, sans-serif"];
|
||||
[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"];
|
||||
[self assert:[_boldCustomFont cssString] equals:@"bold 30px Helvetica, Arial, sans-serif"];
|
||||
}
|
||||
|
||||
- (void)testIsEqual
|
||||
@@ -48,3 +52,39 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
var _CPFontStripRegExp = new RegExp("(^\\s*[\"']?|[\"']?\\s*$)", "g");
|
||||
|
||||
var _CPFontConcatNameWithFallback = function(aName)
|
||||
{
|
||||
var names = _CPFontNormalizedNameArray(aName),
|
||||
fallbackFaces = ["Arial", "sans-serif"];
|
||||
|
||||
// Remove the fallback names used in the names passed in
|
||||
for (var i = 0; i < names.length; ++i)
|
||||
{
|
||||
for (var j = 0; j < fallbackFaces.length; ++j)
|
||||
{
|
||||
if (names[i].toLowerCase() === fallbackFaces[j].toLowerCase())
|
||||
{
|
||||
fallbackFaces.splice(j, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (names[i].indexOf(" ") > 0)
|
||||
names[i] = '"' + names[i] + '"';
|
||||
}
|
||||
|
||||
return names.concat(fallbackFaces).join(", ");
|
||||
};
|
||||
|
||||
var _CPFontNormalizedNameArray = function(aName)
|
||||
{
|
||||
var names = aName.split(",");
|
||||
|
||||
for (var i = 0; i < names.length; ++i)
|
||||
names[i] = names[i].replace(_CPFontStripRegExp, "");
|
||||
|
||||
return names;
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -338,6 +338,7 @@
|
||||
</object>
|
||||
<string key="NSFrame">{{1, 17}, {453, 117}}</string>
|
||||
<reference key="NSSuperview" ref="34816847"/>
|
||||
<reference key="NSNextKeyView" ref="164099841"/>
|
||||
<reference key="NSDocView" ref="164099841"/>
|
||||
<reference key="NSBGColor" ref="181840125"/>
|
||||
<int key="NScvFlags">4</int>
|
||||
@@ -370,6 +371,7 @@
|
||||
</object>
|
||||
<string key="NSFrame">{{1, 0}, {453, 17}}</string>
|
||||
<reference key="NSSuperview" ref="34816847"/>
|
||||
<reference key="NSNextKeyView" ref="62911344"/>
|
||||
<reference key="NSDocView" ref="62911344"/>
|
||||
<reference key="NSBGColor" ref="181840125"/>
|
||||
<int key="NScvFlags">4</int>
|
||||
@@ -378,6 +380,7 @@
|
||||
</object>
|
||||
<string key="NSFrame">{{32, 124}, {455, 135}}</string>
|
||||
<reference key="NSSuperview" ref="439893737"/>
|
||||
<reference key="NSNextKeyView" ref="941606776"/>
|
||||
<int key="NSsFlags">530</int>
|
||||
<reference key="NSVScroller" ref="927749950"/>
|
||||
<reference key="NSHScroller" ref="69583515"/>
|
||||
@@ -1071,7 +1074,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
</object>
|
||||
<int key="NSTvFlags">0</int>
|
||||
<bool key="NSAllowTruncatedLabels">YES</bool>
|
||||
<bool key="NSDrawsBackground">YES</bool>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="88189651"/>
|
||||
@@ -1112,7 +1114,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
<reference key="NSFont" ref="613390050"/>
|
||||
<int key="NSTvFlags">0</int>
|
||||
<bool key="NSAllowTruncatedLabels">YES</bool>
|
||||
<bool key="NSDrawsBackground">YES</bool>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="338115759"/>
|
||||
|
||||
Reference in New Issue
Block a user