Skip to content

Commit f6ad43e

Browse files
Update pdf.js
1 parent 8a256b0 commit f6ad43e

File tree

5 files changed

+96
-80
lines changed

5 files changed

+96
-80
lines changed

build/pdf.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/pdf.sandbox.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/pdf.worker.js

Lines changed: 90 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -23679,7 +23679,6 @@ class PartialEvaluator {
2367923679
}) {
2368023680
resources = resources || _primitives.Dict.empty;
2368123681
stateManager = stateManager || new StateManager(new TextState());
23682-
const WhitespaceRegexp = /\s/g;
2368323682
const NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
2368423683
const textContent = {
2368523684
items: [],
@@ -23798,24 +23797,11 @@ class PartialEvaluator {
2379823797
textContentItem.textAdvanceScale = scaleFactor;
2379923798
}
2380023799

23801-
function replaceWhitespace(str) {
23802-
const ii = str.length;
23803-
let i = 0,
23804-
code;
23805-
23806-
while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7f) {
23807-
i++;
23808-
}
23809-
23810-
return i < ii ? str.replace(WhitespaceRegexp, " ") : str;
23811-
}
23812-
2381323800
function runBidiTransform(textChunk) {
2381423801
const text = textChunk.str.join("");
2381523802
const bidiResult = (0, _bidi.bidi)(text, -1, textChunk.vertical);
23816-
const str = normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str;
2381723803
return {
23818-
str,
23804+
str: bidiResult.str,
2381923805
dir: bidiResult.dir,
2382023806
width: Math.abs(textChunk.totalWidth),
2382123807
height: Math.abs(textChunk.totalHeight),
@@ -24007,7 +23993,6 @@ class PartialEvaluator {
2400723993
}
2400823994

2400923995
compareWithLastPosition();
24010-
let glyphUnicode = glyph.unicode;
2401123996
const textChunk = ensureTextContentItem();
2401223997

2401323998
if (glyph.isDiacritic) {
@@ -24028,9 +24013,14 @@ class PartialEvaluator {
2402824013
textChunk.prevTransform = getCurrentTextTransform();
2402924014
}
2403024015

24031-
glyphUnicode = NormalizedUnicodes[glyphUnicode] || glyphUnicode;
24032-
glyphUnicode = (0, _unicode.reverseIfRtl)(glyphUnicode);
24033-
textChunk.str.push(glyphUnicode);
24016+
if (glyph.isWhitespace && normalizeWhitespace) {
24017+
textChunk.str.push(" ");
24018+
} else {
24019+
let glyphUnicode = glyph.unicode;
24020+
glyphUnicode = NormalizedUnicodes[glyphUnicode] || glyphUnicode;
24021+
glyphUnicode = (0, _unicode.reverseIfRtl)(glyphUnicode);
24022+
textChunk.str.push(glyphUnicode);
24023+
}
2403424024

2403524025
if (charSpacing) {
2403624026
if (!font.vertical) {
@@ -42568,14 +42558,26 @@ var _encodings = __w_pdfjs_require__(19);
4256842558

4256942559
var _stream = __w_pdfjs_require__(10);
4257042560

42571-
function getLong(data, offset) {
42572-
return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
42561+
function getUint32(data, offset) {
42562+
return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
4257342563
}
4257442564

42575-
function getUshort(data, offset) {
42565+
function getUint16(data, offset) {
4257642566
return data[offset] << 8 | data[offset + 1];
4257742567
}
4257842568

42569+
function getInt16(data, offset) {
42570+
return (data[offset] << 24 | data[offset + 1] << 16) >> 16;
42571+
}
42572+
42573+
function getInt8(data, offset) {
42574+
return data[offset] << 24 >> 24;
42575+
}
42576+
42577+
function getFloat214(data, offset) {
42578+
return getInt16(data, offset) / 16384;
42579+
}
42580+
4257942581
function getSubroutineBias(subrs) {
4258042582
const numSubrs = subrs.length;
4258142583
let bias = 32768;
@@ -42590,34 +42592,34 @@ function getSubroutineBias(subrs) {
4259042592
}
4259142593

4259242594
function parseCmap(data, start, end) {
42593-
const offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
42594-
const format = getUshort(data, start + offset);
42595+
const offset = getUint16(data, start + 2) === 1 ? getUint32(data, start + 8) : getUint32(data, start + 16);
42596+
const format = getUint16(data, start + offset);
4259542597
let ranges, p, i;
4259642598

4259742599
if (format === 4) {
42598-
getUshort(data, start + offset + 2);
42599-
const segCount = getUshort(data, start + offset + 6) >> 1;
42600+
getUint16(data, start + offset + 2);
42601+
const segCount = getUint16(data, start + offset + 6) >> 1;
4260042602
p = start + offset + 14;
4260142603
ranges = [];
4260242604

4260342605
for (i = 0; i < segCount; i++, p += 2) {
4260442606
ranges[i] = {
42605-
end: getUshort(data, p)
42607+
end: getUint16(data, p)
4260642608
};
4260742609
}
4260842610

4260942611
p += 2;
4261042612

4261142613
for (i = 0; i < segCount; i++, p += 2) {
42612-
ranges[i].start = getUshort(data, p);
42614+
ranges[i].start = getUint16(data, p);
4261342615
}
4261442616

4261542617
for (i = 0; i < segCount; i++, p += 2) {
42616-
ranges[i].idDelta = getUshort(data, p);
42618+
ranges[i].idDelta = getUint16(data, p);
4261742619
}
4261842620

4261942621
for (i = 0; i < segCount; i++, p += 2) {
42620-
let idOffset = getUshort(data, p);
42622+
let idOffset = getUint16(data, p);
4262142623

4262242624
if (idOffset === 0) {
4262342625
continue;
@@ -42626,23 +42628,23 @@ function parseCmap(data, start, end) {
4262642628
ranges[i].ids = [];
4262742629

4262842630
for (let j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
42629-
ranges[i].ids[j] = getUshort(data, p + idOffset);
42631+
ranges[i].ids[j] = getUint16(data, p + idOffset);
4263042632
idOffset += 2;
4263142633
}
4263242634
}
4263342635

4263442636
return ranges;
4263542637
} else if (format === 12) {
42636-
getLong(data, start + offset + 4);
42637-
const groups = getLong(data, start + offset + 12);
42638+
const groups = getUint32(data, start + offset + 12);
4263842639
p = start + offset + 16;
4263942640
ranges = [];
4264042641

4264142642
for (i = 0; i < groups; i++) {
42643+
start = getUint32(data, p);
4264242644
ranges.push({
42643-
start: getLong(data, p),
42644-
end: getLong(data, p + 4),
42645-
idDelta: getLong(data, p + 8) - getLong(data, p)
42645+
start,
42646+
end: getUint32(data, p + 4),
42647+
idDelta: getUint32(data, p + 8) - start
4264642648
});
4264742649
p += 12;
4264842650
}
@@ -42672,16 +42674,11 @@ function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
4267242674

4267342675
if (isGlyphLocationsLong) {
4267442676
itemSize = 4;
42675-
42676-
itemDecode = function fontItemDecodeLong(data, offset) {
42677-
return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
42678-
};
42677+
itemDecode = getUint32;
4267942678
} else {
4268042679
itemSize = 2;
4268142680

42682-
itemDecode = function fontItemDecode(data, offset) {
42683-
return data[offset] << 9 | data[offset + 1] << 1;
42684-
};
42681+
itemDecode = (data, offset) => 2 * getUint16(data, offset);
4268542682
}
4268642683

4268742684
const glyphs = [];
@@ -42745,26 +42742,37 @@ function compileGlyf(code, cmds, font) {
4274542742
}
4274642743

4274742744
let i = 0;
42748-
const numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
42745+
const numberOfContours = getInt16(code, i);
4274942746
let flags;
4275042747
let x = 0,
4275142748
y = 0;
4275242749
i += 10;
4275342750

4275442751
if (numberOfContours < 0) {
4275542752
do {
42756-
flags = code[i] << 8 | code[i + 1];
42757-
const glyphIndex = code[i + 2] << 8 | code[i + 3];
42753+
flags = getUint16(code, i);
42754+
const glyphIndex = getUint16(code, i + 2);
4275842755
i += 4;
4275942756
let arg1, arg2;
4276042757

4276142758
if (flags & 0x01) {
42762-
arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
42763-
arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
42759+
if (flags & 0x02) {
42760+
arg1 = getInt16(code, i);
42761+
arg2 = getInt16(code, i + 2);
42762+
} else {
42763+
arg1 = getUint16(code, i);
42764+
arg2 = getUint16(code, i + 2);
42765+
}
42766+
4276442767
i += 4;
4276542768
} else {
42766-
arg1 = code[i++];
42767-
arg2 = code[i++];
42769+
if (flags & 0x02) {
42770+
arg1 = getInt8(code, i++);
42771+
arg2 = getInt8(code, i++);
42772+
} else {
42773+
arg1 = code[i++];
42774+
arg2 = code[i++];
42775+
}
4276842776
}
4276942777

4277042778
if (flags & 0x02) {
@@ -42781,17 +42789,17 @@ function compileGlyf(code, cmds, font) {
4278142789
scale10 = 0;
4278242790

4278342791
if (flags & 0x08) {
42784-
scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
42792+
scaleX = scaleY = getFloat214(code, i);
4278542793
i += 2;
4278642794
} else if (flags & 0x40) {
42787-
scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
42788-
scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
42795+
scaleX = getFloat214(code, i);
42796+
scaleY = getFloat214(code, i + 2);
4278942797
i += 4;
4279042798
} else if (flags & 0x80) {
42791-
scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
42792-
scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
42793-
scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
42794-
scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
42799+
scaleX = getFloat214(code, i);
42800+
scale01 = getFloat214(code, i + 2);
42801+
scale10 = getFloat214(code, i + 4);
42802+
scaleY = getFloat214(code, i + 6);
4279542803
i += 8;
4279642804
}
4279742805

@@ -42804,6 +42812,9 @@ function compileGlyf(code, cmds, font) {
4280442812
cmd: "transform",
4280542813
args: [scaleX, scale01, scale10, scaleY, x, y]
4280642814
});
42815+
42816+
if (!(flags & 0x02)) {}
42817+
4280742818
compileGlyf(subglyph, cmds, font);
4280842819
cmds.push({
4280942820
cmd: "restore"
@@ -42815,11 +42826,11 @@ function compileGlyf(code, cmds, font) {
4281542826
let j, jj;
4281642827

4281742828
for (j = 0; j < numberOfContours; j++) {
42818-
endPtsOfContours.push(code[i] << 8 | code[i + 1]);
42829+
endPtsOfContours.push(getUint16(code, i));
4281942830
i += 2;
4282042831
}
4282142832

42822-
const instructionLength = code[i] << 8 | code[i + 1];
42833+
const instructionLength = getUint16(code, i);
4282342834
i += 2 + instructionLength;
4282442835
const numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
4282542836
const points = [];
@@ -42842,7 +42853,7 @@ function compileGlyf(code, cmds, font) {
4284242853
for (j = 0; j < numberOfPoints; j++) {
4284342854
switch (points[j].flags & 0x12) {
4284442855
case 0x00:
42845-
x += (code[i] << 24 | code[i + 1] << 16) >> 16;
42856+
x += getInt16(code, i);
4284642857
i += 2;
4284742858
break;
4284842859

@@ -42861,7 +42872,7 @@ function compileGlyf(code, cmds, font) {
4286142872
for (j = 0; j < numberOfPoints; j++) {
4286242873
switch (points[j].flags & 0x24) {
4286342874
case 0x00:
42864-
y += (code[i] << 24 | code[i + 1] << 16) >> 16;
42875+
y += getInt16(code, i);
4286542876
i += 2;
4286642877
break;
4286742878

@@ -43479,12 +43490,12 @@ class FontRendererFactory {
4347943490
static create(font, seacAnalysisEnabled) {
4348043491
const data = new Uint8Array(font.data);
4348143492
let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
43482-
const numTables = getUshort(data, 4);
43493+
const numTables = getUint16(data, 4);
4348343494

4348443495
for (let i = 0, p = 12; i < numTables; i++, p += 16) {
4348543496
const tag = (0, _util.bytesToString)(data.subarray(p, p + 4));
43486-
const offset = getLong(data, p + 8);
43487-
const length = getLong(data, p + 12);
43497+
const offset = getUint32(data, p + 8);
43498+
const length = getUint32(data, p + 12);
4348843499

4348943500
switch (tag) {
4349043501
case "cmap":
@@ -43500,8 +43511,8 @@ class FontRendererFactory {
4350043511
break;
4350143512

4350243513
case "head":
43503-
unitsPerEm = getUshort(data, offset + 18);
43504-
indexToLocFormat = getUshort(data, offset + 50);
43514+
unitsPerEm = getUint16(data, offset + 18);
43515+
indexToLocFormat = getUint16(data, offset + 50);
4350543516
break;
4350643517

4350743518
case "CFF ":
@@ -44063,14 +44074,12 @@ class CompositeGlyph {
4406344074
pos += 4;
4406444075
flags ^= ARG_1_AND_2_ARE_WORDS;
4406544076
} else {
44066-
argument1 = glyf.getUint8(pos);
44067-
argument2 = glyf.getUint8(pos + 1);
44068-
4406944077
if (flags & ARGS_ARE_XY_VALUES) {
44070-
const abs1 = argument1 & 0x7f;
44071-
argument1 = argument1 & 0x80 ? -abs1 : abs1;
44072-
const abs2 = argument2 & 0x7f;
44073-
argument2 = argument2 & 0x80 ? -abs2 : abs2;
44078+
argument1 = glyf.getInt8(pos);
44079+
argument2 = glyf.getInt8(pos + 1);
44080+
} else {
44081+
argument1 = glyf.getUint8(pos);
44082+
argument2 = glyf.getUint8(pos + 1);
4407444083
}
4407544084

4407644085
pos += 2;
@@ -45133,6 +45142,11 @@ const Type1Parser = function Type1ParserClosure() {
4513345142
return this.currentChar = this.stream.getByte();
4513445143
}
4513545144

45145+
prevChar() {
45146+
this.stream.skip(-2);
45147+
return this.currentChar = this.stream.getByte();
45148+
}
45149+
4513645150
getToken() {
4513745151
let comment = false;
4513845152
let ch = this.currentChar;
@@ -45229,6 +45243,8 @@ const Type1Parser = function Type1ParserClosure() {
4522945243

4523045244
if (token === "noaccess") {
4523145245
this.getToken();
45246+
} else if (token === "/") {
45247+
this.prevChar();
4523245248
}
4523345249

4523445250
charstrings.push({
@@ -73590,7 +73606,7 @@ Object.defineProperty(exports, "WorkerMessageHandler", ({
7359073606
var _worker = __w_pdfjs_require__(1);
7359173607

7359273608
const pdfjsVersion = '2.13.0';
73593-
const pdfjsBuild = 'da953f4';
73609+
const pdfjsBuild = '23b6fde';
7359473610
})();
7359573611

7359673612
/******/ return __webpack_exports__;

build/pdf.worker.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/viewer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)