Bug 937670 - Update pdf.js to version 0.8.681. r=bdahl

This commit is contained in:
Ryan VanderMeulen 2013-11-15 21:47:02 -05:00
parent d58558034d
commit 209381c745
4 changed files with 139 additions and 36 deletions

View File

@ -1,4 +1,4 @@
This is the pdf.js project output, https://github.com/mozilla/pdf.js
Current extension version is: 0.8.641
Current extension version is: 0.8.681

View File

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '0.8.641';
PDFJS.build = '19485c3';
PDFJS.version = '0.8.681';
PDFJS.build = '48c672b';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -3858,7 +3858,7 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
if (action) {
var linkType = action.get('S').name;
if (linkType === 'URI') {
var url = action.get('URI');
var url = addDefaultProtocolToUrl(action.get('URI'));
// TODO: pdf spec mentions urls can be relative to a Base
// entry in the dictionary.
if (!isValidUrl(url, false)) {
@ -3894,6 +3894,14 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
}
}
// Lets URLs beginning with 'www.' default to using the 'http://' protocol.
function addDefaultProtocolToUrl(url) {
if (url.indexOf('www.') === 0) {
return ('http://' + url);
}
return url;
}
Util.inherit(LinkAnnotation, Annotation, {
hasOperatorList: function LinkAnnotation_hasOperatorList() {
return false;
@ -4449,11 +4457,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
if (supportTypedArray) {
this.worker = worker;
this.setupMessageHandler(messageHandler);
workerInitializedPromise.resolve();
} else {
globalScope.PDFJS.disableWorker = true;
this.setupFakeWorker();
this.loadFakeWorkerFiles().then(function() {
this.setupFakeWorker();
workerInitializedPromise.resolve();
}.bind(this));
}
workerInitializedPromise.resolve();
}.bind(this));
var testObj = new Uint8Array(1);
@ -6576,10 +6587,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
group.bbox,
currentCtx.mozCurrentTransform);
// Clip the bounding box to the current canvas.
bounds = Util.intersect(bounds, [0,
0,
currentCtx.canvas.width,
currentCtx.canvas.height]);
var canvasBounds = [0,
0,
currentCtx.canvas.width,
currentCtx.canvas.height];
bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
// Use ceil in case we're between sizes so we don't create canvas that is
// too small and make the canvas at least 1x1 pixels.
var drawnWidth = Math.max(Math.ceil(bounds[2] - bounds[0]), 1);

View File

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '0.8.641';
PDFJS.build = '19485c3';
PDFJS.version = '0.8.681';
PDFJS.build = '48c672b';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -2994,7 +2994,7 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
if (action) {
var linkType = action.get('S').name;
if (linkType === 'URI') {
var url = action.get('URI');
var url = addDefaultProtocolToUrl(action.get('URI'));
// TODO: pdf spec mentions urls can be relative to a Base
// entry in the dictionary.
if (!isValidUrl(url, false)) {
@ -3030,6 +3030,14 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
}
}
// Lets URLs beginning with 'www.' default to using the 'http://' protocol.
function addDefaultProtocolToUrl(url) {
if (url.indexOf('www.') === 0) {
return ('http://' + url);
}
return url;
}
Util.inherit(LinkAnnotation, Annotation, {
hasOperatorList: function LinkAnnotation_hasOperatorList() {
return false;
@ -14909,7 +14917,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// The Symbolic attribute can be misused for regular fonts
// Heuristic: we have to check if the font is a standard one also
if (!!(flags & FontFlags.Symbolic)) {
baseEncoding = !properties.file ? Encodings.symbolsEncoding :
baseEncoding = !properties.file ? Encodings.SymbolSetEncoding :
Encodings.MacRomanEncoding;
}
if (dict.has('Encoding')) {
@ -15756,8 +15764,8 @@ var Encodings = {
'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
'ydieresis'],
symbolsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
@ -18607,6 +18615,17 @@ var Font = (function FontClosure() {
error('cmap table has unsupported format: ' + format);
}
// removing duplicate entries
mappings.sort(function (a, b) {
return a.charcode - b.charcode;
});
for (var i = 1; i < mappings.length; i++) {
if (mappings[i - 1].charcode === mappings[i].charcode) {
mappings.splice(i, 1);
i--;
}
}
return {
platformId: potentialTable.platformId,
encodingId: potentialTable.encodingId,
@ -18694,6 +18713,10 @@ var Font = (function FontClosure() {
coordinatesLength += repeat * xyLength;
}
}
// glyph without coordinates will be rejected
if (coordinatesLength === 0) {
return 0;
}
var glyphDataLength = j + coordinatesLength;
if (glyphDataLength > glyf.length) {
// not enough data for coordinates
@ -18792,6 +18815,13 @@ var Font = (function FontClosure() {
};
}
var locaData = loca.data;
var locaDataSize = itemSize * (1 + numGlyphs);
// is loca.data too short or long?
if (locaData.length !== locaDataSize) {
locaData = new Uint8Array(locaDataSize);
locaData.set(loca.data.subarray(0, locaDataSize));
loca.data = locaData;
}
// removing the invalid glyphs
var oldGlyfData = glyf.data;
var oldGlyfDataLength = oldGlyfData.length;
@ -18835,9 +18865,7 @@ var Font = (function FontClosure() {
glyf.data.set(newGlyfData.subarray(0, writeOffset));
}
glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
loca.data = new Uint8Array(locaData.length + itemSize);
loca.data.set(locaData);
itemEncode(loca.data, locaData.length,
itemEncode(loca.data, locaData.length - itemSize,
writeOffset + firstEntryLength);
} else {
glyf.data = newGlyfData.subarray(0, writeOffset);
@ -19037,6 +19065,11 @@ var Font = (function FontClosure() {
callstack.push({data: data, i: i, stackTop: stack.length - 1});
functionsCalled.push(funcId);
var pc = ttContext.functionsDefined[funcId];
if (!pc) {
warn('TT: CALL non-existent function');
ttContext.hintsValid = false;
return;
}
data = pc.data;
i = pc.i;
}
@ -19057,6 +19090,11 @@ var Font = (function FontClosure() {
lastEndf = i;
} else {
var pc = callstack.pop();
if (!pc) {
warn('TT: ENDF bad stack');
ttContext.hintsValid = false;
return;
}
var funcId = functionsCalled.pop();
data = pc.data;
i = pc.i;
@ -19156,7 +19194,7 @@ var Font = (function FontClosure() {
}
}
function sanitizeTTPrograms(fpgm, prep) {
function sanitizeTTPrograms(fpgm, prep, cvt) {
var ttContext = {
functionsDefined: [],
functionsUsed: [],
@ -19173,6 +19211,11 @@ var Font = (function FontClosure() {
if (fpgm) {
checkInvalidFunctions(ttContext, maxFunctionDefs);
}
if (cvt && (cvt.length & 1)) {
var cvtData = new Uint8Array(cvt.length + 1);
cvtData.set(cvt.data);
cvt.data = cvtData;
}
return ttContext.hintsValid;
}
@ -19192,6 +19235,9 @@ var Font = (function FontClosure() {
if (VALID_TABLES.indexOf(table.tag) < 0) {
continue; // skipping table if it's not a required or optional table
}
if (table.length === 0) {
continue; // skipping empty tables
}
tables[table.tag] = table;
}
@ -19226,7 +19272,14 @@ var Font = (function FontClosure() {
var numGlyphs = int16(font.getBytes(2));
var maxFunctionDefs = 0;
if (version >= 0x00010000 && tables.maxp.length >= 22) {
font.pos += 14;
// maxZones can be invalid
font.pos += 8;
var maxZones = int16(font.getBytes(2));
if (maxZones > 2) { // reset to 2 if font has invalid maxZones
tables.maxp.data[14] = 0;
tables.maxp.data[15] = 2;
}
font.pos += 4;
maxFunctionDefs = int16(font.getBytes(2));
}
@ -19241,10 +19294,11 @@ var Font = (function FontClosure() {
}
var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
maxFunctionDefs);
tables['cvt '], maxFunctionDefs);
if (!hintsValid) {
delete tables.fpgm;
delete tables.prep;
delete tables['cvt '];
}
// Tables needs to be written by ascendant alphabetic order
@ -19278,7 +19332,6 @@ var Font = (function FontClosure() {
if (isTrueType) {
var isGlyphLocationsLong = int16([tables.head.data[50],
tables.head.data[51]]);
sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
isGlyphLocationsLong, hintsValid, dupFirstEntry);
}
@ -20082,8 +20135,10 @@ var Font = (function FontClosure() {
var glyph = this.charToGlyph(charcode);
glyphs.push(glyph);
// placing null after each word break charcode (ASCII SPACE)
if (charcode == 0x20)
// Ignore occurences of 0x20 in multiple-byte codes.
if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
glyphs.push(null);
}
}
}
else {
@ -20725,13 +20780,21 @@ var Type1Parser = (function Type1ParserClosure() {
for (var j = 0; j < size; j++) {
var token = this.getToken();
if (token === 'dup') {
var index = this.readInt();
this.getToken(); // read in '/'
var glyph = this.getToken();
encoding[index] = glyph;
this.getToken(); // read the in 'put'
// skipping till first dup or def (e.g. ignoring for statement)
while (token !== 'dup' && token !== 'def') {
token = this.getToken();
if (token === null) {
return; // invalid header
}
}
if (token === 'def') {
break; // read all array data
}
var index = this.readInt();
this.getToken(); // read in '/'
var glyph = this.getToken();
encoding[index] = glyph;
this.getToken(); // read the in 'put'
}
}
if (properties.overridableEncoding && encoding) {
@ -20739,6 +20802,13 @@ var Type1Parser = (function Type1ParserClosure() {
break;
}
break;
case 'FontBBox':
var fontBBox = this.readNumberArray();
// adjusting ascent/descent
properties.ascent = fontBBox[3];
properties.descent = fontBBox[1];
properties.ascentScaled = true;
break;
}
}
}
@ -20821,13 +20891,33 @@ var CFFStandardStrings = [
// Type1Font is also a CIDFontType0.
var Type1Font = function Type1Font(name, file, properties) {
// Some bad generators embed pfb file as is, we have to strip 6-byte headers.
// Also, length1 and length2 might be off by 6 bytes as well.
// http://www.math.ubc.ca/~cass/piscript/type1.pdf
var PFB_HEADER_SIZE = 6;
var headerBlockLength = properties.length1;
var eexecBlockLength = properties.length2;
var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
var pfbHeaderPresent = pfbHeader[0] == 0x80 && pfbHeader[1] == 0x01;
if (pfbHeaderPresent) {
file.skip(PFB_HEADER_SIZE);
headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
(pfbHeader[3] << 8) | pfbHeader[2];
}
// Get the data block containing glyphs and subrs informations
var headerBlock = new Stream(file.getBytes(properties.length1));
var headerBlock = new Stream(file.getBytes(headerBlockLength));
var headerBlockParser = new Type1Parser(headerBlock);
headerBlockParser.extractFontHeader(properties);
if (pfbHeaderPresent) {
pfbHeader = file.getBytes(PFB_HEADER_SIZE);
eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
(pfbHeader[3] << 8) | pfbHeader[2];
}
// Decrypt the data blocks and retrieve it's content
var eexecBlock = new Stream(file.getBytes(properties.length2));
var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
var eexecBlockParser = new Type1Parser(eexecBlock, true);
var data = eexecBlockParser.extractFontProgram();
for (var info in data.properties)

View File

@ -30,6 +30,7 @@ var CACHE_SIZE = 20;
var CSS_UNITS = 96.0 / 72.0;
var SCROLLBAR_PADDING = 40;
var VERTICAL_PADDING = 5;
var MAX_AUTO_SCALE = 1.25;
var MIN_SCALE = 0.25;
var MAX_SCALE = 4.0;
var SETTINGS_MEMORY = 20;
@ -1813,7 +1814,7 @@ var PDFView = {
scale = Math.min(pageWidthScale, pageHeightScale);
break;
case 'auto':
scale = Math.min(1.0, pageWidthScale);
scale = Math.min(MAX_AUTO_SCALE, pageWidthScale);
break;
}
}
@ -3253,7 +3254,7 @@ var PageView = function pageView(container, id, scale,
// since aligning the bottom of the intended page with the
// top of the window is rarely helpful).
x = x !== null ? x : 0;
y = y !== null ? y : this.height / this.scale;
y = y !== null ? y : (this.height / this.scale) / CSS_UNITS;
break;
case 'Fit':
case 'FitB':
@ -4383,8 +4384,8 @@ function updateViewarea() {
var currentScale = PDFView.currentScale;
var currentScaleValue = PDFView.currentScaleValue;
var normalizedScaleValue = currentScaleValue == currentScale ?
currentScale * 100 : currentScaleValue;
var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ?
Math.round(currentScale * 10000) / 100 : currentScaleValue;
var pageNumber = firstPage.id;
var pdfOpenParams = '#page=' + pageNumber;