Use Math.hypot, instead of Math.sqrt with manual squaring (#12973)

When the PDF.js project started `Math.hypot` didn't exist yet, and until recently we still supported browsers (IE 11) without a native `Math.hypot` implementation; please see this compatibility information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot#browser_compatibility

Furthermore, somewhat recently there were performance improvements of `Math.hypot` in Firefox; see https://bugzilla.mozilla.org/show_bug.cgi?id=1648820

Finally, this patch also replaces a couple of multiplications with the exponentiation operator.
This commit is contained in:
Jonas Jenwald 2021-02-10 12:28:49 +01:00 committed by GitHub
parent 3a2c259b57
commit 31098c404d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 27 deletions

View file

@ -89,7 +89,7 @@ const renderTextLayer = (function renderTextLayerClosure() {
if (style.vertical) {
angle += Math.PI / 2;
}
const fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
const fontHeight = Math.hypot(tx[2], tx[3]);
let fontAscent = fontHeight;
if (style.ascent) {
fontAscent = style.ascent * fontAscent;