Skip to content

Commit a544bed

Browse files
committed
Merge branch 'master' of git://github.com/mozilla/pdf.js into text-select
Conflicts: src/canvas.js
2 parents 4cfc552 + fcc05b0 commit a544bed

File tree

3 files changed

+229
-125
lines changed

3 files changed

+229
-125
lines changed

src/canvas.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,6 @@ var CanvasGraphics = (function canvasGraphics() {
619619
this.textDivs.push(div);
620620
},
621621
showText: function canvasGraphicsShowText(str, skipTextSelection) {
622-
function unicodeToChar(unicode) {
623-
return (unicode >= 0x10000) ?
624-
String.fromCharCode(0xD800 | ((unicode - 0x10000) >> 10),
625-
0xDC00 | (unicode & 0x3FF)) : String.fromCharCode(unicode);
626-
};
627-
628622
var ctx = this.ctx;
629623
var current = this.current;
630624
var font = current.font;
@@ -673,7 +667,7 @@ var CanvasGraphics = (function canvasGraphics() {
673667
ctx.translate(charWidth, 0);
674668
current.x += charWidth;
675669

676-
text.str += unicodeToChar(glyph.unicode);
670+
text.str += glyph.fontChar;
677671
text.length++;
678672
text.canvasWidth += charWidth;
679673
}
@@ -691,7 +685,7 @@ var CanvasGraphics = (function canvasGraphics() {
691685
continue;
692686
}
693687

694-
var char = unicodeToChar(glyph.unicode);
688+
var char = glyph.fontChar;
695689
var charWidth = glyph.width * fontSize * 0.001 + charSpacing;
696690
ctx.fillText(char, width, 0);
697691
width += charWidth;

src/evaluator.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ var PartialEvaluator = (function partialEvaluator() {
512512
error('Encoding is not a Name nor a Dict');
513513
}
514514
}
515+
515516
properties.differences = differences;
516517
properties.baseEncoding = baseEncoding;
517518
properties.hasEncoding = hasEncoding;
@@ -554,9 +555,21 @@ var PartialEvaluator = (function partialEvaluator() {
554555
var startRange = tokens[j];
555556
var endRange = tokens[j + 1];
556557
var code = tokens[j + 2];
557-
while (startRange <= endRange) {
558-
charToUnicode[startRange] = code++;
559-
++startRange;
558+
if (code == 0xFFFF) {
559+
// CMap is broken, assuming code == startRange
560+
code = startRange;
561+
}
562+
if (isArray(code)) {
563+
var codeindex = 0;
564+
while (startRange <= endRange) {
565+
charToUnicode[startRange] = code[codeindex++];
566+
++startRange;
567+
}
568+
} else {
569+
while (startRange <= endRange) {
570+
charToUnicode[startRange] = code++;
571+
++startRange;
572+
}
560573
}
561574
}
562575
break;
@@ -595,9 +608,18 @@ var PartialEvaluator = (function partialEvaluator() {
595608
}
596609
} else if (byte == 0x3E) {
597610
if (token.length) {
598-
// parsing hex number
599-
tokens.push(parseInt(token, 16));
600-
token = '';
611+
if (token.length <= 4) {
612+
// parsing hex number
613+
tokens.push(parseInt(token, 16));
614+
token = '';
615+
} else {
616+
// parsing hex UTF-16BE numbers
617+
var str = [];
618+
for (var i = 0, ii = token.length; i < ii; i += 4)
619+
str.push(parseInt(token.substr(i, 4), 16));
620+
tokens.push(String.fromCharCode.apply(String, str));
621+
token = '';
622+
}
601623
}
602624
} else {
603625
token += String.fromCharCode(byte);

0 commit comments

Comments
 (0)