Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #103 from typekit/bs-remove-height-check

Drop checking the height in the FontWatchRunner
  • Loading branch information...
commit 7cdd38304e83d61eacac236872dbee1da6fbd797 2 parents c2fb2ba + 452552c
@bramstein bramstein authored
View
8 spec/core/fontruler_spec.js
@@ -10,7 +10,7 @@ describe('FontRuler', function () {
it('should prevent a long test string from word wrapping', function () {
var fontRulerA = new FontRuler(domHelper, 'abc'),
- fontRulerB = new FontRuler(domHelper, 'Hello World, this should wrap!');
+ fontRulerB = new FontRuler(domHelper, 'abc HelloWorld,thisshouldwrap!!!!');
fontRulerA.insert();
fontRulerB.insert();
@@ -18,9 +18,9 @@ describe('FontRuler', function () {
fontRulerA.setFont('sans-serif');
fontRulerB.setFont('sans-serif');
- var sizeA = fontRulerA.getSize(),
- sizeB = fontRulerB.getSize();
+ var widthA = fontRulerA.getWidth(),
+ widthB = fontRulerB.getWidth();
- expect(sizeA.height).toEqual(sizeB.height);
+ expect(widthA).not.toEqual(widthB);
});
});
View
99 spec/core/fontwatchrunner_spec.js
@@ -2,7 +2,6 @@ describe('FontWatchRunner', function () {
var FontWatchRunner = webfont.FontWatchRunner,
BrowserInfo = webfont.BrowserInfo,
UserAgentParser = webfont.UserAgentParser,
- Size = webfont.Size,
DomHelper = webfont.DomHelper,
FontRuler = webfont.FontRuler;
@@ -20,40 +19,40 @@ describe('FontWatchRunner', function () {
describe('Fake browser', function () {
var fontFamily = 'My Family',
fontDescription = 'n4',
- TARGET_SIZE = new Size(3, 3),
- FALLBACK_SIZE_A = new Size(1, 1),
- FALLBACK_SIZE_B = new Size(2, 2),
- LAST_RESORT_SIZE = new Size(4, 4),
+ TARGET_SIZE = 3,
+ FALLBACK_SIZE_A = 1,
+ FALLBACK_SIZE_B = 2,
+ LAST_RESORT_SIZE = 4,
browserInfo = new BrowserInfo(true, false, false),
fallbackBugBrowserInfo = new BrowserInfo(true, true, false),
- setupSizes = [],
- actualSizes = [],
+ setupWidths = [],
+ actualWidths = [],
timesToGetTimeBeforeTimeout = 10;
beforeEach(function () {
jasmine.Clock.useMock();
- setupSizes = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE];
+ setupWidths = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE];
- actualSizes = [];
+ actualWidths = [];
var setupFinished = false,
- fakeGetSizeCount = 0;
+ fakeGetWidthCount = 0;
- spyOn(FontRuler.prototype, 'getSize').andCallFake(function () {
+ spyOn(FontRuler.prototype, 'getWidth').andCallFake(function () {
var result = null;
if (setupFinished) {
// If you are getting an exception here your tests does not specify enough
// size data to run properly.
- if (fakeGetSizeCount >= actualSizes.length) {
+ if (fakeGetWidthCount >= actualWidths.length) {
throw 'Invalid test data';
}
- result = actualSizes[fakeGetSizeCount];
- fakeGetSizeCount += 1;
+ result = actualWidths[fakeGetWidthCount];
+ fakeGetWidthCount += 1;
} else {
- result = setupSizes[Math.min(fakeGetSizeCount, setupSizes.length - 1)];
- fakeGetSizeCount += 1;
+ result = setupWidths[Math.min(fakeGetWidthCount, setupWidths.length - 1)];
+ fakeGetWidthCount += 1;
}
return result;
});
@@ -73,14 +72,14 @@ describe('FontWatchRunner', function () {
spyOn(FontWatchRunner.prototype, 'start').andCallFake(function () {
setupFinished = true;
- fakeGetSizeCount = 0;
+ fakeGetWidthCount = 0;
originalStart.apply(this);
});
});
it('should call active if fonts are already loaded', function () {
- actualSizes = [
+ actualWidths = [
TARGET_SIZE, TARGET_SIZE
];
@@ -94,7 +93,7 @@ describe('FontWatchRunner', function () {
});
it('should wait for font load and call active', function () {
- actualSizes = [
+ actualWidths = [
FALLBACK_SIZE_A, FALLBACK_SIZE_B,
FALLBACK_SIZE_A, FALLBACK_SIZE_B,
FALLBACK_SIZE_A, FALLBACK_SIZE_B,
@@ -113,7 +112,7 @@ describe('FontWatchRunner', function () {
it('should wait for font inactive and call inactive', function () {
timesToGetTimeBeforeTimeout = 5;
- actualSizes = [
+ actualWidths = [
FALLBACK_SIZE_A, FALLBACK_SIZE_B,
FALLBACK_SIZE_A, FALLBACK_SIZE_B,
FALLBACK_SIZE_A, FALLBACK_SIZE_B,
@@ -132,7 +131,7 @@ describe('FontWatchRunner', function () {
describe('WebKit fallback bug', function () {
it('should ignore fallback size and call active', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
TARGET_SIZE, TARGET_SIZE
];
@@ -147,7 +146,7 @@ describe('FontWatchRunner', function () {
});
it('should consider last resort font as having identical metrics and call active', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
LAST_RESORT_SIZE, LAST_RESORT_SIZE
];
@@ -164,7 +163,7 @@ describe('FontWatchRunner', function () {
});
it('should fail to load font and call inactive', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
FALLBACK_SIZE_A, FALLBACK_SIZE_B
@@ -182,7 +181,7 @@ describe('FontWatchRunner', function () {
});
it('should call inactive when we are loading a metric incompatible font', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
LAST_RESORT_SIZE, LAST_RESORT_SIZE
];
@@ -200,7 +199,7 @@ describe('FontWatchRunner', function () {
});
it('should call active when we are loading a metric compatible font', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
LAST_RESORT_SIZE, LAST_RESORT_SIZE
];
@@ -218,24 +217,6 @@ describe('FontWatchRunner', function () {
});
});
- describe('webkit metrics bug', function () {
- it('should correctly call active even though the height is different', function () {
- actualSizes = [
- FALLBACK_SIZE_A, FALLBACK_SIZE_B,
- new Size(1, 2), new Size(2, 3), // Same as FALLBACK_SIZE_A and FALLBACK_SIZE_B except that the height is different.
- TARGET_SIZE, TARGET_SIZE
- ];
-
- var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
- domHelper, fontFamily, fontDescription, new BrowserInfo(true, false, true));
-
- fontWatchRunner.start();
-
- jasmine.Clock.tick(2 * 25);
- expect(activeCallback).toHaveBeenCalledWith('My Family', 'n4');
- });
- });
-
describe('test string', function () {
var fontWatchRunner = null;
@@ -244,7 +225,7 @@ describe('FontWatchRunner', function () {
});
it('should be the default', function () {
- actualSizes = [
+ actualWidths = [
TARGET_SIZE, TARGET_SIZE
];
fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
@@ -257,7 +238,7 @@ describe('FontWatchRunner', function () {
});
it('should be a custom string', function () {
- actualSizes = [
+ actualWidths = [
TARGET_SIZE, TARGET_SIZE
];
@@ -302,14 +283,14 @@ describe('FontWatchRunner', function () {
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, 'SourceSansA', '', userAgent.getBrowserInfo(), 500),
ruler = new FontRuler(domHelper, 'abcdef'),
- activeSize = null,
- originalSize = null,
+ activeWidth = null,
+ originalWidth = null,
finalCheck = false;
runs(function () {
ruler.insert();
ruler.setFont('monospace');
- originalSize = ruler.getSize();
+ originalWidth = ruler.getWidth();
ruler.setFont("'SourceSansA', monospace");
fontWatchRunner.start();
});
@@ -320,8 +301,8 @@ describe('FontWatchRunner', function () {
runs(function () {
expect(activeCallback).toHaveBeenCalledWith('SourceSansA', '');
- activeSize = ruler.getSize();
- expect(activeSize).not.toEqual(originalSize);
+ activeWidth = ruler.getWidth();
+ expect(activeWidth).not.toEqual(originalWidth);
window.setTimeout(function () {
finalCheck = true;
@@ -333,8 +314,8 @@ describe('FontWatchRunner', function () {
});
runs(function () {
- expect(ruler.getSize()).not.toEqual(originalSize);
- expect(ruler.getSize()).toEqual(activeSize);
+ expect(ruler.getWidth()).not.toEqual(originalWidth);
+ expect(ruler.getWidth()).toEqual(activeWidth);
});
});
@@ -359,14 +340,14 @@ describe('FontWatchRunner', function () {
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, 'SourceSansB', '', userAgent.getBrowserInfo(), 500),
ruler = new FontRuler(domHelper, 'abcdef'),
- activeSize = null,
- originalSize = null,
+ activeWidth = null,
+ originalWidth = null,
finalCheck = false;
runs(function () {
ruler.insert();
ruler.setFont('monospace');
- originalSize = ruler.getSize();
+ originalWidth = ruler.getWidth();
ruler.setFont("'SourceSansB', monospace");
fontWatchRunner.start();
var link = document.createElement('link');
@@ -383,8 +364,8 @@ describe('FontWatchRunner', function () {
runs(function () {
expect(activeCallback).toHaveBeenCalledWith('SourceSansB', '');
- activeSize = ruler.getSize();
- expect(activeSize).not.toEqual(originalSize);
+ activeWidth = ruler.getWidth();
+ expect(activeWidth).not.toEqual(originalWidth);
window.setTimeout(function () {
finalCheck = true;
@@ -396,8 +377,8 @@ describe('FontWatchRunner', function () {
});
runs(function () {
- expect(ruler.getSize()).not.toEqual(originalSize);
- expect(ruler.getSize()).toEqual(activeSize);
+ expect(ruler.getWidth()).not.toEqual(originalWidth);
+ expect(ruler.getWidth()).toEqual(activeWidth);
});
});
});
View
5 spec/deps.js
@@ -7,14 +7,13 @@ goog.addDependency("../../src/core/cssclassname.js", ["webfont.CssClassName"], [
goog.addDependency("../../src/core/cssfontfamilyname.js", ["webfont.CssFontFamilyName"], []);
goog.addDependency("../../src/core/domhelper.js", ["webfont.DomHelper"], []);
goog.addDependency("../../src/core/eventdispatcher.js", ["webfont.EventDispatcher"], ["webfont.CssClassName"]);
-goog.addDependency("../../src/core/font.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher","webfont.Size"]);
+goog.addDependency("../../src/core/font.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher"]);
goog.addDependency("../../src/core/fontmoduleloader.js", ["webfont.FontModuleLoader"], []);
-goog.addDependency("../../src/core/fontruler.js", ["webfont.FontRuler"], ["webfont.CssFontFamilyName","webfont.FontVariationDescription","webfont.Size"]);
+goog.addDependency("../../src/core/fontruler.js", ["webfont.FontRuler"], ["webfont.CssFontFamilyName","webfont.FontVariationDescription"]);
goog.addDependency("../../src/core/fontvariationdescription.js", ["webfont.FontVariationDescription"], []);
goog.addDependency("../../src/core/fontwatcher.js", ["webfont.FontWatcher"], ["webfont.FontWatchRunner"]);
goog.addDependency("../../src/core/fontwatchrunner.js", ["webfont.FontWatchRunner"], ["webfont.FontRuler"]);
goog.addDependency("../../src/core/initialize.js", ["webfont"], ["webfont.UserAgentParser","webfont.FontModuleLoader","webfont.WebFont"]);
-goog.addDependency("../../src/core/size.js", ["webfont.Size"], []);
goog.addDependency("../../src/core/useragent.js", ["webfont.UserAgent"], []);
goog.addDependency("../../src/core/useragentparser.js", ["webfont.UserAgentParser"], ["webfont.BrowserInfo","webfont.UserAgent"]);
goog.addDependency("../../src/custom/customcss.js", ["webfont.CustomCss"], []);
View
39 spec/google/lastresortwebkitfontwatchrunner_spec.js
@@ -1,21 +1,20 @@
describe('LastResortWebKitFontWatchRunner', function () {
var LastResortWebKitFontWatchRunner = webfont.LastResortWebKitFontWatchRunner,
BrowserInfo = webfont.BrowserInfo,
- Size = webfont.Size,
DomHelper = webfont.DomHelper,
FontRuler = webfont.FontRuler,
domHelper = new DomHelper(window),
fontFamily = 'My Family',
fontDescription = 'n4';
- var TARGET_SIZE = new Size(3, 3),
- FALLBACK_SIZE_A = new Size(1, 1),
- FALLBACK_SIZE_B = new Size(2, 2),
- LAST_RESORT_SIZE = new Size(4, 4),
+ var TARGET_SIZE = 3,
+ FALLBACK_SIZE_A = 1,
+ FALLBACK_SIZE_B = 2,
+ LAST_RESORT_SIZE = 4,
browserInfo = new BrowserInfo(true, true, false),
- setupSizes = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE],
- actualSizes = [],
+ setupWidths = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE],
+ actualWidths = [],
timesToGetTimeBeforeTimeout = 10,
activeCallback = null,
inactiveCallback = null;
@@ -23,29 +22,29 @@ describe('LastResortWebKitFontWatchRunner', function () {
beforeEach(function () {
jasmine.Clock.useMock();
- actualSizes = [];
+ actualWidths = [];
activeCallback = jasmine.createSpy('activeCallback');
inactiveCallback = jasmine.createSpy('inactiveCallback');
timesToGetTimeBeforeTimeout = 10;
var setupFinished = false,
- fakeGetSizeCount = 0;
+ fakeGetWidthCount = 0;
- spyOn(FontRuler.prototype, 'getSize').andCallFake(function () {
+ spyOn(FontRuler.prototype, 'getWidth').andCallFake(function () {
var result = null;
if (setupFinished) {
// If you are getting an exception here your tests does not specify enough
// size data to run properly.
- if (fakeGetSizeCount >= actualSizes.length) {
+ if (fakeGetWidthCount >= actualWidths.length) {
throw 'Invalid test data';
}
- result = actualSizes[fakeGetSizeCount];
- fakeGetSizeCount += 1;
+ result = actualWidths[fakeGetWidthCount];
+ fakeGetWidthCount += 1;
} else {
- result = setupSizes[Math.min(fakeGetSizeCount, setupSizes.length - 1)];
- fakeGetSizeCount += 1;
+ result = setupWidths[Math.min(fakeGetWidthCount, setupWidths.length - 1)];
+ fakeGetWidthCount += 1;
}
return result;
});
@@ -63,13 +62,13 @@ describe('LastResortWebKitFontWatchRunner', function () {
spyOn(LastResortWebKitFontWatchRunner.prototype, 'start').andCallFake(function () {
setupFinished = true;
- fakeGetSizeCount = 0;
+ fakeGetWidthCount = 0;
originalStart.apply(this);
});
});
it('should ignore fallback size and call active', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
TARGET_SIZE, TARGET_SIZE
];
@@ -84,7 +83,7 @@ describe('LastResortWebKitFontWatchRunner', function () {
});
it('should consider last resort font as having identical metrics and call active', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
LAST_RESORT_SIZE, LAST_RESORT_SIZE
];
@@ -101,7 +100,7 @@ describe('LastResortWebKitFontWatchRunner', function () {
});
it('should fail to load font and call inactive', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
FALLBACK_SIZE_A, FALLBACK_SIZE_B
@@ -119,7 +118,7 @@ describe('LastResortWebKitFontWatchRunner', function () {
});
it('should call inactive when we are loading a metric incompatible font', function () {
- actualSizes = [
+ actualWidths = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
LAST_RESORT_SIZE, LAST_RESORT_SIZE
];
View
1  spec/index.html
@@ -37,7 +37,6 @@
<script src="../spec/core/useragentparser_spec.js"></script>
<script src="../spec/core/fontmoduleloader_spec.js"></script>
<script src="../spec/core/eventdispatcher_spec.js"></script>
- <script src="../spec/core/size_spec.js"></script>
<script src="../spec/core/fontruler_spec.js"></script>
<script src="../spec/core/fontwatchrunner_spec.js"></script>
<script src="../spec/core/fontwatcher_spec.js"></script>
View
4 src/core/font.js
@@ -3,7 +3,6 @@ goog.provide('webfont.WebFont');
goog.require('webfont.DomHelper');
goog.require('webfont.EventDispatcher');
goog.require('webfont.FontWatcher');
-goog.require('webfont.Size');
/**
* @param {Window} mainWindow The main application window containing
@@ -24,8 +23,7 @@ goog.scope(function () {
var WebFont = webfont.WebFont,
DomHelper = webfont.DomHelper,
EventDispatcher = webfont.EventDispatcher,
- FontWatcher = webfont.FontWatcher,
- Size = webfont.Size;
+ FontWatcher = webfont.FontWatcher;
/**
* @param {string} name
View
10 src/core/fontruler.js
@@ -2,7 +2,6 @@ goog.provide('webfont.FontRuler');
goog.require('webfont.CssFontFamilyName');
goog.require('webfont.FontVariationDescription');
-goog.require('webfont.Size');
/**
* An element that can be used to measure the metrics
@@ -20,8 +19,7 @@ webfont.FontRuler = function(domHelper, fontTestString) {
};
goog.scope(function () {
- var FontRuler = webfont.FontRuler,
- Size = webfont.Size;
+ var FontRuler = webfont.FontRuler;
/**
* @param {string} fontFamily
@@ -55,10 +53,10 @@ goog.scope(function () {
};
/**
- * @return {webfont.Size}
+ * @return {number}
*/
- FontRuler.prototype.getSize = function() {
- return new Size(this.el_.offsetWidth, this.el_.offsetHeight);
+ FontRuler.prototype.getWidth = function() {
+ return this.el_.offsetWidth;
};
/**
View
79 src/core/fontwatchrunner.js
@@ -23,7 +23,7 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
this.fontDescription_ = fontDescription;
this.fontTestString_ = opt_fontTestString || webfont.FontWatchRunner.DEFAULT_TEST_STRING;
this.browserInfo_ = browserInfo;
- this.lastResortSizes_ = {};
+ this.lastResortWidths_ = {};
this.timeout_ = opt_timeout || 5000;
this.metricCompatibleFonts_ = opt_metricCompatibleFonts || null;
@@ -31,7 +31,7 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
this.fontRulerA_ = null;
this.fontRulerB_ = null;
- this.setupLastResortSizes_();
+ this.setupLastResortWidths_();
};
/**
@@ -41,16 +41,7 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
webfont.FontWatchRunner.LastResortFonts = {
SERIF: 'serif',
SANS_SERIF: 'sans-serif',
- MONOSPACE: 'monospace',
- // Apple Color Emoji is the last character fallback on iOS. Since
- // all iOS installations that support web fonts have this font it
- // effectively means that Apple Color Emoji is the last resort
- // font on iOS. The caveat is that it only has characters in the
- // Emoji code range, and falls back to the real last resort font,
- // which is the default sans-serif font. It however affects the
- // height of the span we are monitoring, so we'll have to include
- // it in our list of last resort fonts.
- EMOJI: 'Apple Color Emoji'
+ MONOSPACE: 'monospace'
};
/**
@@ -69,7 +60,7 @@ goog.scope(function () {
/**
* @private
*/
- FontWatchRunner.prototype.setupLastResortSizes_ = function() {
+ FontWatchRunner.prototype.setupLastResortWidths_ = function() {
var fontRuler = new FontRuler(this.domHelper_, this.fontTestString_);
fontRuler.insert();
@@ -77,7 +68,7 @@ goog.scope(function () {
for (var font in FontWatchRunner.LastResortFonts) {
if (FontWatchRunner.LastResortFonts.hasOwnProperty(font)) {
fontRuler.setFont(FontWatchRunner.LastResortFonts[font], this.fontDescription_);
- this.lastResortSizes_[FontWatchRunner.LastResortFonts[font]] = fontRuler.getSize();
+ this.lastResortWidths_[FontWatchRunner.LastResortFonts[font]] = fontRuler.getWidth();
}
}
fontRuler.remove();
@@ -98,35 +89,31 @@ goog.scope(function () {
};
/**
- * Returns true if the given size matches the generic font family size.
+ * Returns true if the given width matches the generic font family width.
*
* @private
- * @param {?webfont.Size} size
+ * @param {number} width
* @param {string} lastResortFont
* @return {boolean}
*/
- FontWatchRunner.prototype.sizeMatches_ = function(size, lastResortFont) {
- if (this.browserInfo_.hasWebKitMetricsBug()) {
- return size.equalsWidth(this.lastResortSizes_[lastResortFont]);
- } else {
- return size.equals(this.lastResortSizes_[lastResortFont]);
- }
+ FontWatchRunner.prototype.widthMatches_ = function(width, lastResortFont) {
+ return width === this.lastResortWidths_[lastResortFont];
};
/**
- * Return true if the given sizes match any of the generic font family
- * sizes.
+ * Return true if the given widths match any of the generic font family
+ * widths.
*
* @private
- * @param {?webfont.Size} a
- * @param {?webfont.Size} b
+ * @param {number} a
+ * @param {number} b
* @return {boolean}
*/
- FontWatchRunner.prototype.sizesMatchLastResortSizes_ = function(a, b) {
+ FontWatchRunner.prototype.widthsMatchLastResortWidths_ = function(a, b) {
for (var font in FontWatchRunner.LastResortFonts) {
if (FontWatchRunner.LastResortFonts.hasOwnProperty(font)) {
- if (this.sizeMatches_(a, FontWatchRunner.LastResortFonts[font]) &&
- this.sizeMatches_(b, FontWatchRunner.LastResortFonts[font])) {
+ if (this.widthMatches_(a, FontWatchRunner.LastResortFonts[font]) &&
+ this.widthMatches_(b, FontWatchRunner.LastResortFonts[font])) {
return true;
}
}
@@ -147,25 +134,25 @@ goog.scope(function () {
* Returns true if both fonts match the normal fallback fonts.
*
* @private
- * @param {webfont.Size} sizeA
- * @param {webfont.Size} sizeB
+ * @param {number} a
+ * @param {number} b
* @return {boolean}
*/
- FontWatchRunner.prototype.isFallbackFont_ = function (sizeA, sizeB) {
- return this.sizeMatches_(sizeA, FontWatchRunner.LastResortFonts.SERIF) &&
- this.sizeMatches_(sizeB, FontWatchRunner.LastResortFonts.SANS_SERIF);
+ FontWatchRunner.prototype.isFallbackFont_ = function (a, b) {
+ return this.widthMatches_(a, FontWatchRunner.LastResortFonts.SERIF) &&
+ this.widthMatches_(b, FontWatchRunner.LastResortFonts.SANS_SERIF);
};
/**
- * Returns true if the WebKit bug is present and both sizes match a last resort font.
+ * Returns true if the WebKit bug is present and both widths match a last resort font.
*
* @private
- * @param {webfont.Size} sizeA
- * @param {webfont.Size} sizeB
+ * @param {number} a
+ * @param {number} b
* @return {boolean}
*/
- FontWatchRunner.prototype.isLastResortFont_ = function (sizeA, sizeB) {
- return this.browserInfo_.hasWebKitFallbackBug() && this.sizesMatchLastResortSizes_(sizeA, sizeB);
+ FontWatchRunner.prototype.isLastResortFont_ = function (a, b) {
+ return this.browserInfo_.hasWebKitFallbackBug() && this.widthsMatchLastResortWidths_(a, b);
};
/**
@@ -180,21 +167,21 @@ goog.scope(function () {
};
/**
- * Checks the size of the two spans against their original sizes during each
- * async loop. If the size of one of the spans is different than the original
- * size, then we know that the font is rendering and finish with the active
+ * Checks the width of the two spans against their original widths during each
+ * async loop. If the width of one of the spans is different than the original
+ * width, then we know that the font is rendering and finish with the active
* callback. If we wait more than 5 seconds and nothing has changed, we finish
* with the inactive callback.
*
* @private
*/
FontWatchRunner.prototype.check_ = function() {
- var sizeA = this.fontRulerA_.getSize();
- var sizeB = this.fontRulerB_.getSize();
+ var widthA = this.fontRulerA_.getWidth();
+ var widthB = this.fontRulerB_.getWidth();
- if (this.isFallbackFont_(sizeA, sizeB) || this.isLastResortFont_(sizeA, sizeB)) {
+ if (this.isFallbackFont_(widthA, widthB) || this.isLastResortFont_(widthA, widthB)) {
if (this.hasTimedOut_()) {
- if (this.isLastResortFont_(sizeA, sizeB) && this.isMetricCompatibleFont_()) {
+ if (this.isLastResortFont_(widthA, widthB) && this.isMetricCompatibleFont_()) {
this.finish_(this.activeCallback_);
} else {
this.finish_(this.inactiveCallback_);
View
43 src/core/size.js
@@ -1,43 +0,0 @@
-goog.provide('webfont.Size');
-
-/**
- * @constructor
- * @param {number} width
- * @param {number} height
- */
-webfont.Size = function (width, height) {
- this.width = width;
- this.height = height;
-};
-
-goog.scope(function () {
- var Size = webfont.Size;
-
- /**
- * Returns true if this size equals other.
- *
- * @param {webfont.Size} other
- * @return {boolean}
- */
- Size.prototype.equals = function (other) {
- return this.equalsWidth(other) && this.equalsHeight(other);
- };
-
- /**
- * Returns true if this.width equals other.width
- * @param {webfont.Size} other
- * @return {boolean}
- */
- Size.prototype.equalsWidth = function (other) {
- return !!other && this.width == other.width;
- };
-
- /**
- * Returns true if this.height equals other.height
- * @param {webfont.Size} other
- * @return {boolean}
- */
- Size.prototype.equalsHeight = function (other) {
- return !!other && this.height == other.height;
- };
-});
View
50 src/google/lastresortwebkitfontwatchrunner.js
@@ -22,10 +22,10 @@ webfont.LastResortWebKitFontWatchRunner = function(activeCallback,
goog.base(this, activeCallback, inactiveCallback, domHelper,
fontFamily, fontDescription, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString);
- this.webKitLastResortFontSizes_ = this.setUpWebKitLastResortFontSizes_();
- this.webKitLastResortSizeChange_ = false;
- this.lastObservedSizeA_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SERIF];
- this.lastObservedSizeB_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SANS_SERIF];;
+ this.webKitLastResortFontWidths_ = this.setUpWebKitLastResortFontWidths_();
+ this.webKitLastResortWidthChange_ = false;
+ this.lastObservedWidthA_ = this.lastResortWidths_[webfont.FontWatchRunner.LastResortFonts.SERIF];
+ this.lastObservedWidthB_ = this.lastResortWidths_[webfont.FontWatchRunner.LastResortFonts.SANS_SERIF];;
};
goog.inherits(webfont.LastResortWebKitFontWatchRunner, webfont.FontWatchRunner)
@@ -49,57 +49,57 @@ goog.scope(function () {
* OS/browsers values.
*/
LastResortWebKitFontWatchRunner.prototype
- .setUpWebKitLastResortFontSizes_ = function() {
+ .setUpWebKitLastResortFontWidths_ = function() {
var lastResortFonts = ['Times New Roman', 'Arial', 'Times', 'Sans', 'Serif'];
- var lastResortFontSizes = lastResortFonts.length;
- var webKitLastResortFontSizes = {};
+ var lastResortFontWidths = lastResortFonts.length;
+ var webKitLastResortFontWidths = {};
var fontRuler = new FontRuler(this.domHelper_, this.fontTestString_);
fontRuler.insert();
fontRuler.setFont(lastResortFonts[0], this.fontDescription_);
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
- for (var i = 1; i < lastResortFontSizes; i++) {
+ webKitLastResortFontWidths[fontRuler.getWidth()] = true;
+ for (var i = 1; i < lastResortFontWidths; i++) {
var font = lastResortFonts[i];
fontRuler.setFont(font, this.fontDescription_);
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
+ webKitLastResortFontWidths[fontRuler.getWidth()] = true;
// Another WebKit quirk if the normal weight/style is loaded first,
// the size of the normal weight is returned when loading another weight.
if (this.fontDescription_[1] != '4') {
fontRuler.setFont(font, this.fontDescription_[0] + '4');
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
+ webKitLastResortFontWidths[fontRuler.getWidth()] = true;
}
}
fontRuler.remove();
- return webKitLastResortFontSizes;
+ return webKitLastResortFontWidths;
};
/**
* @override
*/
LastResortWebKitFontWatchRunner.prototype.check_ = function() {
- var sizeA = this.fontRulerA_.getSize();
- var sizeB = this.fontRulerB_.getSize();
+ var widthA = this.fontRulerA_.getWidth();
+ var widthB = this.fontRulerB_.getWidth();
- if (!this.webKitLastResortSizeChange_ && sizeA.width == sizeB.width &&
- this.webKitLastResortFontSizes_[sizeA.width]) {
- this.webKitLastResortFontSizes_ = {};
- this.webKitLastResortFontSizes_[sizeA.width] = true;
- this.webKitLastResortSizeChange_ = true;
+ if (!this.webKitLastResortWidthChange_ && widthA == widthB &&
+ this.webKitLastResortFontWidths_[widthA]) {
+ this.webKitLastResortFontWidths_ = {};
+ this.webKitLastResortFontWidths_[widthA] = true;
+ this.webKitLastResortWidthChange_ = true;
}
- if ((this.lastObservedSizeA_.width != sizeA.width || this.lastObservedSizeB_.width != sizeB.width) &&
- (!this.webKitLastResortFontSizes_[sizeA.width] &&
- !this.webKitLastResortFontSizes_[sizeB.width])) {
+ if ((this.lastObservedWidthA_ != widthA || this.lastObservedWidthB_ != widthB) &&
+ (!this.webKitLastResortFontWidths_[widthA] &&
+ !this.webKitLastResortFontWidths_[widthB])) {
this.finish_(this.activeCallback_);
} else if (goog.now() - this.started_ >= 5000) {
// In order to handle the fact that a font could be the same size as the
// default browser font on a webkit browser, mark the font as active
- // after 5 seconds if the latest 2 sizes are in webKitLastResortFontSizes_
+ // after 5 seconds if the latest 2 widths are in webKitLastResortFontWidths_
// and the font name is known to be metrics compatible.
- if (this.webKitLastResortFontSizes_[sizeA.width]
- && this.webKitLastResortFontSizes_[sizeB.width] &&
+ if (this.webKitLastResortFontWidths_[widthA]
+ && this.webKitLastResortFontWidths_[widthB] &&
LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS[
this.fontFamily_]) {
this.finish_(this.activeCallback_);
View
1  src/modules.yml
@@ -9,7 +9,6 @@ core:
- core/fontvariationdescription.js
- core/eventdispatcher.js
- core/fontmoduleloader.js
- - core/size.js
- core/fontruler.js
- core/fontwatchrunner.js
- core/fontwatcher.js
Please sign in to comment.
Something went wrong with that request. Please try again.