webfontloader 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/CHANGELOG +4 -0
  2. data/lib/webfontloader.rb +1 -1
  3. data/spec/ascender/ascenderscript_spec.js +24 -1
  4. data/spec/core/eventdispatcher_spec.js +15 -11
  5. data/spec/core/font_spec.js +83 -192
  6. data/spec/core/fontruler_spec.js +7 -4
  7. data/spec/core/fontwatcher_spec.js +78 -61
  8. data/spec/core/fontwatchrunner_spec.js +85 -33
  9. data/spec/core/webfont_spec.js +224 -0
  10. data/spec/custom/customcss_spec.js +5 -2
  11. data/spec/deps.js +13 -13
  12. data/spec/fontdeck/fontdeckscript_spec.js +4 -6
  13. data/spec/fonts/sourcesansc.css +1 -0
  14. data/spec/fonts/sourcesanscbold.css +1 -0
  15. data/spec/fonts/sourcesanscbold.otf +0 -0
  16. data/spec/google/fontapiparser_spec.js +58 -178
  17. data/spec/google/googlefontapi_spec.js +14 -42
  18. data/spec/google/lastresortwebkitfontwatchrunner_spec.js +12 -10
  19. data/spec/index.html +5 -3
  20. data/spec/monotype/monotypescript_spec.js +3 -2
  21. data/spec/typekit/typekitscript_spec.js +9 -4
  22. data/src/ascender/ascender_script.js +43 -26
  23. data/src/core/eventdispatcher.js +23 -23
  24. data/src/core/font.js +80 -99
  25. data/src/core/fontmoduleloader.js +1 -1
  26. data/src/core/fontruler.js +10 -20
  27. data/src/core/fontwatcher.js +24 -46
  28. data/src/core/fontwatchrunner.js +13 -13
  29. data/src/core/initialize.js +0 -10
  30. data/src/core/webfont.js +134 -0
  31. data/src/custom/customcss.js +14 -10
  32. data/src/fontdeck/fontdeck_script.js +7 -9
  33. data/src/google/fontapiparser.js +11 -15
  34. data/src/google/googlefontapi.js +1 -2
  35. data/src/google/lastresortwebkitfontwatchrunner.js +15 -13
  36. data/src/modules.yml +2 -3
  37. data/src/monotype/monotype_script.js +9 -8
  38. data/src/typekit/typekit_script.js +17 -7
  39. data/webfontloader.gemspec +7 -6
  40. metadata +9 -8
  41. data/spec/core/cssfontfamilyname_spec.js +0 -38
  42. data/spec/core/fontvariationdescription_spec.js +0 -67
  43. data/src/core/cssfontfamilyname.js +0 -33
  44. data/src/core/fontvariationdescription.js +0 -140
@@ -1,5 +1,7 @@
1
1
  goog.provide('webfont.TypekitScript');
2
2
 
3
+ goog.require('webfont.Font');
4
+
3
5
  /**
4
6
  * @constructor
5
7
  * @implements {webfont.FontModule}
@@ -7,15 +9,15 @@ goog.provide('webfont.TypekitScript');
7
9
  webfont.TypekitScript = function(domHelper, configuration) {
8
10
  this.domHelper_ = domHelper;
9
11
  this.configuration_ = configuration;
10
- this.fontFamilies_ = [];
11
- this.fontVariations_ = {};
12
+ this.fonts_ = [];
12
13
  };
13
14
 
14
15
  webfont.TypekitScript.NAME = 'typekit';
15
16
  webfont.TypekitScript.HOOK = '__webfonttypekitmodule__';
16
17
 
17
18
  goog.scope(function () {
18
- var TypekitScript = webfont.TypekitScript;
19
+ var TypekitScript = webfont.TypekitScript,
20
+ Font = webfont.Font;
19
21
 
20
22
  TypekitScript.prototype.getScriptSrc = function(kitId) {
21
23
  var protocol = this.domHelper_.getProtocol();
@@ -39,8 +41,17 @@ goog.scope(function () {
39
41
  // and what fonts will be provided.
40
42
  loadWindow[webfont.TypekitScript.HOOK][kitId] = function(callback) {
41
43
  var init = function(typekitSupports, fontFamilies, fontVariations) {
42
- self.fontFamilies_ = fontFamilies;
43
- self.fontVariations_ = fontVariations;
44
+ for (var i = 0; i < fontFamilies.length; i += 1) {
45
+ var variations = fontVariations[fontFamilies[i]];
46
+
47
+ if (variations) {
48
+ for(var j = 0; j < variations.length; j += 1) {
49
+ self.fonts_.push(new Font(fontFamilies[i], variations[j]));
50
+ }
51
+ } else {
52
+ self.fonts_.push(new Font(fontFamilies[i]));
53
+ }
54
+ }
44
55
  support(typekitSupports);
45
56
  };
46
57
  callback(userAgent, configuration, init);
@@ -49,14 +60,13 @@ goog.scope(function () {
49
60
  // Load the Typekit script.
50
61
  var script = this.domHelper_.createScriptSrc(this.getScriptSrc(kitId))
51
62
  this.domHelper_.insertInto('head', script);
52
-
53
63
  } else {
54
64
  support(true);
55
65
  }
56
66
  };
57
67
 
58
68
  TypekitScript.prototype.load = function(onReady) {
59
- onReady(this.fontFamilies_, this.fontVariations_);
69
+ onReady(this.fonts_);
60
70
  };
61
71
  });
62
72
 
@@ -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.4.0'
17
- s.date = '2013-03-28'
16
+ s.version = '1.4.1'
17
+ s.date = '2013-04-08'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
@@ -110,17 +110,16 @@ DESC
110
110
  lib/webfontloader/modules.rb
111
111
  spec/ascender/ascenderscript_spec.js
112
112
  spec/core/cssclassname_spec.js
113
- spec/core/cssfontfamilyname_spec.js
114
113
  spec/core/domhelper_spec.js
115
114
  spec/core/eventdispatcher_spec.js
116
115
  spec/core/font_spec.js
117
116
  spec/core/fontmoduleloader_spec.js
118
117
  spec/core/fontruler_spec.js
119
- spec/core/fontvariationdescription_spec.js
120
118
  spec/core/fontwatcher_spec.js
121
119
  spec/core/fontwatchrunner_spec.js
122
120
  spec/core/size_spec.js
123
121
  spec/core/useragentparser_spec.js
122
+ spec/core/webfont_spec.js
124
123
  spec/custom/customcss_spec.js
125
124
  spec/deps.js
126
125
  spec/fontdeck/fontdeckscript_spec.js
@@ -136,6 +135,9 @@ DESC
136
135
  spec/fonts/sourcesans.woff
137
136
  spec/fonts/sourcesansa.css
138
137
  spec/fonts/sourcesansb.css
138
+ spec/fonts/sourcesansc.css
139
+ spec/fonts/sourcesanscbold.css
140
+ spec/fonts/sourcesanscbold.otf
139
141
  spec/google/fontapiparser_spec.js
140
142
  spec/google/fontapiurlbuilder_spec.js
141
143
  spec/google/googlefontapi_spec.js
@@ -148,19 +150,18 @@ DESC
148
150
  src/closure.js
149
151
  src/core/browserinfo.js
150
152
  src/core/cssclassname.js
151
- src/core/cssfontfamilyname.js
152
153
  src/core/domhelper.js
153
154
  src/core/eventdispatcher.js
154
155
  src/core/font.js
155
156
  src/core/fontmoduleloader.js
156
157
  src/core/fontruler.js
157
- src/core/fontvariationdescription.js
158
158
  src/core/fontwatcher.js
159
159
  src/core/fontwatchrunner.js
160
160
  src/core/initialize.js
161
161
  src/core/namespace.js
162
162
  src/core/useragent.js
163
163
  src/core/useragentparser.js
164
+ src/core/webfont.js
164
165
  src/custom/customcss.js
165
166
  src/fontdeck/fontdeck_script.js
166
167
  src/google/fontapiparser.js
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: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 0
10
- version: 1.4.0
9
+ - 1
10
+ version: 1.4.1
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: 2013-03-28 00:00:00 Z
19
+ date: 2013-04-08 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rake
@@ -141,17 +141,16 @@ files:
141
141
  - lib/webfontloader/modules.rb
142
142
  - spec/ascender/ascenderscript_spec.js
143
143
  - spec/core/cssclassname_spec.js
144
- - spec/core/cssfontfamilyname_spec.js
145
144
  - spec/core/domhelper_spec.js
146
145
  - spec/core/eventdispatcher_spec.js
147
146
  - spec/core/font_spec.js
148
147
  - spec/core/fontmoduleloader_spec.js
149
148
  - spec/core/fontruler_spec.js
150
- - spec/core/fontvariationdescription_spec.js
151
149
  - spec/core/fontwatcher_spec.js
152
150
  - spec/core/fontwatchrunner_spec.js
153
151
  - spec/core/size_spec.js
154
152
  - spec/core/useragentparser_spec.js
153
+ - spec/core/webfont_spec.js
155
154
  - spec/custom/customcss_spec.js
156
155
  - spec/deps.js
157
156
  - spec/fontdeck/fontdeckscript_spec.js
@@ -167,6 +166,9 @@ files:
167
166
  - spec/fonts/sourcesans.woff
168
167
  - spec/fonts/sourcesansa.css
169
168
  - spec/fonts/sourcesansb.css
169
+ - spec/fonts/sourcesansc.css
170
+ - spec/fonts/sourcesanscbold.css
171
+ - spec/fonts/sourcesanscbold.otf
170
172
  - spec/google/fontapiparser_spec.js
171
173
  - spec/google/fontapiurlbuilder_spec.js
172
174
  - spec/google/googlefontapi_spec.js
@@ -179,19 +181,18 @@ files:
179
181
  - src/closure.js
180
182
  - src/core/browserinfo.js
181
183
  - src/core/cssclassname.js
182
- - src/core/cssfontfamilyname.js
183
184
  - src/core/domhelper.js
184
185
  - src/core/eventdispatcher.js
185
186
  - src/core/font.js
186
187
  - src/core/fontmoduleloader.js
187
188
  - src/core/fontruler.js
188
- - src/core/fontvariationdescription.js
189
189
  - src/core/fontwatcher.js
190
190
  - src/core/fontwatchrunner.js
191
191
  - src/core/initialize.js
192
192
  - src/core/namespace.js
193
193
  - src/core/useragent.js
194
194
  - src/core/useragentparser.js
195
+ - src/core/webfont.js
195
196
  - src/custom/customcss.js
196
197
  - src/fontdeck/fontdeck_script.js
197
198
  - src/google/fontapiparser.js
@@ -1,38 +0,0 @@
1
- describe('CssFontFamilyName', function () {
2
- var CssFontFamilyName = webfont.CssFontFamilyName,
3
- sanitizer = new CssFontFamilyName();
4
-
5
- describe('#quote', function () {
6
- it('should quote names with spaces', function () {
7
- expect(sanitizer.quote('My Family')).toEqual("'My Family'");
8
- });
9
-
10
- it('should quote names with spaces and double quotes', function () {
11
- expect(sanitizer.quote('"My Family"')).toEqual("'My Family'");
12
- });
13
-
14
- it('should quote names with spaces and single quotes', function () {
15
- expect(sanitizer.quote("'My Family'")).toEqual("'My Family'");
16
- });
17
-
18
- it('should quote multiple single quoted names separated with a comma', function () {
19
- expect(sanitizer.quote("'family 1','family 2'")).toEqual("'family 1','family 2'");
20
- });
21
-
22
- it('should quote multiple single quoted names separated with a comma and space', function () {
23
- expect(sanitizer.quote("'family 1', 'family 2'")).toEqual("'family 1','family 2'");
24
- });
25
-
26
- it('should not quote when there is no space', function () {
27
- expect(sanitizer.quote('MyFamily')).toEqual('MyFamily');
28
- });
29
-
30
- it('should remove quotes when they are unnecesssary', function () {
31
- expect(sanitizer.quote('"MyFamily"')).toEqual('MyFamily');
32
- });
33
-
34
- it('should not quote multiple names when there is no space', function () {
35
- expect(sanitizer.quote("'family-1', 'family-2'")).toEqual('family-1,family-2');
36
- });
37
- });
38
- });
@@ -1,67 +0,0 @@
1
- describe('FontVariationDescription', function () {
2
- var FontVariationDescription = webfont.FontVariationDescription,
3
- fvd = new FontVariationDescription();
4
-
5
- describe('#compact', function () {
6
- it('should default to n4 when there is no description', function () {
7
- expect(fvd.compact('')).toEqual('n4');
8
- });
9
-
10
- it('should compact font style', function () {
11
- expect(fvd.compact('font-style: normal;')).toEqual('n4');
12
- expect(fvd.compact('font-style: italic;')).toEqual('i4');
13
- expect(fvd.compact('font-style: oblique;')).toEqual('o4');
14
- });
15
-
16
- it('should return the default value when font-style is incorrect', function () {
17
- expect(fvd.compact('font-style: other;')).toEqual('n4');
18
- });
19
-
20
- it('should compact font weight', function () {
21
- expect(fvd.compact('font-weight: normal;')).toEqual('n4');
22
- expect(fvd.compact('font-weight: bold;')).toEqual('n7');
23
- for (var i = 1; i < 10; i += 1) {
24
- expect(fvd.compact('font-weight: ' + (i * 100) + ';')).toEqual('n' + i);
25
- }
26
- });
27
-
28
- it('should return the default value when font-weight is incorrect', function () {
29
- expect(fvd.compact('font-weight: 140;')).toEqual('n4');
30
- expect(fvd.compact('font-weight: other;')).toEqual('n4');
31
- });
32
-
33
- it('should compact multiple properties', function () {
34
- expect(fvd.compact('font-weight: bold; font-style: italic;')).toEqual('i7');
35
- expect(fvd.compact('; font-weight: bold; font-style: italic;')).toEqual('i7');
36
- expect(fvd.compact('font-style:italic;font-weight:bold;')).toEqual('i7');
37
- expect(fvd.compact(' font-style: italic ;\n\nfont-weight: bold; ')).toEqual('i7');
38
- });
39
-
40
- it('should return default values for incorrect individual properties', function () {
41
- expect(fvd.compact('src: url(/font.otf)')).toEqual('n4');
42
- expect(fvd.compact('font-weight: 900; src: url(/font.otf);')).toEqual('n9');
43
- expect(fvd.compact('font-weight: 800; font-stretch:condensed;')).toEqual('n8');
44
- });
45
- });
46
-
47
- describe('#expand', function () {
48
- it('should expand font-style', function () {
49
- expect(fvd.expand('n4')).toEqual('font-style:normal;font-weight:400;');
50
- expect(fvd.expand('i4')).toEqual('font-style:italic;font-weight:400;');
51
- expect(fvd.expand('o4')).toEqual('font-style:oblique;font-weight:400;');
52
- });
53
-
54
- it('should expand weights correctly', function () {
55
- for (var i = 1; i < 10; i += 1) {
56
- expect(fvd.expand('n' + i)).toEqual('font-style:normal;font-weight:' + (i * 100) + ';');
57
- }
58
- });
59
-
60
- it('should not expand incorrect input', function () {
61
- expect(fvd.expand('')).toBeNull();
62
- expect(fvd.expand('n')).toBeNull();
63
- expect(fvd.expand('1')).toBeNull();
64
- expect(fvd.expand('n1x')).toBeNull();
65
- });
66
- });
67
- });
@@ -1,33 +0,0 @@
1
- goog.provide('webfont.CssFontFamilyName');
2
-
3
- /**
4
- * Handles quoting rules for a font family name in css.
5
- * @constructor
6
- */
7
- webfont.CssFontFamilyName = function() {
8
- /** @type {string} */
9
- this.quote_ = "'";
10
- };
11
-
12
- goog.scope(function () {
13
- var CssFontFamilyName = webfont.CssFontFamilyName;
14
-
15
- /**
16
- * Quotes the name.
17
- * @param {string} name The name to quote.
18
- * @return {string} The quoted name.
19
- */
20
- CssFontFamilyName.prototype.quote = function(name) {
21
- var quoted = [];
22
- var split = name.split(/,\s*/);
23
- for (var i = 0; i < split.length; i++) {
24
- var part = split[i].replace(/['"]/g, '');
25
- if (part.indexOf(' ') == -1) {
26
- quoted.push(part);
27
- } else {
28
- quoted.push(this.quote_ + part + this.quote_);
29
- }
30
- }
31
- return quoted.join(',');
32
- };
33
- });
@@ -1,140 +0,0 @@
1
- goog.provide('webfont.FontVariationDescription');
2
-
3
- /**
4
- * @constructor
5
- */
6
- webfont.FontVariationDescription = function() {
7
- this.properties_ = webfont.FontVariationDescription.PROPERTIES;
8
- this.values_ = webfont.FontVariationDescription.VALUES;
9
- };
10
-
11
- /**
12
- * @const
13
- */
14
- webfont.FontVariationDescription.PROPERTIES = [
15
- 'font-style',
16
- 'font-weight'
17
- ];
18
-
19
- /**
20
- * @const
21
- */
22
- webfont.FontVariationDescription.VALUES = {
23
- 'font-style': [
24
- ['n', 'normal'],
25
- ['i', 'italic'],
26
- ['o', 'oblique']
27
- ],
28
- 'font-weight': [
29
- ['1', '100'],
30
- ['2', '200'],
31
- ['3', '300'],
32
- ['4', '400'],
33
- ['5', '500'],
34
- ['6', '600'],
35
- ['7', '700'],
36
- ['8', '800'],
37
- ['9', '900'],
38
- ['4', 'normal'],
39
- ['7', 'bold']
40
- ]
41
- };
42
-
43
- goog.scope(function () {
44
- var FontVariationDescription = webfont.FontVariationDescription;
45
-
46
- /**
47
- * @private
48
- * @constructor
49
- */
50
- FontVariationDescription.Item = function(index, property, values) {
51
- this.index_ = index;
52
- this.property_ = property;
53
- this.values_ = values;
54
- }
55
-
56
- FontVariationDescription.Item.prototype.compact = function(output, value) {
57
- for (var i = 0; i < this.values_.length; i++) {
58
- if (value == this.values_[i][1]) {
59
- output[this.index_] = this.values_[i][0];
60
- return;
61
- }
62
- }
63
- }
64
-
65
- FontVariationDescription.Item.prototype.expand = function(output, value) {
66
- for (var i = 0; i < this.values_.length; i++) {
67
- if (value == this.values_[i][0]) {
68
- output[this.index_] = this.property_ + ':' + this.values_[i][1];
69
- return;
70
- }
71
- }
72
- }
73
-
74
- /**
75
- * Compacts CSS declarations into an FVD.
76
- * @param {string} input A string of CSS declarations such as
77
- * 'font-weight:normal;font-style:italic'.
78
- * @return {string} The equivalent FVD such as 'n4'.
79
- */
80
- FontVariationDescription.prototype.compact = function(input) {
81
- var result = ['n', '4'];
82
- var descriptors = input.split(';');
83
-
84
- for (var i = 0, len = descriptors.length; i < len; i++) {
85
- var pair = descriptors[i].replace(/\s+/g, '').split(':');
86
- if (pair.length == 2) {
87
- var property = pair[0];
88
- var value = pair[1];
89
- var item = this.getItem_(property);
90
- if (item) {
91
- item.compact(result, value);
92
- }
93
- }
94
- }
95
-
96
- return result.join('');
97
- };
98
-
99
- /**
100
- * Expands a FVD string into equivalent CSS declarations.
101
- * @param {string} fvd The FVD string, such as 'n4'.
102
- * @return {?string} The equivalent CSS such as
103
- * 'font-weight:normal;font-style:italic' or null if it cannot be parsed.
104
- */
105
- FontVariationDescription.prototype.expand = function(fvd) {
106
- if (fvd.length != 2) {
107
- return null;
108
- }
109
-
110
- var result = [null, null];
111
-
112
- for (var i = 0, len = this.properties_.length; i < len; i++) {
113
- var property = this.properties_[i];
114
- var key = fvd.substr(i, 1);
115
- var values = this.values_[property];
116
- var item = new webfont.FontVariationDescription.Item(i, property, values);
117
- item.expand(result, key);
118
- }
119
-
120
- if (result[0] && result[1]) {
121
- return result.join(';') + ';';
122
- } else {
123
- return null;
124
- }
125
- }
126
-
127
- /**
128
- * @private
129
- */
130
- FontVariationDescription.prototype.getItem_ = function(property) {
131
- for (var i = 0; i < this.properties_.length; i++) {
132
- if (property == this.properties_[i]) {
133
- var values = this.values_[property];
134
- return new webfont.FontVariationDescription.Item(i, property, values);
135
- }
136
- }
137
-
138
- return null;
139
- };
140
- });