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

2
test/driver.js

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

4
web/pdf_find_controller.js

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

10
web/text_layer_builder.js

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

Loading…
Cancel
Save