Merge pull request #10577 from Snuffleupagus/util-split
Move worker-thread only functions from `src/shared/util.js` and into a new `src/core/core_utils.js` file
This commit is contained in:
commit
de56518799
@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag,
|
AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag,
|
||||||
AnnotationType, getInheritableProperty, OPS, stringToBytes, stringToPDFString,
|
AnnotationType, OPS, stringToBytes, stringToPDFString, Util, warn
|
||||||
Util, warn
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { Catalog, FileSpec, ObjectLoader } from './obj';
|
import { Catalog, FileSpec, ObjectLoader } from './obj';
|
||||||
import { Dict, isDict, isName, isRef, isStream } from './primitives';
|
import { Dict, isDict, isName, isRef, isStream } from './primitives';
|
||||||
import { ColorSpace } from './colorspace';
|
import { ColorSpace } from './colorspace';
|
||||||
|
import { getInheritableProperty } from './core_utils';
|
||||||
import { OperatorList } from './operator_list';
|
import { OperatorList } from './operator_list';
|
||||||
import { Stream } from './stream';
|
import { Stream } from './stream';
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
arrayByteLength, arraysToBytes, createPromiseCapability, isEmptyObj,
|
arrayByteLength, arraysToBytes, createPromiseCapability, isEmptyObj
|
||||||
MissingDataException
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
|
import { MissingDataException } from './core_utils';
|
||||||
|
|
||||||
class ChunkedStream {
|
class ChunkedStream {
|
||||||
constructor(length, chunkSize, manager) {
|
constructor(length, chunkSize, manager) {
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CMapCompressionType, FormatError, isString, MissingDataException, unreachable,
|
CMapCompressionType, FormatError, isString, unreachable, warn
|
||||||
warn
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { isCmd, isEOF, isName, isStream } from './primitives';
|
import { isCmd, isEOF, isName, isStream } from './primitives';
|
||||||
import { Lexer } from './parser';
|
import { Lexer } from './parser';
|
||||||
|
import { MissingDataException } from './core_utils';
|
||||||
import { Stream } from './stream';
|
import { Stream } from './stream';
|
||||||
|
|
||||||
var BUILT_IN_CMAPS = [
|
var BUILT_IN_CMAPS = [
|
||||||
|
160
src/core/core_utils.js
Normal file
160
src/core/core_utils.js
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/* Copyright 2019 Mozilla Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/* eslint no-var: error */
|
||||||
|
|
||||||
|
import { assert, warn } from '../shared/util';
|
||||||
|
|
||||||
|
function getLookupTableFactory(initializer) {
|
||||||
|
let lookup;
|
||||||
|
return function() {
|
||||||
|
if (initializer) {
|
||||||
|
lookup = Object.create(null);
|
||||||
|
initializer(lookup);
|
||||||
|
initializer = null;
|
||||||
|
}
|
||||||
|
return lookup;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const MissingDataException = (function MissingDataExceptionClosure() {
|
||||||
|
function MissingDataException(begin, end) {
|
||||||
|
this.begin = begin;
|
||||||
|
this.end = end;
|
||||||
|
this.message = `Missing data [${begin}, ${end})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
MissingDataException.prototype = new Error();
|
||||||
|
MissingDataException.prototype.name = 'MissingDataException';
|
||||||
|
MissingDataException.constructor = MissingDataException;
|
||||||
|
|
||||||
|
return MissingDataException;
|
||||||
|
})();
|
||||||
|
|
||||||
|
const XRefEntryException = (function XRefEntryExceptionClosure() {
|
||||||
|
function XRefEntryException(msg) {
|
||||||
|
this.message = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
XRefEntryException.prototype = new Error();
|
||||||
|
XRefEntryException.prototype.name = 'XRefEntryException';
|
||||||
|
XRefEntryException.constructor = XRefEntryException;
|
||||||
|
|
||||||
|
return XRefEntryException;
|
||||||
|
})();
|
||||||
|
|
||||||
|
const XRefParseException = (function XRefParseExceptionClosure() {
|
||||||
|
function XRefParseException(msg) {
|
||||||
|
this.message = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
XRefParseException.prototype = new Error();
|
||||||
|
XRefParseException.prototype.name = 'XRefParseException';
|
||||||
|
XRefParseException.constructor = XRefParseException;
|
||||||
|
|
||||||
|
return XRefParseException;
|
||||||
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of an inheritable property.
|
||||||
|
*
|
||||||
|
* If the PDF specification explicitly lists a property in a dictionary as
|
||||||
|
* inheritable, then the value of the property may be present in the dictionary
|
||||||
|
* itself or in one or more parents of the dictionary.
|
||||||
|
*
|
||||||
|
* If the key is not found in the tree, `undefined` is returned. Otherwise,
|
||||||
|
* the value for the key is returned or, if `stopWhenFound` is `false`, a list
|
||||||
|
* of values is returned. To avoid infinite loops, the traversal is stopped when
|
||||||
|
* the loop limit is reached.
|
||||||
|
*
|
||||||
|
* @param {Dict} dict - Dictionary from where to start the traversal.
|
||||||
|
* @param {string} key - The key of the property to find the value for.
|
||||||
|
* @param {boolean} getArray - Whether or not the value should be fetched as an
|
||||||
|
* array. The default value is `false`.
|
||||||
|
* @param {boolean} stopWhenFound - Whether or not to stop the traversal when
|
||||||
|
* the key is found. If set to `false`, we always walk up the entire parent
|
||||||
|
* chain, for example to be able to find `\Resources` placed on multiple
|
||||||
|
* levels of the tree. The default value is `true`.
|
||||||
|
*/
|
||||||
|
function getInheritableProperty({ dict, key, getArray = false,
|
||||||
|
stopWhenFound = true, }) {
|
||||||
|
const LOOP_LIMIT = 100;
|
||||||
|
let loopCount = 0;
|
||||||
|
let values;
|
||||||
|
|
||||||
|
while (dict) {
|
||||||
|
const value = getArray ? dict.getArray(key) : dict.get(key);
|
||||||
|
if (value !== undefined) {
|
||||||
|
if (stopWhenFound) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (!values) {
|
||||||
|
values = [];
|
||||||
|
}
|
||||||
|
values.push(value);
|
||||||
|
}
|
||||||
|
if (++loopCount > LOOP_LIMIT) {
|
||||||
|
warn(`getInheritableProperty: maximum loop count exceeded for "${key}"`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dict = dict.get('Parent');
|
||||||
|
}
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ROMAN_NUMBER_MAP = [
|
||||||
|
'', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
|
||||||
|
'', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
|
||||||
|
'', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts positive integers to (upper case) Roman numerals.
|
||||||
|
* @param {integer} number - The number that should be converted.
|
||||||
|
* @param {boolean} lowerCase - Indicates if the result should be converted
|
||||||
|
* to lower case letters. The default value is `false`.
|
||||||
|
* @return {string} The resulting Roman number.
|
||||||
|
*/
|
||||||
|
function toRomanNumerals(number, lowerCase = false) {
|
||||||
|
assert(Number.isInteger(number) && number > 0,
|
||||||
|
'The number should be a positive integer.');
|
||||||
|
let pos, romanBuf = [];
|
||||||
|
// Thousands
|
||||||
|
while (number >= 1000) {
|
||||||
|
number -= 1000;
|
||||||
|
romanBuf.push('M');
|
||||||
|
}
|
||||||
|
// Hundreds
|
||||||
|
pos = (number / 100) | 0;
|
||||||
|
number %= 100;
|
||||||
|
romanBuf.push(ROMAN_NUMBER_MAP[pos]);
|
||||||
|
// Tens
|
||||||
|
pos = (number / 10) | 0;
|
||||||
|
number %= 10;
|
||||||
|
romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
|
||||||
|
// Ones
|
||||||
|
romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
|
||||||
|
|
||||||
|
const romanStr = romanBuf.join('');
|
||||||
|
return (lowerCase ? romanStr.toLowerCase() : romanStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
getLookupTableFactory,
|
||||||
|
MissingDataException,
|
||||||
|
XRefEntryException,
|
||||||
|
XRefParseException,
|
||||||
|
getInheritableProperty,
|
||||||
|
toRomanNumerals,
|
||||||
|
};
|
@ -15,12 +15,15 @@
|
|||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, FormatError, getInheritableProperty, info, isArrayBuffer, isBool,
|
assert, FormatError, info, isArrayBuffer, isBool, isNum, isSpace, isString,
|
||||||
isNum, isSpace, isString, MissingDataException, OPS, shadow, stringToBytes,
|
OPS, shadow, stringToBytes, stringToPDFString, Util, warn
|
||||||
stringToPDFString, Util, warn, XRefEntryException, XRefParseException
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { Catalog, ObjectLoader, XRef } from './obj';
|
import { Catalog, ObjectLoader, XRef } from './obj';
|
||||||
import { Dict, isDict, isName, isStream, Ref } from './primitives';
|
import { Dict, isDict, isName, isStream, Ref } from './primitives';
|
||||||
|
import {
|
||||||
|
getInheritableProperty, MissingDataException, XRefEntryException,
|
||||||
|
XRefParseException
|
||||||
|
} from './core_utils';
|
||||||
import { NullStream, Stream, StreamsSequenceStream } from './stream';
|
import { NullStream, Stream, StreamsSequenceStream } from './stream';
|
||||||
import { AnnotationFactory } from './annotation';
|
import { AnnotationFactory } from './annotation';
|
||||||
import { calculateMD5 } from './crypto';
|
import { calculateMD5 } from './crypto';
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
AbortException, assert, CMapCompressionType, createPromiseCapability,
|
AbortException, assert, CMapCompressionType, createPromiseCapability,
|
||||||
FONT_IDENTITY_MATRIX, FormatError, getLookupTableFactory, IDENTITY_MATRIX,
|
FONT_IDENTITY_MATRIX, FormatError, IDENTITY_MATRIX, info, isNum, isString,
|
||||||
info, isNum, isString, NativeImageDecoding, OPS, stringToPDFString,
|
NativeImageDecoding, OPS, stringToPDFString, TextRenderingMode,
|
||||||
TextRenderingMode, UNSUPPORTED_FEATURES, Util, warn
|
UNSUPPORTED_FEATURES, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { CMapFactory, IdentityCMap } from './cmap';
|
import { CMapFactory, IdentityCMap } from './cmap';
|
||||||
import { DecodeStream, Stream } from './stream';
|
import { DecodeStream, Stream } from './stream';
|
||||||
@ -42,6 +42,7 @@ import { Lexer, Parser } from './parser';
|
|||||||
import { bidi } from './bidi';
|
import { bidi } from './bidi';
|
||||||
import { ColorSpace } from './colorspace';
|
import { ColorSpace } from './colorspace';
|
||||||
import { getGlyphsUnicode } from './glyphlist';
|
import { getGlyphsUnicode } from './glyphlist';
|
||||||
|
import { getLookupTableFactory } from './core_utils';
|
||||||
import { getMetrics } from './metrics';
|
import { getMetrics } from './metrics';
|
||||||
import { isPDFFunction } from './function';
|
import { isPDFFunction } from './function';
|
||||||
import { JpegStream } from './jpeg_stream';
|
import { JpegStream } from './jpeg_stream';
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
assert, bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info,
|
assert, bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info,
|
||||||
isNum, isSpace, MissingDataException, readUint32, shadow, string32,
|
isNum, isSpace, readUint32, shadow, string32, unreachable, warn
|
||||||
unreachable, warn
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict,
|
CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict,
|
||||||
@ -36,6 +35,7 @@ import {
|
|||||||
} from './unicode';
|
} from './unicode';
|
||||||
import { FontRendererFactory } from './font_renderer';
|
import { FontRendererFactory } from './font_renderer';
|
||||||
import { IdentityCMap } from './cmap';
|
import { IdentityCMap } from './cmap';
|
||||||
|
import { MissingDataException } from './core_utils';
|
||||||
import { Stream } from './stream';
|
import { Stream } from './stream';
|
||||||
import { Type1Parser } from './type1_parser';
|
import { Type1Parser } from './type1_parser';
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
/* no-babel-preset */
|
/* no-babel-preset */
|
||||||
|
|
||||||
var getLookupTableFactory = require('../shared/util').getLookupTableFactory;
|
var getLookupTableFactory = require('./core_utils').getLookupTableFactory;
|
||||||
|
|
||||||
var getGlyphsUnicode = getLookupTableFactory(function (t) {
|
var getGlyphsUnicode = getLookupTableFactory(function (t) {
|
||||||
t['A'] = 0x0041;
|
t['A'] = 0x0041;
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getLookupTableFactory } from '../shared/util';
|
import { getLookupTableFactory } from './core_utils';
|
||||||
|
|
||||||
// The Metrics object contains glyph widths (in glyph space units).
|
// The Metrics object contains glyph widths (in glyph space units).
|
||||||
// As per PDF spec, for most fonts (Type 3 being an exception) a glyph
|
// As per PDF spec, for most fonts (Type 3 being an exception) a glyph
|
||||||
|
@ -15,15 +15,17 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError,
|
bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError,
|
||||||
info, InvalidPDFException, isBool, isNum, isString, MissingDataException,
|
info, InvalidPDFException, isBool, isNum, isString, PermissionFlag, shadow,
|
||||||
PermissionFlag, shadow, stringToPDFString, stringToUTF8String,
|
stringToPDFString, stringToUTF8String, unreachable, warn
|
||||||
toRomanNumerals, unreachable, warn, XRefEntryException, XRefParseException
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
Dict, isCmd, isDict, isName, isRef, isRefsEqual, isStream, Ref, RefSet,
|
Dict, isCmd, isDict, isName, isRef, isRefsEqual, isStream, Ref, RefSet,
|
||||||
RefSetCache
|
RefSetCache
|
||||||
} from './primitives';
|
} from './primitives';
|
||||||
import { Lexer, Parser } from './parser';
|
import { Lexer, Parser } from './parser';
|
||||||
|
import {
|
||||||
|
MissingDataException, toRomanNumerals, XRefEntryException, XRefParseException
|
||||||
|
} from './core_utils';
|
||||||
import { ChunkedStream } from './chunked_stream';
|
import { ChunkedStream } from './chunked_stream';
|
||||||
import { CipherTransformFactory } from './crypto';
|
import { CipherTransformFactory } from './crypto';
|
||||||
import { ColorSpace } from './colorspace';
|
import { ColorSpace } from './colorspace';
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
} from './stream';
|
} from './stream';
|
||||||
import {
|
import {
|
||||||
assert, bytesToString, FormatError, info, isNum, isSpace, isString,
|
assert, bytesToString, FormatError, info, isNum, isSpace, isString,
|
||||||
MissingDataException, StreamType, warn
|
StreamType, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
Cmd, Dict, EOF, isCmd, isDict, isEOF, isName, Name, Ref
|
Cmd, Dict, EOF, isCmd, isDict, isEOF, isName, Name, Ref
|
||||||
@ -28,6 +28,7 @@ import { CCITTFaxStream } from './ccitt_stream';
|
|||||||
import { Jbig2Stream } from './jbig2_stream';
|
import { Jbig2Stream } from './jbig2_stream';
|
||||||
import { JpegStream } from './jpeg_stream';
|
import { JpegStream } from './jpeg_stream';
|
||||||
import { JpxStream } from './jpx_stream';
|
import { JpxStream } from './jpx_stream';
|
||||||
|
import { MissingDataException } from './core_utils';
|
||||||
|
|
||||||
const MAX_LENGTH_TO_CACHE = 1000;
|
const MAX_LENGTH_TO_CACHE = 1000;
|
||||||
const MAX_ADLER32_LENGTH = 5552;
|
const MAX_ADLER32_LENGTH = 5552;
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
/* eslint-disable no-multi-spaces */
|
/* eslint-disable no-multi-spaces */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, FormatError, info, MissingDataException, unreachable,
|
assert, FormatError, info, unreachable, UNSUPPORTED_FEATURES, Util, warn
|
||||||
UNSUPPORTED_FEATURES, Util, warn
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { ColorSpace } from './colorspace';
|
import { ColorSpace } from './colorspace';
|
||||||
import { isStream } from './primitives';
|
import { isStream } from './primitives';
|
||||||
|
import { MissingDataException } from './core_utils';
|
||||||
|
|
||||||
var ShadingType = {
|
var ShadingType = {
|
||||||
FUNCTION_BASED: 1,
|
FUNCTION_BASED: 1,
|
||||||
|
@ -14,9 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createValidAbsoluteUrl, MissingDataException, shadow, unreachable, warn
|
createValidAbsoluteUrl, shadow, unreachable, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { ChunkedStreamManager } from './chunked_stream';
|
import { ChunkedStreamManager } from './chunked_stream';
|
||||||
|
import { MissingDataException } from './core_utils';
|
||||||
import { PDFDocument } from './document';
|
import { PDFDocument } from './document';
|
||||||
import { Stream } from './stream';
|
import { Stream } from './stream';
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import { getLookupTableFactory } from '../shared/util';
|
import { getLookupTableFactory } from './core_utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hold a map of decoded fonts and of the standard fourteen Type1
|
* Hold a map of decoded fonts and of the standard fourteen Type1
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
/* no-babel-preset */
|
/* no-babel-preset */
|
||||||
|
|
||||||
var getLookupTableFactory = require('../shared/util').getLookupTableFactory;
|
var getLookupTableFactory = require('./core_utils').getLookupTableFactory;
|
||||||
|
|
||||||
// Some characters, e.g. copyrightserif, are mapped to the private use area
|
// Some characters, e.g. copyrightserif, are mapped to the private use area
|
||||||
// and might not be displayed using standard fonts. Mapping/hacking well-known
|
// and might not be displayed using standard fonts. Mapping/hacking well-known
|
||||||
|
@ -17,12 +17,13 @@ import {
|
|||||||
arrayByteLength, arraysToBytes, assert, createPromiseCapability, info,
|
arrayByteLength, arraysToBytes, assert, createPromiseCapability, info,
|
||||||
InvalidPDFException, MissingPDFException, PasswordException,
|
InvalidPDFException, MissingPDFException, PasswordException,
|
||||||
setVerbosityLevel, UnexpectedResponseException, UnknownErrorException,
|
setVerbosityLevel, UnexpectedResponseException, UnknownErrorException,
|
||||||
UNSUPPORTED_FEATURES, warn, XRefParseException
|
UNSUPPORTED_FEATURES, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
||||||
import isNodeJS from '../shared/is_node';
|
import isNodeJS from '../shared/is_node';
|
||||||
import { MessageHandler } from '../shared/message_handler';
|
import { MessageHandler } from '../shared/message_handler';
|
||||||
import { Ref } from './primitives';
|
import { Ref } from './primitives';
|
||||||
|
import { XRefParseException } from './core_utils';
|
||||||
|
|
||||||
var WorkerTask = (function WorkerTaskClosure() {
|
var WorkerTask = (function WorkerTaskClosure() {
|
||||||
function WorkerTask(name) {
|
function WorkerTask(name) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
addLinkAttributes, DOMSVGFactory, getFilenameFromUrl, LinkTarget
|
addLinkAttributes, DOMSVGFactory, getFilenameFromUrl, LinkTarget
|
||||||
} from './dom_utils';
|
} from './display_utils';
|
||||||
import {
|
import {
|
||||||
AnnotationBorderStyleType, AnnotationType, stringToPDFString, unreachable,
|
AnnotationBorderStyleType, AnnotationType, stringToPDFString, unreachable,
|
||||||
Util, warn
|
Util, warn
|
||||||
|
@ -25,7 +25,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, loadScript,
|
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, loadScript,
|
||||||
PageViewport, RenderingCancelledException, StatTimer
|
PageViewport, RenderingCancelledException, StatTimer
|
||||||
} from './dom_utils';
|
} from './display_utils';
|
||||||
import { FontFaceObject, FontLoader } from './font_loader';
|
import { FontFaceObject, FontLoader } from './font_loader';
|
||||||
import { apiCompatibilityParams } from './api_compatibility';
|
import { apiCompatibilityParams } from './api_compatibility';
|
||||||
import { CanvasGraphics } from './canvas';
|
import { CanvasGraphics } from './canvas';
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
createObjectURL, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, isNum, OPS,
|
createObjectURL, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, isNum, OPS,
|
||||||
TextRenderingMode, Util, warn
|
TextRenderingMode, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { DOMSVGFactory } from './dom_utils';
|
import { DOMSVGFactory } from './display_utils';
|
||||||
import isNodeJS from '../shared/is_node';
|
import isNodeJS from '../shared/is_node';
|
||||||
|
|
||||||
var SVGGraphics = function() {
|
var SVGGraphics = function() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2018 Mozilla Foundation
|
/* Copyright 2019 Mozilla Foundation
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @licstart The following is the entire license notice for the
|
* @licstart The following is the entire license notice for the
|
||||||
* Javascript code in this page
|
* Javascript code in this page
|
||||||
*
|
*
|
||||||
* Copyright 2018 Mozilla Foundation
|
* Copyright 2019 Mozilla Foundation
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
12
src/pdf.js
12
src/pdf.js
@ -25,7 +25,7 @@ var pdfjsSharedUtil = require('./shared/util.js');
|
|||||||
var pdfjsDisplayAPI = require('./display/api.js');
|
var pdfjsDisplayAPI = require('./display/api.js');
|
||||||
var pdfjsDisplayTextLayer = require('./display/text_layer.js');
|
var pdfjsDisplayTextLayer = require('./display/text_layer.js');
|
||||||
var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
|
var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
|
||||||
var pdfjsDisplayDOMUtils = require('./display/dom_utils.js');
|
var pdfjsDisplayDisplayUtils = require('./display/display_utils.js');
|
||||||
var pdfjsDisplaySVG = require('./display/svg.js');
|
var pdfjsDisplaySVG = require('./display/svg.js');
|
||||||
let pdfjsDisplayWorkerOptions = require('./display/worker_options.js');
|
let pdfjsDisplayWorkerOptions = require('./display/worker_options.js');
|
||||||
let pdfjsDisplayAPICompatibility = require('./display/api_compatibility.js');
|
let pdfjsDisplayAPICompatibility = require('./display/api_compatibility.js');
|
||||||
@ -107,11 +107,11 @@ exports.Util = pdfjsSharedUtil.Util;
|
|||||||
exports.ReadableStream = pdfjsSharedUtil.ReadableStream;
|
exports.ReadableStream = pdfjsSharedUtil.ReadableStream;
|
||||||
exports.URL = pdfjsSharedUtil.URL;
|
exports.URL = pdfjsSharedUtil.URL;
|
||||||
exports.RenderingCancelledException =
|
exports.RenderingCancelledException =
|
||||||
pdfjsDisplayDOMUtils.RenderingCancelledException;
|
pdfjsDisplayDisplayUtils.RenderingCancelledException;
|
||||||
exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
|
exports.getFilenameFromUrl = pdfjsDisplayDisplayUtils.getFilenameFromUrl;
|
||||||
exports.LinkTarget = pdfjsDisplayDOMUtils.LinkTarget;
|
exports.LinkTarget = pdfjsDisplayDisplayUtils.LinkTarget;
|
||||||
exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
|
exports.addLinkAttributes = pdfjsDisplayDisplayUtils.addLinkAttributes;
|
||||||
exports.loadScript = pdfjsDisplayDOMUtils.loadScript;
|
exports.loadScript = pdfjsDisplayDisplayUtils.loadScript;
|
||||||
exports.GlobalWorkerOptions = pdfjsDisplayWorkerOptions.GlobalWorkerOptions;
|
exports.GlobalWorkerOptions = pdfjsDisplayWorkerOptions.GlobalWorkerOptions;
|
||||||
exports.apiCompatibilityParams =
|
exports.apiCompatibilityParams =
|
||||||
pdfjsDisplayAPICompatibility.apiCompatibilityParams;
|
pdfjsDisplayAPICompatibility.apiCompatibilityParams;
|
||||||
|
@ -382,18 +382,6 @@ function shadow(obj, prop, value) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLookupTableFactory(initializer) {
|
|
||||||
var lookup;
|
|
||||||
return function () {
|
|
||||||
if (initializer) {
|
|
||||||
lookup = Object.create(null);
|
|
||||||
initializer(lookup);
|
|
||||||
initializer = null;
|
|
||||||
}
|
|
||||||
return lookup;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var PasswordException = (function PasswordExceptionClosure() {
|
var PasswordException = (function PasswordExceptionClosure() {
|
||||||
function PasswordException(msg, code) {
|
function PasswordException(msg, code) {
|
||||||
this.name = 'PasswordException';
|
this.name = 'PasswordException';
|
||||||
@ -458,44 +446,6 @@ var UnexpectedResponseException =
|
|||||||
return UnexpectedResponseException;
|
return UnexpectedResponseException;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var MissingDataException = (function MissingDataExceptionClosure() {
|
|
||||||
function MissingDataException(begin, end) {
|
|
||||||
this.begin = begin;
|
|
||||||
this.end = end;
|
|
||||||
this.message = 'Missing data [' + begin + ', ' + end + ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
MissingDataException.prototype = new Error();
|
|
||||||
MissingDataException.prototype.name = 'MissingDataException';
|
|
||||||
MissingDataException.constructor = MissingDataException;
|
|
||||||
|
|
||||||
return MissingDataException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const XRefEntryException = (function XRefEntryExceptionClosure() {
|
|
||||||
function XRefEntryException(msg) {
|
|
||||||
this.message = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
XRefEntryException.prototype = new Error();
|
|
||||||
XRefEntryException.prototype.name = 'XRefEntryException';
|
|
||||||
XRefEntryException.constructor = XRefEntryException;
|
|
||||||
|
|
||||||
return XRefEntryException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
var XRefParseException = (function XRefParseExceptionClosure() {
|
|
||||||
function XRefParseException(msg) {
|
|
||||||
this.message = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
XRefParseException.prototype = new Error();
|
|
||||||
XRefParseException.prototype.name = 'XRefParseException';
|
|
||||||
XRefParseException.constructor = XRefParseException;
|
|
||||||
|
|
||||||
return XRefParseException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error caused during parsing PDF data.
|
* Error caused during parsing PDF data.
|
||||||
*/
|
*/
|
||||||
@ -659,53 +609,6 @@ function isEvalSupported() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the value of an inheritable property.
|
|
||||||
*
|
|
||||||
* If the PDF specification explicitly lists a property in a dictionary as
|
|
||||||
* inheritable, then the value of the property may be present in the dictionary
|
|
||||||
* itself or in one or more parents of the dictionary.
|
|
||||||
*
|
|
||||||
* If the key is not found in the tree, `undefined` is returned. Otherwise,
|
|
||||||
* the value for the key is returned or, if `stopWhenFound` is `false`, a list
|
|
||||||
* of values is returned. To avoid infinite loops, the traversal is stopped when
|
|
||||||
* the loop limit is reached.
|
|
||||||
*
|
|
||||||
* @param {Dict} dict - Dictionary from where to start the traversal.
|
|
||||||
* @param {string} key - The key of the property to find the value for.
|
|
||||||
* @param {boolean} getArray - Whether or not the value should be fetched as an
|
|
||||||
* array. The default value is `false`.
|
|
||||||
* @param {boolean} stopWhenFound - Whether or not to stop the traversal when
|
|
||||||
* the key is found. If set to `false`, we always walk up the entire parent
|
|
||||||
* chain, for example to be able to find `\Resources` placed on multiple
|
|
||||||
* levels of the tree. The default value is `true`.
|
|
||||||
*/
|
|
||||||
function getInheritableProperty({ dict, key, getArray = false,
|
|
||||||
stopWhenFound = true, }) {
|
|
||||||
const LOOP_LIMIT = 100;
|
|
||||||
let loopCount = 0;
|
|
||||||
let values;
|
|
||||||
|
|
||||||
while (dict) {
|
|
||||||
const value = getArray ? dict.getArray(key) : dict.get(key);
|
|
||||||
if (value !== undefined) {
|
|
||||||
if (stopWhenFound) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
if (!values) {
|
|
||||||
values = [];
|
|
||||||
}
|
|
||||||
values.push(value);
|
|
||||||
}
|
|
||||||
if (++loopCount > LOOP_LIMIT) {
|
|
||||||
warn(`getInheritableProperty: maximum loop count exceeded for "${key}"`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
dict = dict.get('Parent');
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
var Util = (function UtilClosure() {
|
var Util = (function UtilClosure() {
|
||||||
function Util() {}
|
function Util() {}
|
||||||
|
|
||||||
@ -866,43 +769,6 @@ var Util = (function UtilClosure() {
|
|||||||
return Util;
|
return Util;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const ROMAN_NUMBER_MAP = [
|
|
||||||
'', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
|
|
||||||
'', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
|
|
||||||
'', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts positive integers to (upper case) Roman numerals.
|
|
||||||
* @param {integer} number - The number that should be converted.
|
|
||||||
* @param {boolean} lowerCase - Indicates if the result should be converted
|
|
||||||
* to lower case letters. The default value is `false`.
|
|
||||||
* @return {string} The resulting Roman number.
|
|
||||||
*/
|
|
||||||
function toRomanNumerals(number, lowerCase = false) {
|
|
||||||
assert(Number.isInteger(number) && number > 0,
|
|
||||||
'The number should be a positive integer.');
|
|
||||||
let pos, romanBuf = [];
|
|
||||||
// Thousands
|
|
||||||
while (number >= 1000) {
|
|
||||||
number -= 1000;
|
|
||||||
romanBuf.push('M');
|
|
||||||
}
|
|
||||||
// Hundreds
|
|
||||||
pos = (number / 100) | 0;
|
|
||||||
number %= 100;
|
|
||||||
romanBuf.push(ROMAN_NUMBER_MAP[pos]);
|
|
||||||
// Tens
|
|
||||||
pos = (number / 10) | 0;
|
|
||||||
number %= 10;
|
|
||||||
romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
|
|
||||||
// Ones
|
|
||||||
romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
|
|
||||||
|
|
||||||
const romanStr = romanBuf.join('');
|
|
||||||
return (lowerCase ? romanStr.toLowerCase() : romanStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
||||||
0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
|
0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@ -1046,7 +912,6 @@ export {
|
|||||||
CMapCompressionType,
|
CMapCompressionType,
|
||||||
AbortException,
|
AbortException,
|
||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
MissingDataException,
|
|
||||||
MissingPDFException,
|
MissingPDFException,
|
||||||
NativeImageDecoding,
|
NativeImageDecoding,
|
||||||
PasswordException,
|
PasswordException,
|
||||||
@ -1057,9 +922,6 @@ export {
|
|||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
UnknownErrorException,
|
UnknownErrorException,
|
||||||
Util,
|
Util,
|
||||||
toRomanNumerals,
|
|
||||||
XRefEntryException,
|
|
||||||
XRefParseException,
|
|
||||||
FormatError,
|
FormatError,
|
||||||
arrayByteLength,
|
arrayByteLength,
|
||||||
arraysToBytes,
|
arraysToBytes,
|
||||||
@ -1068,8 +930,6 @@ export {
|
|||||||
createPromiseCapability,
|
createPromiseCapability,
|
||||||
createObjectURL,
|
createObjectURL,
|
||||||
deprecated,
|
deprecated,
|
||||||
getInheritableProperty,
|
|
||||||
getLookupTableFactory,
|
|
||||||
getVerbosityLevel,
|
getVerbosityLevel,
|
||||||
info,
|
info,
|
||||||
isArrayBuffer,
|
isArrayBuffer,
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
} from '../../src/shared/util';
|
} from '../../src/shared/util';
|
||||||
import {
|
import {
|
||||||
DOMCanvasFactory, RenderingCancelledException, StatTimer
|
DOMCanvasFactory, RenderingCancelledException, StatTimer
|
||||||
} from '../../src/display/dom_utils';
|
} from '../../src/display/display_utils';
|
||||||
import {
|
import {
|
||||||
getDocument, PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy, PDFWorker
|
getDocument, PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy, PDFWorker
|
||||||
} from '../../src/display/api';
|
} from '../../src/display/api';
|
||||||
|
@ -12,10 +12,11 @@
|
|||||||
"cff_parser_spec.js",
|
"cff_parser_spec.js",
|
||||||
"cmap_spec.js",
|
"cmap_spec.js",
|
||||||
"colorspace_spec.js",
|
"colorspace_spec.js",
|
||||||
|
"core_utils_spec.js",
|
||||||
"crypto_spec.js",
|
"crypto_spec.js",
|
||||||
"display_svg_spec.js",
|
"display_svg_spec.js",
|
||||||
|
"display_utils_spec.js",
|
||||||
"document_spec.js",
|
"document_spec.js",
|
||||||
"dom_utils_spec.js",
|
|
||||||
"encodings_spec.js",
|
"encodings_spec.js",
|
||||||
"evaluator_spec.js",
|
"evaluator_spec.js",
|
||||||
"function_spec.js",
|
"function_spec.js",
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CMap, CMapFactory, IdentityCMap } from '../../src/core/cmap';
|
import { CMap, CMapFactory, IdentityCMap } from '../../src/core/cmap';
|
||||||
import { DOMCMapReaderFactory } from '../../src/display/dom_utils';
|
import { DOMCMapReaderFactory } from '../../src/display/display_utils';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import isNodeJS from '../../src/shared/is_node';
|
||||||
import { Name } from '../../src/core/primitives';
|
import { Name } from '../../src/core/primitives';
|
||||||
import { NodeCMapReaderFactory } from './test_utils';
|
import { NodeCMapReaderFactory } from './test_utils';
|
||||||
|
158
test/unit/core_utils_spec.js
Normal file
158
test/unit/core_utils_spec.js
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/* Copyright 2019 Mozilla Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Dict, Ref } from '../../src/core/primitives';
|
||||||
|
import {
|
||||||
|
getInheritableProperty, toRomanNumerals
|
||||||
|
} from '../../src/core/core_utils';
|
||||||
|
import { XRefMock } from './test_utils';
|
||||||
|
|
||||||
|
describe('core_utils', function() {
|
||||||
|
describe('getInheritableProperty', function() {
|
||||||
|
it('handles non-dictionary arguments', function() {
|
||||||
|
expect(getInheritableProperty({ dict: null, key: 'foo', }))
|
||||||
|
.toEqual(undefined);
|
||||||
|
expect(getInheritableProperty({ dict: undefined, key: 'foo', }))
|
||||||
|
.toEqual(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles dictionaries that do not contain the property', function() {
|
||||||
|
// Empty dictionary.
|
||||||
|
const emptyDict = new Dict();
|
||||||
|
expect(getInheritableProperty({ dict: emptyDict, key: 'foo', }))
|
||||||
|
.toEqual(undefined);
|
||||||
|
|
||||||
|
// Filled dictionary with a different property.
|
||||||
|
const filledDict = new Dict();
|
||||||
|
filledDict.set('bar', 'baz');
|
||||||
|
expect(getInheritableProperty({ dict: filledDict, key: 'foo', }))
|
||||||
|
.toEqual(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fetches the property if it is not inherited', function() {
|
||||||
|
const ref = new Ref(10, 0);
|
||||||
|
const xref = new XRefMock([{ ref, data: 'quux', }]);
|
||||||
|
const dict = new Dict(xref);
|
||||||
|
|
||||||
|
// Regular values should be fetched.
|
||||||
|
dict.set('foo', 'bar');
|
||||||
|
expect(getInheritableProperty({ dict, key: 'foo', })).toEqual('bar');
|
||||||
|
|
||||||
|
// Array value should be fetched (with references resolved).
|
||||||
|
dict.set('baz', ['qux', ref]);
|
||||||
|
expect(getInheritableProperty({ dict, key: 'baz', getArray: true, }))
|
||||||
|
.toEqual(['qux', 'quux']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fetches the property if it is inherited and present on one level',
|
||||||
|
function() {
|
||||||
|
const ref = new Ref(10, 0);
|
||||||
|
const xref = new XRefMock([{ ref, data: 'quux', }]);
|
||||||
|
const firstDict = new Dict(xref);
|
||||||
|
const secondDict = new Dict(xref);
|
||||||
|
firstDict.set('Parent', secondDict);
|
||||||
|
|
||||||
|
// Regular values should be fetched.
|
||||||
|
secondDict.set('foo', 'bar');
|
||||||
|
expect(getInheritableProperty({ dict: firstDict, key: 'foo', }))
|
||||||
|
.toEqual('bar');
|
||||||
|
|
||||||
|
// Array value should be fetched (with references resolved).
|
||||||
|
secondDict.set('baz', ['qux', ref]);
|
||||||
|
expect(getInheritableProperty({ dict: firstDict, key: 'baz',
|
||||||
|
getArray: true, }))
|
||||||
|
.toEqual(['qux', 'quux']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fetches the property if it is inherited and present on multiple levels',
|
||||||
|
function() {
|
||||||
|
const ref = new Ref(10, 0);
|
||||||
|
const xref = new XRefMock([{ ref, data: 'quux', }]);
|
||||||
|
const firstDict = new Dict(xref);
|
||||||
|
const secondDict = new Dict(xref);
|
||||||
|
firstDict.set('Parent', secondDict);
|
||||||
|
|
||||||
|
// Regular values should be fetched.
|
||||||
|
firstDict.set('foo', 'bar1');
|
||||||
|
secondDict.set('foo', 'bar2');
|
||||||
|
expect(getInheritableProperty({ dict: firstDict, key: 'foo', }))
|
||||||
|
.toEqual('bar1');
|
||||||
|
expect(getInheritableProperty({ dict: firstDict, key: 'foo',
|
||||||
|
getArray: false, stopWhenFound: false, }))
|
||||||
|
.toEqual(['bar1', 'bar2']);
|
||||||
|
|
||||||
|
// Array value should be fetched (with references resolved).
|
||||||
|
firstDict.set('baz', ['qux1', ref]);
|
||||||
|
secondDict.set('baz', ['qux2', ref]);
|
||||||
|
expect(getInheritableProperty({ dict: firstDict, key: 'baz',
|
||||||
|
getArray: true, stopWhenFound: false, }))
|
||||||
|
.toEqual([['qux1', 'quux'], ['qux2', 'quux']]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stops searching when the loop limit is reached', function() {
|
||||||
|
const dict = new Dict();
|
||||||
|
let currentDict = dict;
|
||||||
|
let parentDict = null;
|
||||||
|
for (let i = 0; i < 150; i++) { // Exceeds the loop limit of 100.
|
||||||
|
parentDict = new Dict();
|
||||||
|
currentDict.set('Parent', parentDict);
|
||||||
|
currentDict = parentDict;
|
||||||
|
}
|
||||||
|
parentDict.set('foo', 'bar'); // Never found because of loop limit.
|
||||||
|
expect(getInheritableProperty({ dict, key: 'foo', })).toEqual(undefined);
|
||||||
|
|
||||||
|
dict.set('foo', 'baz');
|
||||||
|
expect(getInheritableProperty({ dict, key: 'foo', getArray: false,
|
||||||
|
stopWhenFound: false, }))
|
||||||
|
.toEqual(['baz']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toRomanNumerals', function() {
|
||||||
|
it('handles invalid arguments', function() {
|
||||||
|
for (const input of ['foo', -1, 0]) {
|
||||||
|
expect(function() {
|
||||||
|
toRomanNumerals(input);
|
||||||
|
}).toThrow(new Error('The number should be a positive integer.'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts numbers to uppercase Roman numerals', function() {
|
||||||
|
expect(toRomanNumerals(1)).toEqual('I');
|
||||||
|
expect(toRomanNumerals(6)).toEqual('VI');
|
||||||
|
expect(toRomanNumerals(7)).toEqual('VII');
|
||||||
|
expect(toRomanNumerals(8)).toEqual('VIII');
|
||||||
|
expect(toRomanNumerals(10)).toEqual('X');
|
||||||
|
expect(toRomanNumerals(40)).toEqual('XL');
|
||||||
|
expect(toRomanNumerals(100)).toEqual('C');
|
||||||
|
expect(toRomanNumerals(500)).toEqual('D');
|
||||||
|
expect(toRomanNumerals(1000)).toEqual('M');
|
||||||
|
expect(toRomanNumerals(2019)).toEqual('MMXIX');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts numbers to lowercase Roman numerals', function() {
|
||||||
|
expect(toRomanNumerals(1, /* lowercase = */ true)).toEqual('i');
|
||||||
|
expect(toRomanNumerals(6, /* lowercase = */ true)).toEqual('vi');
|
||||||
|
expect(toRomanNumerals(7, /* lowercase = */ true)).toEqual('vii');
|
||||||
|
expect(toRomanNumerals(8, /* lowercase = */ true)).toEqual('viii');
|
||||||
|
expect(toRomanNumerals(10, /* lowercase = */ true)).toEqual('x');
|
||||||
|
expect(toRomanNumerals(40, /* lowercase = */ true)).toEqual('xl');
|
||||||
|
expect(toRomanNumerals(100, /* lowercase = */ true)).toEqual('c');
|
||||||
|
expect(toRomanNumerals(500, /* lowercase = */ true)).toEqual('d');
|
||||||
|
expect(toRomanNumerals(1000, /* lowercase = */ true)).toEqual('m');
|
||||||
|
expect(toRomanNumerals(2019, /* lowercase = */ true)).toEqual('mmxix');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { buildGetDocumentParams, NodeCanvasFactory } from './test_utils';
|
import { buildGetDocumentParams, NodeCanvasFactory } from './test_utils';
|
||||||
import { DOMCanvasFactory } from '../../src/display/dom_utils';
|
import { DOMCanvasFactory } from '../../src/display/display_utils';
|
||||||
import { getDocument } from '../../src/display/api';
|
import { getDocument } from '../../src/display/api';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import isNodeJS from '../../src/shared/is_node';
|
||||||
|
|
||||||
|
@ -13,10 +13,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DOMSVGFactory, getFilenameFromUrl } from '../../src/display/dom_utils';
|
import {
|
||||||
|
DOMSVGFactory, getFilenameFromUrl
|
||||||
|
} from '../../src/display/display_utils';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import isNodeJS from '../../src/shared/is_node';
|
||||||
|
|
||||||
describe('dom_utils', function() {
|
describe('display_utils', function() {
|
||||||
describe('DOMSVGFactory', function() {
|
describe('DOMSVGFactory', function() {
|
||||||
let svgFactory;
|
let svgFactory;
|
||||||
|
|
@ -53,11 +53,12 @@ function initializePDFJS(callback) {
|
|||||||
'pdfjs-test/unit/cff_parser_spec',
|
'pdfjs-test/unit/cff_parser_spec',
|
||||||
'pdfjs-test/unit/cmap_spec',
|
'pdfjs-test/unit/cmap_spec',
|
||||||
'pdfjs-test/unit/colorspace_spec',
|
'pdfjs-test/unit/colorspace_spec',
|
||||||
|
'pdfjs-test/unit/core_utils_spec',
|
||||||
'pdfjs-test/unit/crypto_spec',
|
'pdfjs-test/unit/crypto_spec',
|
||||||
'pdfjs-test/unit/custom_spec',
|
'pdfjs-test/unit/custom_spec',
|
||||||
'pdfjs-test/unit/display_svg_spec',
|
'pdfjs-test/unit/display_svg_spec',
|
||||||
|
'pdfjs-test/unit/display_utils_spec',
|
||||||
'pdfjs-test/unit/document_spec',
|
'pdfjs-test/unit/document_spec',
|
||||||
'pdfjs-test/unit/dom_utils_spec',
|
|
||||||
'pdfjs-test/unit/encodings_spec',
|
'pdfjs-test/unit/encodings_spec',
|
||||||
'pdfjs-test/unit/evaluator_spec',
|
'pdfjs-test/unit/evaluator_spec',
|
||||||
'pdfjs-test/unit/function_spec',
|
'pdfjs-test/unit/function_spec',
|
||||||
|
@ -14,13 +14,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bytesToString, createPromiseCapability, createValidAbsoluteUrl,
|
bytesToString, createPromiseCapability, createValidAbsoluteUrl, isArrayBuffer,
|
||||||
getInheritableProperty, isArrayBuffer, isBool, isEmptyObj, isNum,
|
isBool, isEmptyObj, isNum, isSameOrigin, isSpace, isString, log2,
|
||||||
isSameOrigin, isSpace, isString, log2, ReadableStream, removeNullCharacters,
|
ReadableStream, removeNullCharacters, string32, stringToBytes,
|
||||||
string32, stringToBytes, stringToPDFString, toRomanNumerals, URL
|
stringToPDFString, URL
|
||||||
} from '../../src/shared/util';
|
} from '../../src/shared/util';
|
||||||
import { Dict, Ref } from '../../src/core/primitives';
|
|
||||||
import { XRefMock } from './test_utils';
|
|
||||||
|
|
||||||
describe('util', function() {
|
describe('util', function() {
|
||||||
describe('bytesToString', function() {
|
describe('bytesToString', function() {
|
||||||
@ -54,106 +52,6 @@ describe('util', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getInheritableProperty', function() {
|
|
||||||
it('handles non-dictionary arguments', function() {
|
|
||||||
expect(getInheritableProperty({ dict: null, key: 'foo', }))
|
|
||||||
.toEqual(undefined);
|
|
||||||
expect(getInheritableProperty({ dict: undefined, key: 'foo', }))
|
|
||||||
.toEqual(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('handles dictionaries that do not contain the property', function() {
|
|
||||||
// Empty dictionary.
|
|
||||||
const emptyDict = new Dict();
|
|
||||||
expect(getInheritableProperty({ dict: emptyDict, key: 'foo', }))
|
|
||||||
.toEqual(undefined);
|
|
||||||
|
|
||||||
// Filled dictionary with a different property.
|
|
||||||
const filledDict = new Dict();
|
|
||||||
filledDict.set('bar', 'baz');
|
|
||||||
expect(getInheritableProperty({ dict: filledDict, key: 'foo', }))
|
|
||||||
.toEqual(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fetches the property if it is not inherited', function() {
|
|
||||||
const ref = new Ref(10, 0);
|
|
||||||
const xref = new XRefMock([{ ref, data: 'quux', }]);
|
|
||||||
const dict = new Dict(xref);
|
|
||||||
|
|
||||||
// Regular values should be fetched.
|
|
||||||
dict.set('foo', 'bar');
|
|
||||||
expect(getInheritableProperty({ dict, key: 'foo', })).toEqual('bar');
|
|
||||||
|
|
||||||
// Array value should be fetched (with references resolved).
|
|
||||||
dict.set('baz', ['qux', ref]);
|
|
||||||
expect(getInheritableProperty({ dict, key: 'baz', getArray: true, }))
|
|
||||||
.toEqual(['qux', 'quux']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fetches the property if it is inherited and present on one level',
|
|
||||||
function() {
|
|
||||||
const ref = new Ref(10, 0);
|
|
||||||
const xref = new XRefMock([{ ref, data: 'quux', }]);
|
|
||||||
const firstDict = new Dict(xref);
|
|
||||||
const secondDict = new Dict(xref);
|
|
||||||
firstDict.set('Parent', secondDict);
|
|
||||||
|
|
||||||
// Regular values should be fetched.
|
|
||||||
secondDict.set('foo', 'bar');
|
|
||||||
expect(getInheritableProperty({ dict: firstDict, key: 'foo', }))
|
|
||||||
.toEqual('bar');
|
|
||||||
|
|
||||||
// Array value should be fetched (with references resolved).
|
|
||||||
secondDict.set('baz', ['qux', ref]);
|
|
||||||
expect(getInheritableProperty({ dict: firstDict, key: 'baz',
|
|
||||||
getArray: true, }))
|
|
||||||
.toEqual(['qux', 'quux']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fetches the property if it is inherited and present on multiple levels',
|
|
||||||
function() {
|
|
||||||
const ref = new Ref(10, 0);
|
|
||||||
const xref = new XRefMock([{ ref, data: 'quux', }]);
|
|
||||||
const firstDict = new Dict(xref);
|
|
||||||
const secondDict = new Dict(xref);
|
|
||||||
firstDict.set('Parent', secondDict);
|
|
||||||
|
|
||||||
// Regular values should be fetched.
|
|
||||||
firstDict.set('foo', 'bar1');
|
|
||||||
secondDict.set('foo', 'bar2');
|
|
||||||
expect(getInheritableProperty({ dict: firstDict, key: 'foo', }))
|
|
||||||
.toEqual('bar1');
|
|
||||||
expect(getInheritableProperty({ dict: firstDict, key: 'foo',
|
|
||||||
getArray: false, stopWhenFound: false, }))
|
|
||||||
.toEqual(['bar1', 'bar2']);
|
|
||||||
|
|
||||||
// Array value should be fetched (with references resolved).
|
|
||||||
firstDict.set('baz', ['qux1', ref]);
|
|
||||||
secondDict.set('baz', ['qux2', ref]);
|
|
||||||
expect(getInheritableProperty({ dict: firstDict, key: 'baz',
|
|
||||||
getArray: true, stopWhenFound: false, }))
|
|
||||||
.toEqual([['qux1', 'quux'], ['qux2', 'quux']]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('stops searching when the loop limit is reached', function() {
|
|
||||||
const dict = new Dict();
|
|
||||||
let currentDict = dict;
|
|
||||||
let parentDict = null;
|
|
||||||
for (let i = 0; i < 150; i++) { // Exceeds the loop limit of 100.
|
|
||||||
parentDict = new Dict();
|
|
||||||
currentDict.set('Parent', parentDict);
|
|
||||||
currentDict = parentDict;
|
|
||||||
}
|
|
||||||
parentDict.set('foo', 'bar'); // Never found because of loop limit.
|
|
||||||
expect(getInheritableProperty({ dict, key: 'foo', })).toEqual(undefined);
|
|
||||||
|
|
||||||
dict.set('foo', 'baz');
|
|
||||||
expect(getInheritableProperty({ dict, key: 'foo', getArray: false,
|
|
||||||
stopWhenFound: false, }))
|
|
||||||
.toEqual(['baz']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isArrayBuffer', function() {
|
describe('isArrayBuffer', function() {
|
||||||
it('handles array buffer values', function() {
|
it('handles array buffer values', function() {
|
||||||
expect(isArrayBuffer(new ArrayBuffer(0))).toEqual(true);
|
expect(isArrayBuffer(new ArrayBuffer(0))).toEqual(true);
|
||||||
@ -321,42 +219,6 @@ describe('util', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toRomanNumerals', function() {
|
|
||||||
it('handles invalid arguments', function() {
|
|
||||||
for (const input of ['foo', -1, 0]) {
|
|
||||||
expect(function() {
|
|
||||||
toRomanNumerals(input);
|
|
||||||
}).toThrow(new Error('The number should be a positive integer.'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('converts numbers to uppercase Roman numerals', function() {
|
|
||||||
expect(toRomanNumerals(1)).toEqual('I');
|
|
||||||
expect(toRomanNumerals(6)).toEqual('VI');
|
|
||||||
expect(toRomanNumerals(7)).toEqual('VII');
|
|
||||||
expect(toRomanNumerals(8)).toEqual('VIII');
|
|
||||||
expect(toRomanNumerals(10)).toEqual('X');
|
|
||||||
expect(toRomanNumerals(40)).toEqual('XL');
|
|
||||||
expect(toRomanNumerals(100)).toEqual('C');
|
|
||||||
expect(toRomanNumerals(500)).toEqual('D');
|
|
||||||
expect(toRomanNumerals(1000)).toEqual('M');
|
|
||||||
expect(toRomanNumerals(2019)).toEqual('MMXIX');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('converts numbers to lowercase Roman numerals', function() {
|
|
||||||
expect(toRomanNumerals(1, /* lowercase = */ true)).toEqual('i');
|
|
||||||
expect(toRomanNumerals(6, /* lowercase = */ true)).toEqual('vi');
|
|
||||||
expect(toRomanNumerals(7, /* lowercase = */ true)).toEqual('vii');
|
|
||||||
expect(toRomanNumerals(8, /* lowercase = */ true)).toEqual('viii');
|
|
||||||
expect(toRomanNumerals(10, /* lowercase = */ true)).toEqual('x');
|
|
||||||
expect(toRomanNumerals(40, /* lowercase = */ true)).toEqual('xl');
|
|
||||||
expect(toRomanNumerals(100, /* lowercase = */ true)).toEqual('c');
|
|
||||||
expect(toRomanNumerals(500, /* lowercase = */ true)).toEqual('d');
|
|
||||||
expect(toRomanNumerals(1000, /* lowercase = */ true)).toEqual('m');
|
|
||||||
expect(toRomanNumerals(2019, /* lowercase = */ true)).toEqual('mmxix');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('URL', function() {
|
describe('URL', function() {
|
||||||
it('should return an Object', function() {
|
it('should return an Object', function() {
|
||||||
const url = new URL('https://example.com');
|
const url = new URL('https://example.com');
|
||||||
|
Loading…
Reference in New Issue
Block a user