Skip to content

Commit

Permalink
Merge pull request #8194 from Snuffleupagus/getTextContent-use-proper…
Browse files Browse the repository at this point in the history
…-handler

Use a proper `MessageHandler` for `PartialEvaluator.getTextContent` to avoid errors for fonts relying on built-in CMap files (PR 8064 follow-up)
  • Loading branch information
yurydelendik authored Mar 25, 2017
2 parents 68f2bf3 + 5c0c122 commit b7ba44b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
7 changes: 1 addition & 6 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,9 @@ var Page = (function PageClosure() {
});
},

extractTextContent: function Page_extractTextContent(task,
extractTextContent: function Page_extractTextContent(handler, task,
normalizeWhitespace,
combineTextItems) {
var handler = {
on: function nullHandlerOn() {},
send: function nullHandlerSend() {}
};

var self = this;

var pdfManager = this.pdfManager;
Expand Down
2 changes: 1 addition & 1 deletion src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ var WorkerMessageHandler = {
startWorkerTask(task);
var pageNum = pageIndex + 1;
var start = Date.now();
return page.extractTextContent(task, normalizeWhitespace,
return page.extractTextContent(handler, task, normalizeWhitespace,
combineTextItems).then(
function(textContent) {
finishWorkerTask(task);
Expand Down
13 changes: 7 additions & 6 deletions src/display/dom_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {

DOMCMapReaderFactory.prototype = {
fetch: function(params) {
if (!params.name) {
var name = params.name;
if (!name) {
return Promise.reject(new Error('CMap name must be specified.'));
}
return new Promise(function (resolve, reject) {
var url = this.baseUrl + params.name;
var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');

var request = new XMLHttpRequest();
request.open('GET', url, true);

if (this.isCompressed) {
url += '.bcmap';
request.responseType = 'arraybuffer';
}
request.onreadystatechange = function () {
Expand All @@ -105,12 +107,11 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
return;
}
reject(new Error('Unable to load ' +
(this.isCompressed ? 'binary' : '') +
' CMap at: ' + url));
(this.isCompressed ? 'binary ' : '') +
'CMap at: ' + url));
}
}.bind(this);

request.open('GET', url, true);
request.send(null);
}.bind(this));
},
Expand Down
9 changes: 8 additions & 1 deletion test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2757,10 +2757,17 @@
"md5": "797093d67c4d4d4231ac6e1fb66bf6c3",
"rounds": 1,
"link": true,
"firstPage": 1,
"lastPage": 1,
"type": "eq"
},
{ "id": "mao-text",
"file": "pdfs/mao.pdf",
"md5": "797093d67c4d4d4231ac6e1fb66bf6c3",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "text"
},
{ "id": "noembed-identity",
"file": "pdfs/noembed-identity.pdf",
"md5": "05d3803b6c22451e18cb60d8d8c75c0c",
Expand Down
12 changes: 5 additions & 7 deletions test/unit/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,19 @@ var NodeCMapReaderFactory = (function NodeCMapReaderFactoryClosure() {

NodeCMapReaderFactory.prototype = {
fetch: function(params) {
if (!params.name) {
var name = params.name;
if (!name) {
return Promise.reject(new Error('CMap name must be specified.'));
}
return new Promise(function (resolve, reject) {
var url = this.baseUrl + params.name;
var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');

var fs = require('fs');
if (this.isCompressed) {
url += '.bcmap';
}
fs.readFile(url, function (error, data) {
if (error || !data) {
reject(new Error('Unable to load ' +
(this.isCompressed ? 'binary' : '') +
' CMap at: ' + url));
(this.isCompressed ? 'binary ' : '') +
'CMap at: ' + url));
return;
}
resolve({
Expand Down

0 comments on commit b7ba44b

Please sign in to comment.