Browse Source

Refactors getTextContent return value

Yury Delendik 11 years ago
parent
commit
96fff4cc74
  1. 34
      src/core/evaluator.js
  2. 2
      test/driver.js
  3. 4
      web/pdf_find_controller.js
  4. 10
      web/text_layer_builder.js

34
src/core/evaluator.js

@ -597,24 +597,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { @@ -597,24 +597,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
},
getTextContent: function PartialEvaluator_getTextContent(
stream, resources, state) {
stream, resources, textState) {
var bidiTexts;
textState = textState || new TextState();
var bidiTexts = [];
var SPACE_FACTOR = 0.35;
var MULTI_SPACE_FACTOR = 1.5;
var textState;
if (!state) {
textState = new TextState();
bidiTexts = [];
state = {
textState: textState,
bidiTexts: bidiTexts
};
} else {
bidiTexts = state.bidiTexts;
textState = state.textState;
}
var self = this;
var xref = this.xref;
@ -734,11 +723,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { @@ -734,11 +723,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if ('Form' !== type.name)
break;
state = this.getTextContent(
var formTexts = this.getTextContent(
xobj,
xobj.dict.get('Resources') || resources,
state
textState
);
Util.concatenateToArray(bidiTexts, formTexts);
break;
case OPS.setGState:
var dictName = args[0];
@ -758,7 +748,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { @@ -758,7 +748,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} // switch
if (chunk !== '') {
var bidiText = PDFJS.bidi(chunk, -1, font.vertical);
var bidiResult = PDFJS.bidi(chunk, -1, font.vertical);
var bidiText = {
str: bidiResult.str,
dir: bidiResult.dir
};
var renderParams = textState.calcRenderParams(preprocessor.ctm);
bidiText.x = renderParams.renderMatrix[4] - (textState.fontSize *
renderParams.vScale * Math.sin(renderParams.angle));
@ -775,13 +769,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { @@ -775,13 +769,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
bidiText.x += renderParams.vScale / 2;
bidiText.y -= renderParams.vScale;
}
bidiText.angle = renderParams.angle;
bidiText.size = fontHeight;
bidiTexts.push(bidiText);
chunk = '';
}
} // while
return state;
return bidiTexts;
},
extractDataStructures: function

2
test/driver.js

@ -210,7 +210,7 @@ SimpleTextLayerBuilder.prototype = { @@ -210,7 +210,7 @@ SimpleTextLayerBuilder.prototype = {
ctx.stroke();
ctx.fill();
ctx.restore();
var textContent = this.textContent.bidiTexts[this.textCounter].str;
var textContent = this.textContent[this.textCounter].str;
ctx.font = fontHeight + 'px ' + geom.fontFamily;
ctx.fillStyle = 'black';
ctx.fillText(textContent, geom.x, geom.y);

4
web/pdf_find_controller.js

@ -150,9 +150,7 @@ var PDFFindController = { @@ -150,9 +150,7 @@ var PDFFindController = {
var self = this;
function extractPageText(pageIndex) {
self.pdfPageSource.pages[pageIndex].getTextContent().then(
function textContentResolved(data) {
// Build the find string.
var bidiTexts = data.bidiTexts;
function textContentResolved(bidiTexts) {
var str = '';
for (var i = 0; i < bidiTexts.length; i++) {

10
web/text_layer_builder.js

@ -62,7 +62,7 @@ var TextLayerBuilder = function textLayerBuilder(options) { @@ -62,7 +62,7 @@ var TextLayerBuilder = function textLayerBuilder(options) {
this.renderLayer = function textLayerBuilderRenderLayer() {
var self = this;
var textDivs = this.textDivs;
var bidiTexts = this.textContent.bidiTexts;
var bidiTexts = this.textContent;
var textLayerDiv = this.textLayerDiv;
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
@ -149,7 +149,7 @@ var TextLayerBuilder = function textLayerBuilder(options) { @@ -149,7 +149,7 @@ var TextLayerBuilder = function textLayerBuilder(options) {
this.divContentDone = true;
var textDivs = this.textDivs;
var bidiTexts = this.textContent.bidiTexts;
var bidiTexts = this.textContent;
for (var i = 0; i < bidiTexts.length; i++) {
var bidiText = bidiTexts[i];
@ -181,7 +181,7 @@ var TextLayerBuilder = function textLayerBuilder(options) { @@ -181,7 +181,7 @@ var TextLayerBuilder = function textLayerBuilder(options) {
this.convertMatches = function textLayerBuilderConvertMatches(matches) {
var i = 0;
var iIndex = 0;
var bidiTexts = this.textContent.bidiTexts;
var bidiTexts = this.textContent;
var end = bidiTexts.length - 1;
var queryLen = PDFFindController === null ?
0 : PDFFindController.state.query.length;
@ -240,7 +240,7 @@ var TextLayerBuilder = function textLayerBuilder(options) { @@ -240,7 +240,7 @@ var TextLayerBuilder = function textLayerBuilder(options) {
return;
}
var bidiTexts = this.textContent.bidiTexts;
var bidiTexts = this.textContent;
var textDivs = this.textDivs;
var prevEnd = null;
var isSelectedPage = PDFFindController === null ?
@ -355,7 +355,7 @@ var TextLayerBuilder = function textLayerBuilder(options) { @@ -355,7 +355,7 @@ var TextLayerBuilder = function textLayerBuilder(options) {
// Clear out all matches.
var matches = this.matches;
var textDivs = this.textDivs;
var bidiTexts = this.textContent.bidiTexts;
var bidiTexts = this.textContent;
var clearedUntilDivIdx = -1;
// Clear out all current matches.

Loading…
Cancel
Save