diff --git a/src/core/fontwatcher.js b/src/core/fontwatcher.js old mode 100644 new mode 100755 index 66f8f461..e13e2dfe --- a/src/core/fontwatcher.js +++ b/src/core/fontwatcher.js @@ -57,11 +57,14 @@ goog.scope(function () { if (FontWatcher.SHOULD_USE_NATIVE_LOADER === null) { if (!!window.FontFace) { var match = /Gecko.*Firefox\/(\d+)/.exec(FontWatcher.getUserAgent()); - var safari10Match = /OS X.*Version\/10\..*Safari/.exec(FontWatcher.getUserAgent()) && /Apple/.exec(FontWatcher.getVendor()); + var appleMatch = /Apple/.exec(FontWatcher.getVendor()) + var safari10Match = /OS X.*Version\/10\..*Safari/.exec(FontWatcher.getUserAgent()) || + /AppleWebKit\/603/.exec(FontWatcher.getUserAgent()) || + /AppleWebKit\/602/.exec(FontWatcher.getUserAgent()) if (match) { FontWatcher.SHOULD_USE_NATIVE_LOADER = parseInt(match[1], 10) > 42; - } else if (safari10Match) { + } else if (appleMatch && safari10Match) { FontWatcher.SHOULD_USE_NATIVE_LOADER = false; } else { FontWatcher.SHOULD_USE_NATIVE_LOADER = true; diff --git a/src/core/fontwatchrunner.js b/src/core/fontwatchrunner.js old mode 100644 new mode 100755 index 62e91e92..05221d94 --- a/src/core/fontwatchrunner.js +++ b/src/core/fontwatchrunner.js @@ -39,7 +39,8 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper, */ webfont.FontWatchRunner.LastResortFonts = { SERIF: 'serif', - SANS_SERIF: 'sans-serif' + SANS_SERIF: 'sans-serif', + MOCK_FONT: 'FontWatchRunnerMockFont' }; /** @@ -70,7 +71,7 @@ goog.scope(function () { /** * Returns true if this browser is WebKit and it has the fallback bug - * which is present in WebKit 536.11 and earlier. + * which is present in WebKit 602.*, 603.* ,and 536.11 and earlier * * @return {boolean} */ @@ -81,7 +82,9 @@ goog.scope(function () { FontWatchRunner.HAS_WEBKIT_FALLBACK_BUG = !!match && (parseInt(match[1], 10) < 536 || (parseInt(match[1], 10) === 536 && - parseInt(match[2], 10) <= 11)); + parseInt(match[2], 10) <= 11) || + parseInt(match[1], 10) === 602 || + parseInt(match[1], 10) === 603); } return FontWatchRunner.HAS_WEBKIT_FALLBACK_BUG; }; @@ -110,6 +113,10 @@ goog.scope(function () { this.lastResortWidths_[FontWatchRunner.LastResortFonts.SERIF] = this.lastResortRulerA_.getWidth(); this.lastResortWidths_[FontWatchRunner.LastResortFonts.SANS_SERIF] = this.lastResortRulerB_.getWidth(); + if (FontWatchRunner.hasWebKitFallbackBug()) { + this.lastResortWidths_[FontWatchRunner.LastResortFonts.MOCK_FONT] = this.getMockFontWidth_(); + } + this.started_ = goog.now(); this.check_(); @@ -193,6 +200,35 @@ goog.scope(function () { return this.metricCompatibleFonts_ === null || this.metricCompatibleFonts_.hasOwnProperty(this.font_.getName()); }; + + /** + * Calculates the width of a mock font with the current font's variation css style + * before it has finished loading. + * + * @private + * @return {number} + */ + FontWatchRunner.prototype.getMockFontWidth_ = function () { + + var mockFontStyle = "@font-face\{font-family: '" + FontWatchRunner.LastResortFonts.MOCK_FONT + "';" + + this.font_.getCssVariation() + + "src: url(some.woff2) format('woff2');\}" + + var mockFontCss = this.domHelper_.createStyle(mockFontStyle); + this.domHelper_.insertInto('head', mockFontCss) + + var mockFontRuler = new FontRuler(this.domHelper_, this.fontTestString_); + mockFontRuler.setFont(new Font(FontWatchRunner.LastResortFonts.MOCK_FONT, this.font_.getVariation())); + mockFontRuler.insert(); + + var mockFontWidth = mockFontRuler.getWidth(); + + mockFontRuler.remove() + this.domHelper_.removeElement(mockFontCss) + + return mockFontWidth + } + /** * 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