Skip to content

Commit fcc05b0

Browse files
committed
Merge pull request mozilla#838 from notmasteryet/to-unicode-1
Making cmap equal to ToUnicode tables
2 parents 2e70984 + 683a8f0 commit fcc05b0

File tree

3 files changed

+230
-122
lines changed

3 files changed

+230
-122
lines changed

src/canvas.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,11 @@ var CanvasGraphics = (function canvasGraphics() {
586586
continue;
587587
}
588588

589-
var unicode = glyph.unicode;
590-
var char = (unicode >= 0x10000) ?
591-
String.fromCharCode(0xD800 | ((unicode - 0x10000) >> 10),
592-
0xDC00 | (unicode & 0x3FF)) : String.fromCharCode(unicode);
593-
589+
var char = glyph.fontChar;
594590
ctx.fillText(char, width, 0);
595591
width += glyph.width * fontSize * 0.001 + charSpacing;
592+
593+
// TODO actual characters can be extracted from the glyph.unicode
596594
}
597595
current.x += width;
598596

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)