webfontloader 1.0.30 → 1.0.31
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/webfontloader.rb +1 -1
- data/src/google/fontapiparser.js +70 -31
- data/src-test/google/fontapiparsertest.js +14 -2
- data/webfontloader.gemspec +2 -2
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
v1.0.31 (September 11, 2012)
|
2
|
+
* Improvements to Google's module to recognize more variation descriptor formats (such as 100italic and 200n).
|
3
|
+
|
1
4
|
v1.0.30 (August 17, 2012)
|
2
5
|
* Added support for detecting the Windows Phone platform in UserAgentParser, which supports web fonts at version 8 and above.
|
3
6
|
* Changes to make the global namespace of the library easier to configure when used in 3rd-party projects. (Thanks cbosco!)
|
data/lib/webfontloader.rb
CHANGED
data/src/google/fontapiparser.js
CHANGED
@@ -9,20 +9,6 @@ webfont.FontApiParser = function(fontFamilies) {
|
|
9
9
|
this.fvd_ = new webfont.FontVariationDescription();
|
10
10
|
};
|
11
11
|
|
12
|
-
webfont.FontApiParser.VARIATIONS = {
|
13
|
-
'ultralight': 'n2',
|
14
|
-
'light': 'n3',
|
15
|
-
'regular': 'n4',
|
16
|
-
'bold': 'n7',
|
17
|
-
'italic': 'i4',
|
18
|
-
'bolditalic': 'i7',
|
19
|
-
'ul': 'n2',
|
20
|
-
'l': 'n3',
|
21
|
-
'r': 'n4',
|
22
|
-
'b': 'n7',
|
23
|
-
'i': 'i4',
|
24
|
-
'bi': 'i7'
|
25
|
-
};
|
26
12
|
|
27
13
|
webfont.FontApiParser.INT_FONTS = {
|
28
14
|
'latin': webfont.FontWatchRunner.DEFAULT_TEST_STRING,
|
@@ -32,6 +18,44 @@ webfont.FontApiParser.INT_FONTS = {
|
|
32
18
|
'Hanuman': 'កខគ' // For backward compatibility
|
33
19
|
};
|
34
20
|
|
21
|
+
webfont.FontApiParser.WEIGHTS = {
|
22
|
+
'thin': '1',
|
23
|
+
'extralight': '2',
|
24
|
+
'extra-light': '2',
|
25
|
+
'ultralight': '2',
|
26
|
+
'ultra-light': '2',
|
27
|
+
'light': '3',
|
28
|
+
'regular': '4',
|
29
|
+
'book': '4',
|
30
|
+
'medium': '5',
|
31
|
+
'semi-bold': '6',
|
32
|
+
'semibold': '6',
|
33
|
+
'demi-bold': '6',
|
34
|
+
'demibold': '6',
|
35
|
+
'bold': '7',
|
36
|
+
'extra-bold': '8',
|
37
|
+
'extrabold': '8',
|
38
|
+
'ultra-bold': '8',
|
39
|
+
'ultrabold': '8',
|
40
|
+
'black': '9',
|
41
|
+
'heavy': '9',
|
42
|
+
'l': '3',
|
43
|
+
'r': '4',
|
44
|
+
'b': '7'
|
45
|
+
};
|
46
|
+
|
47
|
+
webfont.FontApiParser.STYLES = {
|
48
|
+
'i': 'i',
|
49
|
+
'italic': 'i',
|
50
|
+
'n': 'n',
|
51
|
+
'normal': 'n'
|
52
|
+
};
|
53
|
+
|
54
|
+
webfont.FontApiParser.VARIATION_MATCH =
|
55
|
+
new RegExp("^(thin|(?:(?:extra|ultra)-?)?light|regular|book|medium|" +
|
56
|
+
"(?:(?:semi|demi|extra|ultra)-?)?bold|black|heavy|l|r|b|[1-9]00)?(n|i" +
|
57
|
+
"|normal|italic)?$");
|
58
|
+
|
35
59
|
webfont.FontApiParser.prototype.parse = function() {
|
36
60
|
var length = this.fontFamilies_.length;
|
37
61
|
|
@@ -71,29 +95,44 @@ webfont.FontApiParser.prototype.parse = function() {
|
|
71
95
|
};
|
72
96
|
|
73
97
|
webfont.FontApiParser.prototype.generateFontVariationDescription_ = function(variation) {
|
74
|
-
if (!variation.match(/^[\w
|
98
|
+
if (!variation.match(/^[\w]+$/)) {
|
99
|
+
return '';
|
100
|
+
}
|
101
|
+
var normalizedVariation = variation.toLowerCase();
|
102
|
+
var groups = webfont.FontApiParser.VARIATION_MATCH.exec(normalizedVariation);
|
103
|
+
if (groups == null) {
|
75
104
|
return '';
|
76
105
|
}
|
106
|
+
var styleMatch = this.normalizeStyle_(groups[2]);
|
107
|
+
var weightMatch = this.normalizeWeight_(groups[1]);
|
108
|
+
var css = this.fvd_.expand([styleMatch, weightMatch].join(''));
|
109
|
+
return css ? this.fvd_.compact(css) : null;
|
110
|
+
};
|
111
|
+
|
112
|
+
|
113
|
+
webfont.FontApiParser.prototype.normalizeStyle_ = function(parsedStyle) {
|
114
|
+
if (parsedStyle == null) {
|
115
|
+
return 'n';
|
116
|
+
}
|
117
|
+
return webfont.FontApiParser.STYLES[parsedStyle];
|
118
|
+
};
|
77
119
|
|
78
|
-
|
79
|
-
|
80
|
-
if (
|
81
|
-
return
|
82
|
-
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
var s = styleMatch ? styleMatch : 'n';
|
87
|
-
var w = numericMatch ? numericMatch.substr(0, 1) : '4';
|
88
|
-
var css = this.fvd_.expand([s, w].join(''));
|
89
|
-
if (css) {
|
90
|
-
return this.fvd_.compact(css);
|
91
|
-
} else {
|
92
|
-
return null;
|
93
|
-
}
|
120
|
+
|
121
|
+
webfont.FontApiParser.prototype.normalizeWeight_ = function(parsedWeight) {
|
122
|
+
if (parsedWeight == null) {
|
123
|
+
return '4';
|
124
|
+
}
|
125
|
+
var weight = webfont.FontApiParser.WEIGHTS[parsedWeight];
|
126
|
+
if (weight) {
|
127
|
+
return weight;
|
94
128
|
}
|
129
|
+
if (isNaN(parsedWeight)) {
|
130
|
+
return '4';
|
131
|
+
}
|
132
|
+
return parsedWeight.substr(0, 1);
|
95
133
|
};
|
96
134
|
|
135
|
+
|
97
136
|
webfont.FontApiParser.prototype.parseVariations_ = function(variations) {
|
98
137
|
var finalVariations = [];
|
99
138
|
|
@@ -3,17 +3,19 @@ var FontApiParserTest = TestCase('FontApiParserTest');
|
|
3
3
|
FontApiParserTest.prototype.testParsedValuesAreCoherent = function() {
|
4
4
|
var fontFamilies = [ 'Tangerine', 'Droid Serif:bi',
|
5
5
|
'Yanone Kaffeesatz:200,300,400,700',
|
6
|
-
'Cantarell:italic,b' ];
|
6
|
+
'Cantarell:italic,b', 'Exo:100italic', 'Lobster:200n'];
|
7
7
|
var fontApiParser = new webfont.FontApiParser(fontFamilies);
|
8
8
|
|
9
9
|
fontApiParser.parse();
|
10
10
|
var parsedFontFamilies = fontApiParser.getFontFamilies();
|
11
11
|
|
12
|
-
assertEquals(
|
12
|
+
assertEquals(6, parsedFontFamilies.length);
|
13
13
|
assertEquals('Tangerine', parsedFontFamilies[0]);
|
14
14
|
assertEquals('Droid Serif', parsedFontFamilies[1]);
|
15
15
|
assertEquals('Yanone Kaffeesatz', parsedFontFamilies[2]);
|
16
16
|
assertEquals('Cantarell', parsedFontFamilies[3]);
|
17
|
+
assertEquals('Exo', parsedFontFamilies[4]);
|
18
|
+
assertEquals('Lobster', parsedFontFamilies[5]);
|
17
19
|
var variations = fontApiParser.getVariations();
|
18
20
|
|
19
21
|
var tangerine = variations['Tangerine'];
|
@@ -39,6 +41,16 @@ FontApiParserTest.prototype.testParsedValuesAreCoherent = function() {
|
|
39
41
|
assertEquals(2, cantarell.length);
|
40
42
|
assertEquals('i4', cantarell[0]);
|
41
43
|
assertEquals('n7', cantarell[1]);
|
44
|
+
|
45
|
+
var exo = variations['Exo'];
|
46
|
+
assertNotNull(exo);
|
47
|
+
assertEquals(1, exo.length);
|
48
|
+
assertEquals('i1', exo[0]);
|
49
|
+
|
50
|
+
var lobster = variations['Lobster'];
|
51
|
+
assertNotNull(lobster);
|
52
|
+
assertEquals(1, lobster.length);
|
53
|
+
assertEquals('n2', lobster[0]);
|
42
54
|
};
|
43
55
|
|
44
56
|
FontApiParserTest.prototype.testMixOfNumericWeightAndStyle = function() {
|
data/webfontloader.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'webfontloader'
|
16
|
-
s.version = '1.0.
|
17
|
-
s.date = '2012-
|
16
|
+
s.version = '1.0.31'
|
17
|
+
s.date = '2012-09-11'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 31
|
10
|
+
version: 1.0.31
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Carver
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-09-11 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
prerelease: false
|