@ -908,12 +908,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} ) ;
} ) ;
} ,
} ,
getTextContent : function PartialEvaluator _getTextContent ( stream , task ,
getTextContent :
resources ,
function PartialEvaluator _getTextContent ( stream , task , resources ,
stateManager ) {
stateManager ,
normalizeWhitespace ) {
stateManager = ( stateManager || new StateManager ( new TextState ( ) ) ) ;
stateManager = ( stateManager || new StateManager ( new TextState ( ) ) ) ;
var WhitespaceRegexp = /\s/g ;
var textContent = {
var textContent = {
items : [ ] ,
items : [ ] ,
styles : Object . create ( null )
styles : Object . create ( null )
@ -1027,11 +1030,23 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return textContentItem ;
return textContentItem ;
}
}
function replaceWhitespace ( str ) {
// Replaces all whitespaces with standard spaces (0x20), to avoid
// alignment issues between the textLayer and the canvas if the text
// contains e.g. tabs (fixes issue6612.pdf).
var i = 0 , ii = str . length , code ;
while ( i < ii && ( code = str . charCodeAt ( i ) ) >= 0x20 && code <= 0x7F ) {
i ++ ;
}
return ( i < ii ? str . replace ( WhitespaceRegexp , ' ' ) : str ) ;
}
function runBidiTransform ( textChunk ) {
function runBidiTransform ( textChunk ) {
var str = textChunk . str . join ( '' ) ;
var str = textChunk . str . join ( '' ) ;
var bidiResult = PDFJS . bidi ( str , - 1 , textChunk . vertical ) ;
var bidiResult = PDFJS . bidi ( str , - 1 , textChunk . vertical ) ;
return {
return {
str : bidiResult . str ,
str : ( normalizeWhitespace ? replaceWhitespace ( bidiResult . str ) :
bidiResult . str ) ,
dir : bidiResult . dir ,
dir : bidiResult . dir ,
width : textChunk . width ,
width : textChunk . width ,
height : textChunk . height ,
height : textChunk . height ,
@ -1352,8 +1367,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
}
return self . getTextContent ( xobj , task ,
return self . getTextContent ( xobj , task ,
xobj . dict . get ( 'Resources' ) || resources , stateManager ) .
xobj . dict . get ( 'Resources' ) || resources , stateManager ,
then ( function ( formTextContent ) {
normalizeWhitespace ) . then ( function ( formTextContent ) {
Util . appendToArray ( textContent . items , formTextContent . items ) ;
Util . appendToArray ( textContent . items , formTextContent . items ) ;
Util . extendObj ( textContent . styles , formTextContent . styles ) ;
Util . extendObj ( textContent . styles , formTextContent . styles ) ;
stateManager . restore ( ) ;
stateManager . restore ( ) ;