Merge pull request #11064 from Snuffleupagus/Util-class
Convert the `src/shared/util.js` file to ES6 syntax
This commit is contained in:
commit
02dcd20263
@ -137,8 +137,8 @@ class Page {
|
|||||||
if (cropBox === mediaBox || isArrayEqual(cropBox, mediaBox)) {
|
if (cropBox === mediaBox || isArrayEqual(cropBox, mediaBox)) {
|
||||||
view = mediaBox;
|
view = mediaBox;
|
||||||
} else {
|
} else {
|
||||||
const box = Util.intersect(cropBox, mediaBox, /* skipEmpty = */ true);
|
const box = Util.intersect(cropBox, mediaBox);
|
||||||
if (box) {
|
if (box && ((box[2] - box[0]) !== 0 && (box[3] - box[1]) !== 0)) {
|
||||||
view = box;
|
view = box;
|
||||||
} else {
|
} else {
|
||||||
warn('Empty /CropBox and /MediaBox intersection.');
|
warn('Empty /CropBox and /MediaBox intersection.');
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import './compatibility';
|
import './compatibility';
|
||||||
import { ReadableStream } from './streams_polyfill';
|
import { ReadableStream } from './streams_polyfill';
|
||||||
@ -319,14 +320,14 @@ function getVerbosityLevel() {
|
|||||||
// end users.
|
// end users.
|
||||||
function info(msg) {
|
function info(msg) {
|
||||||
if (verbosity >= VerbosityLevel.INFOS) {
|
if (verbosity >= VerbosityLevel.INFOS) {
|
||||||
console.log('Info: ' + msg);
|
console.log(`Info: ${msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-fatal warnings.
|
// Non-fatal warnings.
|
||||||
function warn(msg) {
|
function warn(msg) {
|
||||||
if (verbosity >= VerbosityLevel.WARNINGS) {
|
if (verbosity >= VerbosityLevel.WARNINGS) {
|
||||||
console.log('Warning: ' + msg);
|
console.log(`Warning: ${msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,8 +343,9 @@ function assert(cond, msg) {
|
|||||||
|
|
||||||
// Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
|
// Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
|
||||||
function isSameOrigin(baseUrl, otherUrl) {
|
function isSameOrigin(baseUrl, otherUrl) {
|
||||||
|
let base;
|
||||||
try {
|
try {
|
||||||
var base = new URL(baseUrl);
|
base = new URL(baseUrl);
|
||||||
if (!base.origin || base.origin === 'null') {
|
if (!base.origin || base.origin === 'null') {
|
||||||
return false; // non-HTTP url
|
return false; // non-HTTP url
|
||||||
}
|
}
|
||||||
@ -351,7 +353,7 @@ function isSameOrigin(baseUrl, otherUrl) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var other = new URL(otherUrl, base);
|
const other = new URL(otherUrl, base);
|
||||||
return base.origin === other.origin;
|
return base.origin === other.origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +386,7 @@ function createValidAbsoluteUrl(url, baseUrl) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
||||||
if (_isValidProtocol(absoluteUrl)) {
|
if (_isValidProtocol(absoluteUrl)) {
|
||||||
return absoluteUrl;
|
return absoluteUrl;
|
||||||
}
|
}
|
||||||
@ -400,7 +402,7 @@ function shadow(obj, prop, value) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var PasswordException = (function PasswordExceptionClosure() {
|
const PasswordException = (function PasswordExceptionClosure() {
|
||||||
function PasswordException(msg, code) {
|
function PasswordException(msg, code) {
|
||||||
this.name = 'PasswordException';
|
this.name = 'PasswordException';
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
@ -413,7 +415,7 @@ var PasswordException = (function PasswordExceptionClosure() {
|
|||||||
return PasswordException;
|
return PasswordException;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var UnknownErrorException = (function UnknownErrorExceptionClosure() {
|
const UnknownErrorException = (function UnknownErrorExceptionClosure() {
|
||||||
function UnknownErrorException(msg, details) {
|
function UnknownErrorException(msg, details) {
|
||||||
this.name = 'UnknownErrorException';
|
this.name = 'UnknownErrorException';
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
@ -426,7 +428,7 @@ var UnknownErrorException = (function UnknownErrorExceptionClosure() {
|
|||||||
return UnknownErrorException;
|
return UnknownErrorException;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var InvalidPDFException = (function InvalidPDFExceptionClosure() {
|
const InvalidPDFException = (function InvalidPDFExceptionClosure() {
|
||||||
function InvalidPDFException(msg) {
|
function InvalidPDFException(msg) {
|
||||||
this.name = 'InvalidPDFException';
|
this.name = 'InvalidPDFException';
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
@ -438,7 +440,7 @@ var InvalidPDFException = (function InvalidPDFExceptionClosure() {
|
|||||||
return InvalidPDFException;
|
return InvalidPDFException;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var MissingPDFException = (function MissingPDFExceptionClosure() {
|
const MissingPDFException = (function MissingPDFExceptionClosure() {
|
||||||
function MissingPDFException(msg) {
|
function MissingPDFException(msg) {
|
||||||
this.name = 'MissingPDFException';
|
this.name = 'MissingPDFException';
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
@ -450,7 +452,7 @@ var MissingPDFException = (function MissingPDFExceptionClosure() {
|
|||||||
return MissingPDFException;
|
return MissingPDFException;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var UnexpectedResponseException =
|
const UnexpectedResponseException =
|
||||||
(function UnexpectedResponseExceptionClosure() {
|
(function UnexpectedResponseExceptionClosure() {
|
||||||
function UnexpectedResponseException(msg, status) {
|
function UnexpectedResponseException(msg, status) {
|
||||||
this.name = 'UnexpectedResponseException';
|
this.name = 'UnexpectedResponseException';
|
||||||
@ -467,7 +469,7 @@ var UnexpectedResponseException =
|
|||||||
/**
|
/**
|
||||||
* Error caused during parsing PDF data.
|
* Error caused during parsing PDF data.
|
||||||
*/
|
*/
|
||||||
let FormatError = (function FormatErrorClosure() {
|
const FormatError = (function FormatErrorClosure() {
|
||||||
function FormatError(msg) {
|
function FormatError(msg) {
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
}
|
}
|
||||||
@ -482,7 +484,7 @@ let FormatError = (function FormatErrorClosure() {
|
|||||||
/**
|
/**
|
||||||
* Error used to indicate task cancellation.
|
* Error used to indicate task cancellation.
|
||||||
*/
|
*/
|
||||||
let AbortException = (function AbortExceptionClosure() {
|
const AbortException = (function AbortExceptionClosure() {
|
||||||
function AbortException(msg) {
|
function AbortException(msg) {
|
||||||
this.name = 'AbortException';
|
this.name = 'AbortException';
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
@ -494,7 +496,7 @@ let AbortException = (function AbortExceptionClosure() {
|
|||||||
return AbortException;
|
return AbortException;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var NullCharactersRegExp = /\x00/g;
|
const NullCharactersRegExp = /\x00/g;
|
||||||
|
|
||||||
function removeNullCharacters(str) {
|
function removeNullCharacters(str) {
|
||||||
if (typeof str !== 'string') {
|
if (typeof str !== 'string') {
|
||||||
@ -507,15 +509,15 @@ function removeNullCharacters(str) {
|
|||||||
function bytesToString(bytes) {
|
function bytesToString(bytes) {
|
||||||
assert(bytes !== null && typeof bytes === 'object' &&
|
assert(bytes !== null && typeof bytes === 'object' &&
|
||||||
bytes.length !== undefined, 'Invalid argument for bytesToString');
|
bytes.length !== undefined, 'Invalid argument for bytesToString');
|
||||||
var length = bytes.length;
|
const length = bytes.length;
|
||||||
var MAX_ARGUMENT_COUNT = 8192;
|
const MAX_ARGUMENT_COUNT = 8192;
|
||||||
if (length < MAX_ARGUMENT_COUNT) {
|
if (length < MAX_ARGUMENT_COUNT) {
|
||||||
return String.fromCharCode.apply(null, bytes);
|
return String.fromCharCode.apply(null, bytes);
|
||||||
}
|
}
|
||||||
var strBuf = [];
|
const strBuf = [];
|
||||||
for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
|
for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
|
||||||
var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
|
const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
|
||||||
var chunk = bytes.subarray(i, chunkEnd);
|
const chunk = bytes.subarray(i, chunkEnd);
|
||||||
strBuf.push(String.fromCharCode.apply(null, chunk));
|
strBuf.push(String.fromCharCode.apply(null, chunk));
|
||||||
}
|
}
|
||||||
return strBuf.join('');
|
return strBuf.join('');
|
||||||
@ -523,9 +525,9 @@ function bytesToString(bytes) {
|
|||||||
|
|
||||||
function stringToBytes(str) {
|
function stringToBytes(str) {
|
||||||
assert(typeof str === 'string', 'Invalid argument for stringToBytes');
|
assert(typeof str === 'string', 'Invalid argument for stringToBytes');
|
||||||
var length = str.length;
|
const length = str.length;
|
||||||
var bytes = new Uint8Array(length);
|
const bytes = new Uint8Array(length);
|
||||||
for (var i = 0; i < length; ++i) {
|
for (let i = 0; i < length; ++i) {
|
||||||
bytes[i] = str.charCodeAt(i) & 0xFF;
|
bytes[i] = str.charCodeAt(i) & 0xFF;
|
||||||
}
|
}
|
||||||
return bytes;
|
return bytes;
|
||||||
@ -550,22 +552,19 @@ function arrayByteLength(arr) {
|
|||||||
* @returns {Uint8Array}
|
* @returns {Uint8Array}
|
||||||
*/
|
*/
|
||||||
function arraysToBytes(arr) {
|
function arraysToBytes(arr) {
|
||||||
|
const length = arr.length;
|
||||||
// Shortcut: if first and only item is Uint8Array, return it.
|
// Shortcut: if first and only item is Uint8Array, return it.
|
||||||
if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
|
if (length === 1 && (arr[0] instanceof Uint8Array)) {
|
||||||
return arr[0];
|
return arr[0];
|
||||||
}
|
}
|
||||||
var resultLength = 0;
|
let resultLength = 0;
|
||||||
var i, ii = arr.length;
|
for (let i = 0; i < length; i++) {
|
||||||
var item, itemLength;
|
resultLength += arrayByteLength(arr[i]);
|
||||||
for (i = 0; i < ii; i++) {
|
|
||||||
item = arr[i];
|
|
||||||
itemLength = arrayByteLength(item);
|
|
||||||
resultLength += itemLength;
|
|
||||||
}
|
}
|
||||||
var pos = 0;
|
let pos = 0;
|
||||||
var data = new Uint8Array(resultLength);
|
const data = new Uint8Array(resultLength);
|
||||||
for (i = 0; i < ii; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
item = arr[i];
|
let item = arr[i];
|
||||||
if (!(item instanceof Uint8Array)) {
|
if (!(item instanceof Uint8Array)) {
|
||||||
if (typeof item === 'string') {
|
if (typeof item === 'string') {
|
||||||
item = stringToBytes(item);
|
item = stringToBytes(item);
|
||||||
@ -573,7 +572,7 @@ function arraysToBytes(arr) {
|
|||||||
item = new Uint8Array(item);
|
item = new Uint8Array(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemLength = item.byteLength;
|
const itemLength = item.byteLength;
|
||||||
data.set(item, pos);
|
data.set(item, pos);
|
||||||
pos += itemLength;
|
pos += itemLength;
|
||||||
}
|
}
|
||||||
@ -611,9 +610,9 @@ function readUint32(data, offset) {
|
|||||||
// Lazy test the endianness of the platform
|
// Lazy test the endianness of the platform
|
||||||
// NOTE: This will be 'true' for simulated TypedArrays
|
// NOTE: This will be 'true' for simulated TypedArrays
|
||||||
function isLittleEndian() {
|
function isLittleEndian() {
|
||||||
var buffer8 = new Uint8Array(4);
|
const buffer8 = new Uint8Array(4);
|
||||||
buffer8[0] = 1;
|
buffer8[0] = 1;
|
||||||
var view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
const view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
||||||
return (view32[0] === 1);
|
return (view32[0] === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,22 +626,20 @@ function isEvalSupported() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var Util = (function UtilClosure() {
|
const rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
|
||||||
function Util() {}
|
|
||||||
|
|
||||||
var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
|
class Util {
|
||||||
|
// makeCssRgb() can be called thousands of times. Using ´rgbBuf` avoids
|
||||||
// makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
|
|
||||||
// creating many intermediate strings.
|
// creating many intermediate strings.
|
||||||
Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
|
static makeCssRgb(r, g, b) {
|
||||||
rgbBuf[1] = r;
|
rgbBuf[1] = r;
|
||||||
rgbBuf[3] = g;
|
rgbBuf[3] = g;
|
||||||
rgbBuf[5] = b;
|
rgbBuf[5] = b;
|
||||||
return rgbBuf.join('');
|
return rgbBuf.join('');
|
||||||
};
|
}
|
||||||
|
|
||||||
// Concatenates two transformation matrices together and returns the result.
|
// Concatenates two transformation matrices together and returns the result.
|
||||||
Util.transform = function Util_transform(m1, m2) {
|
static transform(m1, m2) {
|
||||||
return [
|
return [
|
||||||
m1[0] * m2[0] + m1[2] * m2[1],
|
m1[0] * m2[0] + m1[2] * m2[1],
|
||||||
m1[1] * m2[0] + m1[3] * m2[1],
|
m1[1] * m2[0] + m1[3] * m2[1],
|
||||||
@ -651,44 +648,42 @@ var Util = (function UtilClosure() {
|
|||||||
m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
|
m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
|
||||||
m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
|
m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
|
||||||
];
|
];
|
||||||
};
|
}
|
||||||
|
|
||||||
// For 2d affine transforms
|
// For 2d affine transforms
|
||||||
Util.applyTransform = function Util_applyTransform(p, m) {
|
static applyTransform(p, m) {
|
||||||
var xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
const xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
||||||
var yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
const yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
||||||
return [xt, yt];
|
return [xt, yt];
|
||||||
};
|
}
|
||||||
|
|
||||||
Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
|
static applyInverseTransform(p, m) {
|
||||||
var d = m[0] * m[3] - m[1] * m[2];
|
const d = m[0] * m[3] - m[1] * m[2];
|
||||||
var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
|
const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
|
||||||
var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
|
const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
|
||||||
return [xt, yt];
|
return [xt, yt];
|
||||||
};
|
}
|
||||||
|
|
||||||
// Applies the transform to the rectangle and finds the minimum axially
|
// Applies the transform to the rectangle and finds the minimum axially
|
||||||
// aligned bounding box.
|
// aligned bounding box.
|
||||||
Util.getAxialAlignedBoundingBox =
|
static getAxialAlignedBoundingBox(r, m) {
|
||||||
function Util_getAxialAlignedBoundingBox(r, m) {
|
const p1 = Util.applyTransform(r, m);
|
||||||
|
const p2 = Util.applyTransform(r.slice(2, 4), m);
|
||||||
var p1 = Util.applyTransform(r, m);
|
const p3 = Util.applyTransform([r[0], r[3]], m);
|
||||||
var p2 = Util.applyTransform(r.slice(2, 4), m);
|
const p4 = Util.applyTransform([r[2], r[1]], m);
|
||||||
var p3 = Util.applyTransform([r[0], r[3]], m);
|
|
||||||
var p4 = Util.applyTransform([r[2], r[1]], m);
|
|
||||||
return [
|
return [
|
||||||
Math.min(p1[0], p2[0], p3[0], p4[0]),
|
Math.min(p1[0], p2[0], p3[0], p4[0]),
|
||||||
Math.min(p1[1], p2[1], p3[1], p4[1]),
|
Math.min(p1[1], p2[1], p3[1], p4[1]),
|
||||||
Math.max(p1[0], p2[0], p3[0], p4[0]),
|
Math.max(p1[0], p2[0], p3[0], p4[0]),
|
||||||
Math.max(p1[1], p2[1], p3[1], p4[1])
|
Math.max(p1[1], p2[1], p3[1], p4[1])
|
||||||
];
|
];
|
||||||
};
|
}
|
||||||
|
|
||||||
Util.inverseTransform = function Util_inverseTransform(m) {
|
static inverseTransform(m) {
|
||||||
var d = m[0] * m[3] - m[1] * m[2];
|
const d = m[0] * m[3] - m[1] * m[2];
|
||||||
return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
|
return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
|
||||||
(m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
|
(m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
|
||||||
};
|
}
|
||||||
|
|
||||||
// Apply a generic 3d matrix M on a 3-vector v:
|
// Apply a generic 3d matrix M on a 3-vector v:
|
||||||
// | a b c | | X |
|
// | a b c | | X |
|
||||||
@ -696,44 +691,42 @@ var Util = (function UtilClosure() {
|
|||||||
// | g h i | | Z |
|
// | g h i | | Z |
|
||||||
// M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
|
// M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
|
||||||
// with v as [X,Y,Z]
|
// with v as [X,Y,Z]
|
||||||
Util.apply3dTransform = function Util_apply3dTransform(m, v) {
|
static apply3dTransform(m, v) {
|
||||||
return [
|
return [
|
||||||
m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
|
m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
|
||||||
m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
|
m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
|
||||||
m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
|
m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
|
||||||
];
|
];
|
||||||
};
|
}
|
||||||
|
|
||||||
// This calculation uses Singular Value Decomposition.
|
// This calculation uses Singular Value Decomposition.
|
||||||
// The SVD can be represented with formula A = USV. We are interested in the
|
// The SVD can be represented with formula A = USV. We are interested in the
|
||||||
// matrix S here because it represents the scale values.
|
// matrix S here because it represents the scale values.
|
||||||
Util.singularValueDecompose2dScale =
|
static singularValueDecompose2dScale(m) {
|
||||||
function Util_singularValueDecompose2dScale(m) {
|
const transpose = [m[0], m[2], m[1], m[3]];
|
||||||
|
|
||||||
var transpose = [m[0], m[2], m[1], m[3]];
|
|
||||||
|
|
||||||
// Multiply matrix m with its transpose.
|
// Multiply matrix m with its transpose.
|
||||||
var a = m[0] * transpose[0] + m[1] * transpose[2];
|
const a = m[0] * transpose[0] + m[1] * transpose[2];
|
||||||
var b = m[0] * transpose[1] + m[1] * transpose[3];
|
const b = m[0] * transpose[1] + m[1] * transpose[3];
|
||||||
var c = m[2] * transpose[0] + m[3] * transpose[2];
|
const c = m[2] * transpose[0] + m[3] * transpose[2];
|
||||||
var d = m[2] * transpose[1] + m[3] * transpose[3];
|
const d = m[2] * transpose[1] + m[3] * transpose[3];
|
||||||
|
|
||||||
// Solve the second degree polynomial to get roots.
|
// Solve the second degree polynomial to get roots.
|
||||||
var first = (a + d) / 2;
|
const first = (a + d) / 2;
|
||||||
var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
|
const second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
|
||||||
var sx = first + second || 1;
|
const sx = first + second || 1;
|
||||||
var sy = first - second || 1;
|
const sy = first - second || 1;
|
||||||
|
|
||||||
// Scale values are the square roots of the eigenvalues.
|
// Scale values are the square roots of the eigenvalues.
|
||||||
return [Math.sqrt(sx), Math.sqrt(sy)];
|
return [Math.sqrt(sx), Math.sqrt(sy)];
|
||||||
};
|
}
|
||||||
|
|
||||||
// Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
|
// Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
|
||||||
// For coordinate systems whose origin lies in the bottom-left, this
|
// For coordinate systems whose origin lies in the bottom-left, this
|
||||||
// means normalization to (BL,TR) ordering. For systems with origin in the
|
// means normalization to (BL,TR) ordering. For systems with origin in the
|
||||||
// top-left, this means (TL,BR) ordering.
|
// top-left, this means (TL,BR) ordering.
|
||||||
Util.normalizeRect = function Util_normalizeRect(rect) {
|
static normalizeRect(rect) {
|
||||||
var r = rect.slice(0); // clone rect
|
const r = rect.slice(0); // clone rect
|
||||||
if (rect[0] > rect[2]) {
|
if (rect[0] > rect[2]) {
|
||||||
r[0] = rect[2];
|
r[0] = rect[2];
|
||||||
r[2] = rect[0];
|
r[2] = rect[0];
|
||||||
@ -743,20 +736,20 @@ var Util = (function UtilClosure() {
|
|||||||
r[3] = rect[1];
|
r[3] = rect[1];
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Returns a rectangle [x1, y1, x2, y2] corresponding to the
|
// Returns a rectangle [x1, y1, x2, y2] corresponding to the
|
||||||
// intersection of rect1 and rect2. If no intersection, returns 'false'
|
// intersection of rect1 and rect2. If no intersection, returns 'false'
|
||||||
// The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
|
// The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
|
||||||
Util.intersect = function Util_intersect(rect1, rect2, skipEmpty = false) {
|
static intersect(rect1, rect2) {
|
||||||
function compare(a, b) {
|
function compare(a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order points along the axes
|
// Order points along the axes
|
||||||
var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
|
const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
|
||||||
orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
|
const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
|
||||||
result = [];
|
const result = [];
|
||||||
|
|
||||||
rect1 = Util.normalizeRect(rect1);
|
rect1 = Util.normalizeRect(rect1);
|
||||||
rect2 = Util.normalizeRect(rect2);
|
rect2 = Util.normalizeRect(rect2);
|
||||||
@ -781,15 +774,9 @@ var Util = (function UtilClosure() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skipEmpty &&
|
|
||||||
((result[2] - result[0]) === 0 || (result[3] - result[1]) === 0)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return Util;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const PDFStringTranslateTable = [
|
const PDFStringTranslateTable = [
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@ -804,16 +791,16 @@ const PDFStringTranslateTable = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function stringToPDFString(str) {
|
function stringToPDFString(str) {
|
||||||
var i, n = str.length, strBuf = [];
|
const length = str.length, strBuf = [];
|
||||||
if (str[0] === '\xFE' && str[1] === '\xFF') {
|
if (str[0] === '\xFE' && str[1] === '\xFF') {
|
||||||
// UTF16BE BOM
|
// UTF16BE BOM
|
||||||
for (i = 2; i < n; i += 2) {
|
for (let i = 2; i < length; i += 2) {
|
||||||
strBuf.push(String.fromCharCode(
|
strBuf.push(String.fromCharCode(
|
||||||
(str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
|
(str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < n; ++i) {
|
for (let i = 0; i < length; ++i) {
|
||||||
var code = PDFStringTranslateTable[str.charCodeAt(i)];
|
const code = PDFStringTranslateTable[str.charCodeAt(i)];
|
||||||
strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
|
strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -829,7 +816,7 @@ function utf8StringToString(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isEmptyObj(obj) {
|
function isEmptyObj(obj) {
|
||||||
for (var key in obj) {
|
for (let key in obj) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -903,9 +890,9 @@ function createPromiseCapability() {
|
|||||||
return capability;
|
return capability;
|
||||||
}
|
}
|
||||||
|
|
||||||
var createObjectURL = (function createObjectURLClosure() {
|
const createObjectURL = (function createObjectURLClosure() {
|
||||||
// Blob/createObjectURL is not available, falling back to data schema.
|
// Blob/createObjectURL is not available, falling back to data schema.
|
||||||
var digits =
|
const digits =
|
||||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||||
|
|
||||||
return function createObjectURL(data, contentType, forceDataSchema = false) {
|
return function createObjectURL(data, contentType, forceDataSchema = false) {
|
||||||
@ -914,14 +901,14 @@ var createObjectURL = (function createObjectURLClosure() {
|
|||||||
return URL.createObjectURL(blob);
|
return URL.createObjectURL(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
var buffer = 'data:' + contentType + ';base64,';
|
let buffer = `data:${contentType};base64,`;
|
||||||
for (var i = 0, ii = data.length; i < ii; i += 3) {
|
for (let i = 0, ii = data.length; i < ii; i += 3) {
|
||||||
var b1 = data[i] & 0xFF;
|
const b1 = data[i] & 0xFF;
|
||||||
var b2 = data[i + 1] & 0xFF;
|
const b2 = data[i + 1] & 0xFF;
|
||||||
var b3 = data[i + 2] & 0xFF;
|
const b3 = data[i + 2] & 0xFF;
|
||||||
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
const d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
||||||
var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
|
const d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
|
||||||
var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
|
const d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
|
||||||
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user