Created
March 13, 2012 18:24
-
-
Save subzey/2030480 to your computer and use it in GitHub Desktop.
Firefox bug #733698 workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var FakeTextMetrics, | |
proto, | |
fontSetterNative, | |
measureTextNative, | |
fillTextNative, | |
strokeTextNative; | |
if ( | |
!window.CanvasRenderingContext2D || | |
!window.TextMetrics || | |
!(proto = window.CanvasRenderingContext2D.prototype) || | |
!proto.hasOwnProperty("font") || | |
!proto.hasOwnProperty("mozTextStyle") || | |
typeof proto.__lookupSetter__ !== "function" || | |
!(fontSetterNative = proto.__lookupSetter__("font")) | |
){ | |
return; | |
} | |
proto.__defineSetter__("font", function(value){ | |
try { | |
return fontSetterNative.call(this, value); | |
} catch (e){ | |
if (e.name !== 'NS_ERROR_FAILURE'){ | |
throw e; | |
} | |
} | |
}); | |
measureTextNative = proto.measureText; | |
FakeTextMetrics = function(){ | |
this.width = 0; | |
this.isFake = true; | |
this.__proto__ = window.TextMetrics.prototype; | |
}; | |
proto.measureText = function($0){ | |
try { | |
return measureTextNative.apply(this, arguments); | |
} catch (e) { | |
if (e.name !== 'NS_ERROR_FAILURE'){ | |
throw e; | |
} else { | |
return new FakeTextMetrics(); | |
} | |
} | |
}; | |
fillTextNative = proto.fillText; | |
proto.fillText = function($0, $1, $2, $3){ | |
try { | |
fillTextNative.apply(this, arguments); | |
} catch (e) { | |
if (e.name !== 'NS_ERROR_FAILURE'){ | |
throw e; | |
} | |
} | |
}; | |
strokeTextNative = proto.strokeText; | |
proto.strokeText = function($0, $1, $2, $3){ | |
try { | |
strokeTextNative.apply(this, arguments); | |
} catch (e) { | |
if (e.name !== 'NS_ERROR_FAILURE'){ | |
throw e; | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment