1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge branch 'refs/heads/master' into textsearch

Conflicts:
	web/viewer.css
	web/viewer.html
	web/viewer.js
This commit is contained in:
Artur Adib 2012-05-08 17:22:48 -04:00
commit 2d3ed7fc78
91 changed files with 3260 additions and 5696 deletions

View file

@ -45,7 +45,7 @@ PDFJS.getDocument = function getDocument(source) {
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used
* properties that can be read synchronously.
*/
var PDFDocumentProxy = (function() {
var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
function PDFDocumentProxy(pdfInfo, transport) {
this.pdfInfo = pdfInfo;
this.transport = transport;
@ -69,14 +69,14 @@ var PDFDocumentProxy = (function() {
* @return {Promise} A promise that is resolved with a {PDFPageProxy}
* object.
*/
getPage: function(number) {
getPage: function PDFDocumentProxy_getPage(number) {
return this.transport.getPage(number);
},
/**
* @return {Promise} A promise that is resolved with a lookup table for
* mapping named destinations to reference numbers.
*/
getDestinations: function() {
getDestinations: function PDFDocumentProxy_getDestinations() {
var promise = new PDFJS.Promise();
var destinations = this.pdfInfo.destinations;
promise.resolve(destinations);
@ -97,7 +97,7 @@ var PDFDocumentProxy = (function() {
* ...
* ].
*/
getOutline: function() {
getOutline: function PDFDocumentProxy_getOutline() {
var promise = new PDFJS.Promise();
var outline = this.pdfInfo.outline;
promise.resolve(outline);
@ -109,7 +109,7 @@ var PDFDocumentProxy = (function() {
* available in the information dictionary and similarly metadata is a
* {Metadata} object with information from the metadata section of the PDF.
*/
getMetadata: function() {
getMetadata: function PDFDocumentProxy_getMetadata() {
var promise = new PDFJS.Promise();
var info = this.pdfInfo.info;
var metadata = this.pdfInfo.metadata;
@ -119,7 +119,7 @@ var PDFDocumentProxy = (function() {
});
return promise;
},
destroy: function() {
destroy: function PDFDocumentProxy_destroy() {
this.transport.destroy();
}
};
@ -169,7 +169,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @return {PageViewport} Contains 'width' and 'height' properties along
* with transforms required for rendering.
*/
getViewport: function(scale, rotate) {
getViewport: function PDFPageProxy_getViewport(scale, rotate) {
if (arguments.length < 2)
rotate = this.rotate;
return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
@ -178,7 +178,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @return {Promise} A promise that is resolved with an {array} of the
* annotation objects.
*/
getAnnotations: function() {
getAnnotations: function PDFPageProxy_getAnnotations() {
if (this.annotationsPromise)
return this.annotationsPromise;
@ -198,7 +198,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @return {Promise} A promise that is resolved when the page finishes
* rendering.
*/
render: function(params) {
render: function PDFPageProxy_render(params) {
this.renderInProgress = true;
var promise = new Promise();
@ -257,8 +257,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* For internal use only.
*/
startRenderingFromOperatorList:
function PDFPageWrapper_startRenderingFromOperatorList(operatorList,
fonts) {
function PDFPageProxy_startRenderingFromOperatorList(operatorList,
fonts) {
var self = this;
this.operatorList = operatorList;
@ -279,7 +279,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
/**
* For internal use only.
*/
ensureFonts: function PDFPageWrapper_ensureFonts(fonts, callback) {
ensureFonts: function PDFPageProxy_ensureFonts(fonts, callback) {
this.stats.time('Font Loading');
// Convert the font names to the corresponding font obj.
for (var i = 0, ii = fonts.length; i < ii; i++) {
@ -299,7 +299,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
/**
* For internal use only.
*/
display: function PDFPageWrapper_display(gfx, viewport, callback) {
display: function PDFPageProxy_display(gfx, viewport, callback) {
var stats = this.stats;
stats.time('Rendering');
@ -332,7 +332,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @return {Promise} That is resolved with the a {string} that is the text
* content from the page.
*/
getTextContent: function() {
getTextContent: function PDFPageProxy_getTextContent() {
var promise = new PDFJS.Promise();
this.transport.messageHandler.send('GetTextContent', {
pageIndex: this.pageNumber - 1
@ -346,7 +346,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
/**
* Stub for future feature.
*/
getOperationList: function() {
getOperationList: function PDFPageProxy_getOperationList() {
var promise = new PDFJS.Promise();
var operationList = { // not implemented
dependencyFontsID: null,
@ -358,7 +358,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
/**
* Destroys resources allocated by the page.
*/
destroy: function() {
destroy: function PDFPageProxy_destroy() {
this.destroyed = true;
if (!this.renderInProgress) {

View file

@ -230,6 +230,7 @@ var Page = (function PageClosure() {
case 'http':
case 'https':
case 'ftp':
case 'mailto':
return true;
default:
return false;

View file

@ -557,7 +557,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var toUnicode = dict.get('ToUnicode') ||
baseDict.get('ToUnicode');
if (toUnicode)
properties.toUnicode = this.readToUnicode(toUnicode, xref);
properties.toUnicode = this.readToUnicode(toUnicode, xref, properties);
if (properties.composite) {
// CIDSystemInfo helps to match CID to glyphs
@ -613,7 +613,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
properties.hasEncoding = hasEncoding;
},
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode, xref) {
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode, xref,
properties) {
var cmapObj = toUnicode;
var charToUnicode = [];
if (isName(cmapObj)) {
@ -702,6 +703,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
} else if (octet == 0x3E) {
if (token.length) {
// XXX guessing chars size by checking number size in the CMap
if (token.length <= 2 && properties.composite)
properties.wideChars = false;
if (token.length <= 4) {
// parsing hex number
tokens.push(parseInt(token, 16));
@ -919,6 +924,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
length1: length1,
length2: length2,
composite: composite,
wideChars: composite,
fixedPitch: false,
fontMatrix: dict.get('FontMatrix') || IDENTITY_MATRIX,
firstChar: firstChar || 0,

View file

@ -1519,6 +1519,7 @@ var Font = (function FontClosure() {
this.widths = properties.widths;
this.defaultWidth = properties.defaultWidth;
this.composite = properties.composite;
this.wideChars = properties.wideChars;
this.hasEncoding = properties.hasEncoding;
this.fontMatrix = properties.fontMatrix;
@ -3251,7 +3252,7 @@ var Font = (function FontClosure() {
glyphs = [];
if (this.composite) {
if (this.wideChars) {
// composite fonts have multi-byte strings convert the string from
// single-byte to multi-byte
// XXX assuming CIDFonts are two-byte - later need to extract the

View file

@ -4,8 +4,28 @@
'use strict';
var Metadata = PDFJS.Metadata = (function MetadataClosure() {
function fixMetadata(meta) {
return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
function(code, d1, d2, d3) {
return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
});
var chars = '';
for (var i = 0; i < bytes.length; i += 2) {
var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
chars += code >= 32 && code < 127 && code != 60 && code != 62 &&
code != 38 && false ? String.fromCharCode(code) :
'&#x' + (0x10000 + code).toString(16).substring(1) + ';';
}
return '>' + chars;
});
}
function Metadata(meta) {
if (typeof meta === 'string') {
// Ghostscript produces invalid metadata
meta = fixMetadata(meta);
var parser = new DOMParser();
meta = parser.parseFromString(meta, 'application/xml');
} else if (!(meta instanceof Document)) {

View file

@ -39,7 +39,7 @@ var Dict = (function DictClosure() {
// Map should only be used internally, use functions below to access.
var map = Object.create(null);
this.assignXref = function Dict_assingXref(newXref) {
this.assignXref = function Dict_assignXref(newXref) {
xref = newXref;
};
@ -364,9 +364,8 @@ var XRef = (function XRefClosure() {
}
}
// Sanity check: as per spec, first object must have these properties
if (this.entries[0] &&
!(this.entries[0].gen === 65535 && this.entries[0].free))
// Sanity check: as per spec, first object must be free
if (this.entries[0] && !this.entries[0].free)
error('Invalid XRef table: unexpected first object');
// Sanity check
@ -525,7 +524,7 @@ var XRef = (function XRefClosure() {
}
// reading XRef streams
for (var i = 0, ii = xrefStms.length; i < ii; ++i) {
this.readXRef(xrefStms[i]);
this.readXRef(xrefStms[i], true);
}
// finding main trailer
var dict;
@ -548,7 +547,7 @@ var XRef = (function XRefClosure() {
// nothing helps
error('Invalid PDF structure');
},
readXRef: function XRef_readXRef(startXRef) {
readXRef: function XRef_readXRef(startXRef, recoveryMode) {
var stream = this.stream;
stream.pos = startXRef;
@ -581,16 +580,18 @@ var XRef = (function XRefClosure() {
error('Invalid XRef stream');
}
dict = this.readXRefStream(obj);
if (!dict)
error('Failed to read XRef stream');
}
// Recursively get previous dictionary, if any
obj = dict.get('Prev');
if (isInt(obj))
this.readXRef(obj);
this.readXRef(obj, recoveryMode);
else if (isRef(obj)) {
// The spec says Prev must not be a reference, i.e. "/Prev NNN"
// This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
this.readXRef(obj.num);
this.readXRef(obj.num, recoveryMode);
}
return dict;
@ -598,6 +599,9 @@ var XRef = (function XRefClosure() {
log('(while reading XRef): ' + e);
}
if (recoveryMode)
return;
warn('Indexing all PDF objects');
return this.indexObjects();
},

View file

@ -110,7 +110,7 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
var r1 = raw[6];
return {
type: 'Pattern',
getPattern: function(ctx) {
getPattern: function RadialAxial_getPattern(ctx) {
var curMatrix = ctx.mozCurrentTransform;
if (curMatrix) {
var userMatrix = ctx.mozCurrentTransformInverse;

View file

@ -97,7 +97,7 @@ var Util = PDFJS.Util = (function UtilClosure() {
return [xt, yt];
};
Util.applyInverseTransform = function Util_applyTransform(p, m) {
Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
var d = m[0] * m[3] - m[1] * m[2];
var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;

View file

@ -23,9 +23,9 @@ var files = [
'pattern.js',
'stream.js',
'worker.js',
'../external/jpgjs/jpg.js',
'jpx.js',
'bidi.js'
'bidi.js',
'../external/jpgjs/jpg.js'
];
// Load all the files.