Merge pull request #8064 from Snuffleupagus/fetchBuiltInCMap

[api-minor] Refactor fetching of built-in CMaps to utilize a factory on the `display` side instead, to allow users of the API to provide a custom CMap loading factory (e.g. for use with Node.js)
This commit is contained in:
Yury Delendik 2017-02-17 15:30:31 -06:00 committed by GitHub
commit cfaa621a05
13 changed files with 240 additions and 120 deletions

View File

@ -36,11 +36,12 @@ var error = sharedUtil.error;
var isInt = sharedUtil.isInt;
var isString = sharedUtil.isString;
var MissingDataException = sharedUtil.MissingDataException;
var CMapCompressionType = sharedUtil.CMapCompressionType;
var isEOF = corePrimitives.isEOF;
var isName = corePrimitives.isName;
var isCmd = corePrimitives.isCmd;
var isStream = corePrimitives.isStream;
var StringStream = coreStream.StringStream;
var Stream = coreStream.Stream;
var Lexer = coreParser.Lexer;
var BUILT_IN_CMAPS = [
@ -423,25 +424,6 @@ var IdentityCMap = (function IdentityCMapClosure() {
})();
var BinaryCMapReader = (function BinaryCMapReaderClosure() {
function fetchBinaryData(url) {
return new Promise(function (resolve, reject) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE) {
if (!request.response || request.status !== 200 &&
request.status !== 0) {
reject(new Error('Unable to get binary cMap at: ' + url));
} else {
resolve(new Uint8Array(request.response));
}
}
};
request.send(null);
});
}
function hexToInt(a, size) {
var n = 0;
for (var i = 0; i <= size; i++) {
@ -561,8 +543,8 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
}
};
function processBinaryCMap(url, cMap, extend) {
return fetchBinaryData(url).then(function (data) {
function processBinaryCMap(data, cMap, extend) {
return new Promise(function (resolve, reject) {
var stream = new BinaryCMapStream(data);
var header = stream.readByte();
cMap.vertical = !!(header & 1);
@ -709,22 +691,23 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
}
break;
default:
error('Unknown type: ' + type);
break;
reject(new Error('processBinaryCMap: Unknown type: ' + type));
return;
}
}
if (useCMap) {
return extend(useCMap);
resolve(extend(useCMap));
return;
}
return cMap;
resolve(cMap);
});
}
function BinaryCMapReader() {}
BinaryCMapReader.prototype = {
read: processBinaryCMap
process: processBinaryCMap,
};
return BinaryCMapReader;
@ -879,7 +862,7 @@ var CMapFactory = (function CMapFactoryClosure() {
}
}
function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) {
var previous;
var embededUseCMap;
objLoop: while (true) {
@ -935,14 +918,13 @@ var CMapFactory = (function CMapFactoryClosure() {
useCMap = embededUseCMap;
}
if (useCMap) {
return extendCMap(cMap, builtInCMapParams, useCMap);
return extendCMap(cMap, fetchBuiltInCMap, useCMap);
}
return Promise.resolve(cMap);
}
function extendCMap(cMap, builtInCMapParams, useCMap) {
return createBuiltInCMap(useCMap, builtInCMapParams).then(
function(newCMap) {
function extendCMap(cMap, fetchBuiltInCMap, useCMap) {
return createBuiltInCMap(useCMap, fetchBuiltInCMap).then(function(newCMap) {
cMap.useCMap = newCMap;
// If there aren't any code space ranges defined clone all the parent ones
// into this cMap.
@ -965,15 +947,7 @@ var CMapFactory = (function CMapFactoryClosure() {
});
}
function parseBinaryCMap(name, builtInCMapParams) {
var url = builtInCMapParams.url + name + '.bcmap';
var cMap = new CMap(true);
return new BinaryCMapReader().read(url, cMap, function (useCMap) {
return extendCMap(cMap, builtInCMapParams, useCMap);
});
}
function createBuiltInCMap(name, builtInCMapParams) {
function createBuiltInCMap(name, fetchBuiltInCMap) {
if (name === 'Identity-H') {
return Promise.resolve(new IdentityCMap(false, 2));
} else if (name === 'Identity-V') {
@ -982,45 +956,41 @@ var CMapFactory = (function CMapFactoryClosure() {
if (BUILT_IN_CMAPS.indexOf(name) === -1) {
return Promise.reject(new Error('Unknown cMap name: ' + name));
}
assert(builtInCMapParams, 'built-in cMap parameters are not provided');
assert(fetchBuiltInCMap, 'Built-in CMap parameters are not provided.');
if (builtInCMapParams.packed) {
return parseBinaryCMap(name, builtInCMapParams);
}
return fetchBuiltInCMap(name).then(function (data) {
var cMapData = data.cMapData, compressionType = data.compressionType;
var cMap = new CMap(true);
return new Promise(function (resolve, reject) {
var url = builtInCMapParams.url + name;
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200 || request.status === 0) {
var cMap = new CMap(true);
var lexer = new Lexer(new StringStream(request.responseText));
parseCMap(cMap, lexer, builtInCMapParams, null).then(
function (parsedCMap) {
resolve(parsedCMap);
});
} else {
reject(new Error('Unable to get cMap at: ' + url));
}
}
};
request.open('GET', url, true);
request.send(null);
if (compressionType === CMapCompressionType.BINARY) {
return new BinaryCMapReader().process(cMapData, cMap,
function (useCMap) {
return extendCMap(cMap, fetchBuiltInCMap, useCMap);
});
}
assert(compressionType === CMapCompressionType.NONE,
'TODO: Only BINARY/NONE CMap compression is currently supported.');
// Uncompressed CMap.
var lexer = new Lexer(new Stream(cMapData));
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
});
}
return {
create: function (encoding, builtInCMapParams, useCMap) {
create: function (params) {
var encoding = params.encoding;
var fetchBuiltInCMap = params.fetchBuiltInCMap;
var useCMap = params.useCMap;
if (isName(encoding)) {
return createBuiltInCMap(encoding.name, builtInCMapParams);
return createBuiltInCMap(encoding.name, fetchBuiltInCMap);
} else if (isStream(encoding)) {
var cMap = new CMap();
var lexer = new Lexer(encoding);
return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
return parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap).then(
function (parsedCMap) {
if (parsedCMap.isIdentityCMap) {
return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
return createBuiltInCMap(parsedCMap.name, fetchBuiltInCMap);
}
return parsedCMap;
});

View File

@ -71,13 +71,15 @@ var Page = (function PageClosure() {
var DEFAULT_USER_UNIT = 1.0;
var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache,
builtInCMapCache) {
this.pdfManager = pdfManager;
this.pageIndex = pageIndex;
this.pageDict = pageDict;
this.xref = xref;
this.ref = ref;
this.fontCache = fontCache;
this.builtInCMapCache = builtInCMapCache;
this.evaluatorOptions = pdfManager.evaluatorOptions;
this.resourcesPromise = null;
@ -248,6 +250,7 @@ var Page = (function PageClosure() {
handler, this.pageIndex,
this.idFactory,
this.fontCache,
this.builtInCMapCache,
this.evaluatorOptions);
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
@ -315,6 +318,7 @@ var Page = (function PageClosure() {
handler, self.pageIndex,
self.idFactory,
self.fontCache,
self.builtInCMapCache,
self.evaluatorOptions);
return partialEvaluator.getTextContent(contentStream,
@ -551,9 +555,10 @@ var PDFDocument = (function PDFDocumentClosure() {
this.xref.parse(recoveryMode);
var self = this;
var pageFactory = {
createPage: function (pageIndex, dict, ref, fontCache) {
createPage: function (pageIndex, dict, ref, fontCache,
builtInCMapCache) {
return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
fontCache);
fontCache, builtInCMapCache);
}
};
this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);

View File

@ -53,6 +53,7 @@ var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
var ImageKind = sharedUtil.ImageKind;
var OPS = sharedUtil.OPS;
var TextRenderingMode = sharedUtil.TextRenderingMode;
var CMapCompressionType = sharedUtil.CMapCompressionType;
var Util = sharedUtil.Util;
var assert = sharedUtil.assert;
var createPromiseCapability = sharedUtil.createPromiseCapability;
@ -112,7 +113,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
forceDataSchema: false,
maxImageSize: -1,
disableFontFace: false,
cMapOptions: { url: null, packed: false },
disableNativeImageDecoder: false,
};
@ -170,14 +170,31 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
};
function PartialEvaluator(pdfManager, xref, handler, pageIndex,
idFactory, fontCache, options) {
idFactory, fontCache, builtInCMapCache, options) {
this.pdfManager = pdfManager;
this.xref = xref;
this.handler = handler;
this.pageIndex = pageIndex;
this.idFactory = idFactory;
this.fontCache = fontCache;
this.builtInCMapCache = builtInCMapCache;
this.options = options || DefaultPartialEvaluatorOptions;
this.fetchBuiltInCMap = function (name) {
var cachedCMap = builtInCMapCache[name];
if (cachedCMap) {
return Promise.resolve(cachedCMap);
}
return handler.sendWithPromise('FetchBuiltInCMap', {
name: name,
}).then(function (data) {
if (data.compressionType !== CMapCompressionType.NONE) {
// Given the size of uncompressed CMaps, only cache compressed ones.
builtInCMapCache[name] = data;
}
return data;
});
};
}
// Trying to minimize Date.now() usage and check every 100 time
@ -1879,9 +1896,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
// d) Obtain the CMap with the name constructed in step (c) (available
// from the ASN Web site; see the Bibliography).
return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
null).then(
function (ucs2CMap) {
return CMapFactory.create({
encoding: ucs2CMapName,
fetchBuiltInCMap: this.fetchBuiltInCMap,
useCMap: null,
}).then(function (ucs2CMap) {
var cMap = properties.cMap;
toUnicode = [];
cMap.forEach(function(charcode, cid) {
@ -1907,16 +1926,22 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
var cmapObj = toUnicode;
if (isName(cmapObj)) {
return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
function (cmap) {
return CMapFactory.create({
encoding: cmapObj,
fetchBuiltInCMap: this.fetchBuiltInCMap,
useCMap: null,
}).then(function (cmap) {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xFFFF);
}
return new ToUnicodeMap(cmap.getMap());
});
} else if (isStream(cmapObj)) {
return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
function (cmap) {
return CMapFactory.create({
encoding: cmapObj,
fetchBuiltInCMap: this.fetchBuiltInCMap,
useCMap: null,
}).then(function (cmap) {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xFFFF);
}
@ -2222,7 +2247,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var descriptor = preEvaluatedFont.descriptor;
var type = preEvaluatedFont.type;
var maxCharIndex = (composite ? 0xFFFF : 0xFF);
var cMapOptions = this.options.cMapOptions;
var properties;
if (!descriptor) {
@ -2352,8 +2376,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (isName(cidEncoding)) {
properties.cidEncoding = cidEncoding.name;
}
cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
function (cMap) {
cMapPromise = CMapFactory.create({
encoding: cidEncoding,
fetchBuiltInCMap: this.fetchBuiltInCMap,
useCMap: null,
}).then(function (cMap) {
properties.cMap = cMap;
properties.vertical = properties.cMap.vertical;
});

View File

@ -71,8 +71,8 @@ var Catalog = (function CatalogClosure() {
this.xref = xref;
this.catDict = xref.getCatalogObj();
this.fontCache = new RefSetCache();
assert(isDict(this.catDict),
'catalog object is not a dictionary');
this.builtInCMapCache = Object.create(null);
assert(isDict(this.catDict), 'catalog object is not a dictionary');
// TODO refactor to move getPage() to the PDFDocument.
this.pageFactory = pageFactory;
@ -428,6 +428,7 @@ var Catalog = (function CatalogClosure() {
delete font.translated;
}
this.fontCache.clear();
this.builtInCMapCache = Object.create(null);
}.bind(this));
},
@ -438,7 +439,8 @@ var Catalog = (function CatalogClosure() {
var dict = a[0];
var ref = a[1];
return this.pageFactory.createPage(pageIndex, dict, ref,
this.fontCache);
this.fontCache,
this.builtInCMapCache);
}.bind(this)
);
}

View File

@ -729,15 +729,10 @@ var WorkerMessageHandler = {
ensureNotTerminated();
var cMapOptions = {
url: data.cMapUrl === undefined ? null : data.cMapUrl,
packed: data.cMapPacked === true
};
var evaluatorOptions = {
forceDataSchema: data.disableCreateObjectURL,
maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
disableFontFace: data.disableFontFace,
cMapOptions: cMapOptions,
disableNativeImageDecoder: data.disableNativeImageDecoder,
};

View File

@ -62,6 +62,7 @@ var CanvasGraphics = displayCanvas.CanvasGraphics;
var Metadata = displayMetadata.Metadata;
var getDefaultSetting = displayDOMUtils.getDefaultSetting;
var DOMCanvasFactory = displayDOMUtils.DOMCanvasFactory;
var DOMCMapReaderFactory = displayDOMUtils.DOMCMapReaderFactory;
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
@ -142,6 +143,10 @@ if (typeof PDFJSDev !== 'undefined' &&
* of certain (simple) JPEG images in the browser. This is useful for
* environments without DOM image support, such as e.g. Node.js.
* The default value is `false`.
* @property {Object} CMapReaderFactory - (optional) The factory that will be
* used when reading built-in CMap files. Providing a custom factory is useful
* for environments without `XMLHttpRequest` support, such as e.g. Node.js.
* The default value is {DOMCMapReaderFactory}.
*/
/**
@ -256,6 +261,7 @@ function getDocument(src, pdfDataRangeTransport,
params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
params.disableNativeImageDecoder = params.disableNativeImageDecoder === true;
var CMapReaderFactory = params.CMapReaderFactory || DOMCMapReaderFactory;
if (!worker) {
// Worker was not provided -- creating and owning our own.
@ -273,7 +279,8 @@ function getDocument(src, pdfDataRangeTransport,
throw new Error('Loading aborted');
}
var messageHandler = new MessageHandler(docId, workerId, worker.port);
var transport = new WorkerTransport(messageHandler, task, rangeTransport);
var transport = new WorkerTransport(messageHandler, task, rangeTransport,
CMapReaderFactory);
task._transport = transport;
messageHandler.send('Ready', null);
});
@ -309,8 +316,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
source: source,
disableRange: getDefaultSetting('disableRange'),
maxImageSize: getDefaultSetting('maxImageSize'),
cMapUrl: getDefaultSetting('cMapUrl'),
cMapPacked: getDefaultSetting('cMapPacked'),
disableFontFace: getDefaultSetting('disableFontFace'),
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
@ -1429,12 +1434,17 @@ var PDFWorker = (function PDFWorkerClosure() {
* @ignore
*/
var WorkerTransport = (function WorkerTransportClosure() {
function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport,
CMapReaderFactory) {
this.messageHandler = messageHandler;
this.loadingTask = loadingTask;
this.pdfDataRangeTransport = pdfDataRangeTransport;
this.commonObjs = new PDFObjects();
this.fontLoader = new FontLoader(loadingTask.docId);
this.CMapReaderFactory = new CMapReaderFactory({
baseUrl: getDefaultSetting('cMapUrl'),
isCompressed: getDefaultSetting('cMapPacked'),
});
this.destroyed = false;
this.destroyCapability = null;
@ -1794,6 +1804,15 @@ var WorkerTransport = (function WorkerTransportClosure() {
img.src = imageUrl;
});
}, this);
messageHandler.on('FetchBuiltInCMap', function (data) {
if (this.destroyed) {
return Promise.reject(new Error('Worker was destroyed'));
}
return this.CMapReaderFactory.fetch({
name: data.name,
});
}, this);
},
getData: function WorkerTransport_getData() {

View File

@ -31,6 +31,8 @@ var removeNullCharacters = sharedUtil.removeNullCharacters;
var warn = sharedUtil.warn;
var deprecated = sharedUtil.deprecated;
var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
var stringToBytes = sharedUtil.stringToBytes;
var CMapCompressionType = sharedUtil.CMapCompressionType;
var DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
@ -66,6 +68,57 @@ DOMCanvasFactory.prototype = {
}
};
var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
function DOMCMapReaderFactory(params) {
this.baseUrl = params.baseUrl || null;
this.isCompressed = params.isCompressed || false;
}
DOMCMapReaderFactory.prototype = {
fetch: function(params) {
if (!params.name) {
return Promise.reject(new Error('CMap name must be specified.'));
}
return new Promise(function (resolve, reject) {
var url = this.baseUrl + params.name;
var request = new XMLHttpRequest();
if (this.isCompressed) {
url += '.bcmap';
request.responseType = 'arraybuffer';
}
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE &&
(request.status === 200 || request.status === 0)) {
var data;
if (this.isCompressed && request.response) {
data = new Uint8Array(request.response);
} else if (!this.isCompressed && request.responseText) {
data = stringToBytes(request.responseText);
}
if (data) {
resolve({
cMapData: data,
compressionType: this.isCompressed ?
CMapCompressionType.BINARY : CMapCompressionType.NONE,
});
return;
}
reject(new Error('Unable to load ' +
(this.isCompressed ? 'binary' : '') +
' CMap at: ' + url));
}
}.bind(this);
request.open('GET', url, true);
request.send(null);
}.bind(this));
},
};
return DOMCMapReaderFactory;
})();
/**
* Optimised CSS custom property getter/setter.
* @class
@ -284,4 +337,5 @@ exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
exports.getDefaultSetting = getDefaultSetting;
exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
exports.DOMCanvasFactory = DOMCanvasFactory;
exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
}));

View File

@ -156,6 +156,12 @@ var VERBOSITY_LEVELS = {
infos: 5
};
var CMapCompressionType = {
NONE: 0,
BINARY: 1,
STREAM: 2,
};
// All the possible operations for an operator list.
var OPS = {
// Intentionally start from 1 so it is easy to spot bad operators that will be
@ -2411,6 +2417,7 @@ exports.AnnotationFlag = AnnotationFlag;
exports.AnnotationType = AnnotationType;
exports.FontType = FontType;
exports.ImageKind = ImageKind;
exports.CMapCompressionType = CMapCompressionType;
exports.InvalidPDFException = InvalidPDFException;
exports.MessageHandler = MessageHandler;
exports.MissingDataException = MissingDataException;

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,9 @@ describe('font_post', function() {
});
it('has invalid selection attributes presence', function(done) {
CMapFactory.create(new Name('Identity-H')).then(function (cMap) {
CMapFactory.create({
encoding: Name.get('Identity-H'),
}).then(function (cMap) {
var font = new Font("font", new Stream(font1282), {
loadedName: 'font',
type: 'CIDFontType2',

File diff suppressed because one or more lines are too long

View File

@ -17,34 +17,58 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/cmap_spec', ['exports', 'pdfjs/core/cmap',
'pdfjs/core/primitives', 'pdfjs/core/stream'], factory);
'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/display/dom_utils'],
factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/core/cmap.js'),
require('../../src/core/primitives.js'),
require('../../src/core/stream.js'));
require('../../src/core/primitives.js'),
require('../../src/core/stream.js'),
require('../../src/display/dom_utils.js'));
} else {
factory((root.pdfjsTestUnitCMapSpec = {}), root.pdfjsCoreCMap,
root.pdfjsCorePrimitives, root.pdfjsCoreStream);
root.pdfjsCorePrimitives, root.pdfjsCoreStream,
root.pdfjsDisplayDOMUtils);
}
}(this, function (exports, coreCMap, corePrimitives, coreStream) {
}(this, function (exports, coreCMap, corePrimitives, coreStream,
displayDOMUtils) {
var CMapFactory = coreCMap.CMapFactory;
var CMap = coreCMap.CMap;
var IdentityCMap = coreCMap.IdentityCMap;
var Name = corePrimitives.Name;
var StringStream = coreStream.StringStream;
var DOMCMapReaderFactory = displayDOMUtils.DOMCMapReaderFactory;
var cMapUrl = '../../external/bcmaps/';
var cMapPacked = true;
describe('cmap', function() {
var fetchBuiltInCMap;
beforeAll(function (done) {
var CMapReaderFactory = new DOMCMapReaderFactory({
baseUrl: cMapUrl,
isCompressed: cMapPacked,
});
fetchBuiltInCMap = function (name) {
return CMapReaderFactory.fetch({
name: name,
});
};
done();
});
afterAll(function () {
fetchBuiltInCMap = null;
});
it('parses beginbfchar', function(done) {
var str = '2 beginbfchar\n' +
'<03> <00>\n' +
'<04> <01>\n' +
'endbfchar\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
expect(cmap.lookup(0x03)).toEqual(String.fromCharCode(0x00));
expect(cmap.lookup(0x04)).toEqual(String.fromCharCode(0x01));
@ -59,7 +83,7 @@ describe('cmap', function() {
'<06> <0B> 0\n' +
'endbfrange\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
expect(cmap.lookup(0x05)).toBeUndefined();
expect(cmap.lookup(0x06)).toEqual(String.fromCharCode(0x00));
@ -75,7 +99,7 @@ describe('cmap', function() {
'<0D> <12> [ 0 1 2 3 4 5 ]\n' +
'endbfrange\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
expect(cmap.lookup(0x0C)).toBeUndefined();
expect(cmap.lookup(0x0D)).toEqual(0x00);
@ -91,7 +115,7 @@ describe('cmap', function() {
'<14> 0\n' +
'endcidchar\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
expect(cmap.lookup(0x14)).toEqual(0x00);
expect(cmap.lookup(0x15)).toBeUndefined();
@ -105,7 +129,7 @@ describe('cmap', function() {
'<0016> <001B> 0\n' +
'endcidrange\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
expect(cmap.lookup(0x15)).toBeUndefined();
expect(cmap.lookup(0x16)).toEqual(0x00);
@ -122,7 +146,7 @@ describe('cmap', function() {
'<00000003> <00000004>\n' +
'endcodespacerange\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
var c = {};
cmap.readCharCode(String.fromCharCode(1), 0, c);
@ -141,7 +165,7 @@ describe('cmap', function() {
'<8EA1A1A1> <8EA1FEFE>\n' +
'endcodespacerange\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
var c = {};
cmap.readCharCode(String.fromCharCode(0x8E, 0xA1, 0xA1, 0xA1), 0, c);
@ -155,8 +179,11 @@ describe('cmap', function() {
it('read usecmap', function(done) {
var str = '/Adobe-Japan1-1 usecmap\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream,
{ url: cMapUrl, packed: cMapPacked }, null);
var cmapPromise = CMapFactory.create({
encoding: stream,
fetchBuiltInCMap: fetchBuiltInCMap,
useCMap: null,
});
cmapPromise.then(function (cmap) {
expect(cmap instanceof CMap).toEqual(true);
expect(cmap.useCMap).not.toBeNull();
@ -171,7 +198,7 @@ describe('cmap', function() {
it('parses cmapname', function(done) {
var str = '/CMapName /Identity-H def\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
expect(cmap.name).toEqual('Identity-H');
done();
@ -182,7 +209,7 @@ describe('cmap', function() {
it('parses wmode', function(done) {
var str = '/WMode 1 def\n';
var stream = new StringStream(str);
var cmapPromise = CMapFactory.create(stream);
var cmapPromise = CMapFactory.create({ encoding: stream, });
cmapPromise.then(function (cmap) {
expect(cmap.vertical).toEqual(true);
done();
@ -191,8 +218,11 @@ describe('cmap', function() {
});
});
it('loads built in cmap', function(done) {
var cmapPromise = CMapFactory.create(Name.get('Adobe-Japan1-1'),
{ url: cMapUrl, packed: cMapPacked }, null);
var cmapPromise = CMapFactory.create({
encoding: Name.get('Adobe-Japan1-1'),
fetchBuiltInCMap: fetchBuiltInCMap,
useCMap: null,
});
cmapPromise.then(function (cmap) {
expect(cmap instanceof CMap).toEqual(true);
expect(cmap.useCMap).toBeNull();
@ -205,8 +235,11 @@ describe('cmap', function() {
});
});
it('loads built in identity cmap', function(done) {
var cmapPromise = CMapFactory.create(Name.get('Identity-H'),
{ url: cMapUrl, packed: cMapPacked }, null);
var cmapPromise = CMapFactory.create({
encoding: Name.get('Identity-H'),
fetchBuiltInCMap: fetchBuiltInCMap,
useCMap: null,
});
cmapPromise.then(function (cmap) {
expect(cmap instanceof IdentityCMap).toEqual(true);
expect(cmap.vertical).toEqual(false);

View File

@ -34,11 +34,13 @@ describe('document', function () {
var page1 = new Page(/* pdfManager = */ { }, /* xref = */ null,
/* pageIndex = */ 0,
/* pageDict = */ null, /* ref = */ null,
/* fontCache = */ null);
/* fontCache = */ null,
/* builtInCMapCache = */ null);
var page2 = new Page(/* pdfManager = */ { }, /* xref = */ null,
/* pageIndex = */ 1,
/* pageDict = */ null, /* ref = */ null,
/* fontCache = */ null);
/* fontCache = */ null,
/* builtInCMapCache = */ null);
var idFactory1 = page1.idFactory, idFactory2 = page2.idFactory;