Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Xavier Fung 2012-08-24 23:23:00 +08:00
commit 84f6e2a4e8
6 changed files with 127 additions and 70 deletions

View File

@ -131,29 +131,28 @@ function PdfDataListener(length) {
} }
PdfDataListener.prototype = { PdfDataListener.prototype = {
set: function PdfDataListener_set(chunk, offset) { append: function PdfDataListener_append(chunk) {
if (this.length < 0) { var willBeLoaded = this.loaded + chunk.length;
var willBeLoaded = this.loaded + chunk.length; if (this.length >= 0 && this.length < willBeLoaded) {
this.length = -1; // reset the length, server is giving incorrect one
}
if (this.length < 0 && this.data.length < willBeLoaded) {
// data length is unknown and new chunk will not fit in the existing // data length is unknown and new chunk will not fit in the existing
// buffer, resizing the buffer by doubling the its last length // buffer, resizing the buffer by doubling the its last length
if (this.data.length < willBeLoaded) { var newLength = this.data.length;
var newLength = this.data.length; for (; newLength < willBeLoaded; newLength *= 2) {}
for (; newLength < willBeLoaded; newLength *= 2) {} var newData = new Uint8Array(newLength);
var newData = new Uint8Array(newLength); newData.set(this.data);
newData.set(this.data); this.data = newData;
this.data = newData;
}
this.data.set(chunk, this.loaded);
this.loaded = willBeLoaded;
} else {
this.data.set(chunk, offset);
this.loaded = offset + chunk.length;
this.onprogress(this.loaded, this.length);
} }
this.data.set(chunk, this.loaded);
this.loaded = willBeLoaded;
this.onprogress(this.loaded, this.length >= 0 ? this.length : void(0));
}, },
getData: function PdfDataListener_getData() { getData: function PdfDataListener_getData() {
var data = this.length >= 0 ? this.data : var data = this.data;
this.data.subarray(0, this.loaded); if (this.loaded != data.length)
data = data.subarray(0, this.loaded);
delete this.data; // releasing temporary storage delete this.data; // releasing temporary storage
return data; return data;
}, },
@ -462,7 +461,7 @@ PdfStreamConverter.prototype = {
var binaryStream = this.binaryStream; var binaryStream = this.binaryStream;
binaryStream.setInputStream(aInputStream); binaryStream.setInputStream(aInputStream);
this.dataListener.set(binaryStream.readByteArray(aCount), aOffset); this.dataListener.append(binaryStream.readByteArray(aCount));
}, },
// nsIRequestObserver::onStartRequest // nsIRequestObserver::onStartRequest

105
make.js
View File

@ -1,4 +1,3 @@
#!/usr/bin/env node
require('./external/shelljs/make'); require('./external/shelljs/make');
var builder = require('./external/builder/builder.js'); var builder = require('./external/builder/builder.js');
var crlfchecker = require('./external/crlfchecker/crlfchecker.js'); var crlfchecker = require('./external/crlfchecker/crlfchecker.js');
@ -92,8 +91,9 @@ target.generic = function() {
// //
// make web // make web
// Generates the website for the project, by checking out the gh-pages branch underneath // Generates the website for the project, by checking out the gh-pages branch
// the build directory, and then moving the various viewer files into place. // underneath the build directory, and then moving the various viewer files
// into place.
// //
target.web = function() { target.web = function() {
target.generic(); target.generic();
@ -113,9 +113,9 @@ target.web = function() {
exec('git add -A'); exec('git add -A');
echo(); echo();
echo("Website built in " + GH_PAGES_DIR); echo('Website built in ' + GH_PAGES_DIR);
echo("Don't forget to cd into " + GH_PAGES_DIR + echo('Don\'t forget to cd into ' + GH_PAGES_DIR +
" and issue 'git commit' to push changes."); ' and issue \'git commit\' to push changes.');
}; };
// //
@ -153,7 +153,8 @@ target.locale = function() {
} }
mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale); mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale);
chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' + locale + '/\n'; chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' +
locale + '/\n';
if (test('-f', path + '/viewer.properties')) { if (test('-f', path + '/viewer.properties')) {
var properties = cat(path + '/viewer.properties'); var properties = cat(path + '/viewer.properties');
@ -231,9 +232,10 @@ target.bundle = function() {
// //
// make pagesrepo // make pagesrepo
// //
// This target clones the gh-pages repo into the build directory. It deletes the current contents // This target clones the gh-pages repo into the build directory. It deletes
// of the repo, since we overwrite everything with data from the master repo. The 'make web' target // the current contents of the repo, since we overwrite everything with data
// then uses 'git add -A' to track additions, modifications, moves, and deletions. // from the master repo. The 'make web' target then uses 'git add -A' to track
// additions, modifications, moves, and deletions.
target.pagesrepo = function() { target.pagesrepo = function() {
cd(ROOT_DIR); cd(ROOT_DIR);
echo(); echo();
@ -342,7 +344,8 @@ target.firefox = function() {
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR); mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR);
mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + '/web'); mkdir('-p', FIREFOX_BUILD_CONTENT_DIR + '/web');
cp(FIREFOX_CONTENT_DIR + 'PdfJs-stub.jsm', FIREFOX_BUILD_CONTENT_DIR + 'PdfJs.jsm'); cp(FIREFOX_CONTENT_DIR + 'PdfJs-stub.jsm',
FIREFOX_BUILD_CONTENT_DIR + 'PdfJs.jsm');
// Copy extension files // Copy extension files
cd('extensions/firefox'); cd('extensions/firefox');
@ -368,29 +371,38 @@ target.firefox = function() {
}); });
// Update the build version number // Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION, FIREFOX_BUILD_DIR + '/install.rdf'); sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION, FIREFOX_BUILD_DIR + '/update.rdf'); FIREFOX_BUILD_DIR + '/install.rdf');
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
FIREFOX_BUILD_DIR + '/update.rdf');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, FIREFOX_STREAM_CONVERTER_ID, FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js'); sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, FIREFOX_STREAM_CONVERTER_ID,
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, FIREFOX_PREF_PREFIX, FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js'); FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'false', FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js'); sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, FIREFOX_PREF_PREFIX,
FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'false',
FIREFOX_BUILD_DIR + 'components/PdfStreamConverter.js');
// Update localized metadata // Update localized metadata
var localizedMetadata = cat(EXTENSION_SRC_DIR + '/firefox/metadata.inc'); var localizedMetadata = cat(EXTENSION_SRC_DIR + '/firefox/metadata.inc');
sed('-i', /.*PDFJS_LOCALIZED_METADATA.*\n/, localizedMetadata, FIREFOX_BUILD_DIR + '/install.rdf'); sed('-i', /.*PDFJS_LOCALIZED_METADATA.*\n/, localizedMetadata,
FIREFOX_BUILD_DIR + '/install.rdf');
var chromeManifest = cat(EXTENSION_SRC_DIR + '/firefox/chrome.manifest.inc'); var chromeManifest = cat(EXTENSION_SRC_DIR + '/firefox/chrome.manifest.inc');
sed('-i', /.*PDFJS_SUPPORTED_LOCALES.*\n/, chromeManifest, FIREFOX_BUILD_DIR + '/chrome.manifest'); sed('-i', /.*PDFJS_SUPPORTED_LOCALES.*\n/, chromeManifest,
FIREFOX_BUILD_DIR + '/chrome.manifest');
// Create the xpi // Create the xpi
cd(FIREFOX_BUILD_DIR); cd(FIREFOX_BUILD_DIR);
exec('zip -r ' + FIREFOX_EXTENSION_NAME + ' ' + FIREFOX_EXTENSION_FILES.join(' ')); exec('zip -r ' + FIREFOX_EXTENSION_NAME + ' ' +
FIREFOX_EXTENSION_FILES.join(' '));
echo('extension created: ' + FIREFOX_EXTENSION_NAME); echo('extension created: ' + FIREFOX_EXTENSION_NAME);
cd(ROOT_DIR); cd(ROOT_DIR);
// Build the amo extension too (remove the updateUrl) // Build the amo extension too (remove the updateUrl)
cd(FIREFOX_BUILD_DIR); cd(FIREFOX_BUILD_DIR);
sed('-i', /.*updateURL.*\n/, '', 'install.rdf'); sed('-i', /.*updateURL.*\n/, '', 'install.rdf');
exec('zip -r ' + FIREFOX_AMO_EXTENSION_NAME + ' ' + FIREFOX_EXTENSION_FILES.join(' ')); exec('zip -r ' + FIREFOX_AMO_EXTENSION_NAME + ' ' +
FIREFOX_EXTENSION_FILES.join(' '));
echo('AMO extension created: ' + FIREFOX_AMO_EXTENSION_NAME); echo('AMO extension created: ' + FIREFOX_AMO_EXTENSION_NAME);
cd(ROOT_DIR); cd(ROOT_DIR);
}; };
@ -438,13 +450,14 @@ target.mozcentral = function() {
mkdir('-p', MOZCENTRAL_CONTENT_DIR + BUILD_DIR); mkdir('-p', MOZCENTRAL_CONTENT_DIR + BUILD_DIR);
mkdir('-p', MOZCENTRAL_CONTENT_DIR + '/web'); mkdir('-p', MOZCENTRAL_CONTENT_DIR + '/web');
cp(FIREFOX_CONTENT_DIR + 'PdfJs.jsm', MOZCENTRAL_CONTENT_DIR) cp(FIREFOX_CONTENT_DIR + 'PdfJs.jsm', MOZCENTRAL_CONTENT_DIR);
// Copy extension files // Copy extension files
cd('extensions/firefox'); cd('extensions/firefox');
cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR + MOZCENTRAL_EXTENSION_DIR); cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY,
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR);
mv('-f', ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome-mozcentral.manifest', mv('-f', ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome-mozcentral.manifest',
ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest') ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest');
cd(ROOT_DIR); cd(ROOT_DIR);
var setup = { var setup = {
@ -469,18 +482,22 @@ target.mozcentral = function() {
cp(DEFAULT_LOCALE_FILES, MOZCENTRAL_L10N_DIR); cp(DEFAULT_LOCALE_FILES, MOZCENTRAL_L10N_DIR);
// Update the build version number // Update the build version number
sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION, MOZCENTRAL_EXTENSION_DIR + 'README.mozilla'); sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION,
MOZCENTRAL_EXTENSION_DIR + 'README.mozilla');
sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, MOZCENTRAL_STREAM_CONVERTER_ID, MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js'); sed('-i', /PDFJSSCRIPT_STREAM_CONVERTER_ID/, MOZCENTRAL_STREAM_CONVERTER_ID,
sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, MOZCENTRAL_PREF_PREFIX, MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js'); MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'true', MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js'); sed('-i', /PDFJSSCRIPT_PREF_PREFIX/, MOZCENTRAL_PREF_PREFIX,
MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js');
sed('-i', /PDFJSSCRIPT_MOZ_CENTRAL/, 'true',
MOZCENTRAL_EXTENSION_DIR + 'components/PdfStreamConverter.js');
// List all files for mozilla-central // List all files for mozilla-central
cd(MOZCENTRAL_EXTENSION_DIR); cd(MOZCENTRAL_EXTENSION_DIR);
var extensionFiles = ''; var extensionFiles = '';
find(FIREFOX_MC_EXTENSION_FILES).forEach(function(file){ find(FIREFOX_MC_EXTENSION_FILES).forEach(function(file) {
if (test('-f', file)) if (test('-f', file))
extensionFiles += file+'\n'; extensionFiles += file + '\n';
}); });
extensionFiles.to('extension-files'); extensionFiles.to('extension-files');
cd(ROOT_DIR); cd(ROOT_DIR);
@ -546,7 +563,8 @@ target.chrome = function() {
defines: defines, defines: defines,
copy: [ copy: [
[COMMON_WEB_FILES, CHROME_BUILD_CONTENT_DIR + '/web'], [COMMON_WEB_FILES, CHROME_BUILD_CONTENT_DIR + '/web'],
[['extensions/chrome/*.json', 'extensions/chrome/*.html'], CHROME_BUILD_DIR], [['extensions/chrome/*.json', 'extensions/chrome/*.html'],
CHROME_BUILD_DIR],
[BUILD_TARGET, CHROME_BUILD_CONTENT_DIR + BUILD_TARGET], [BUILD_TARGET, CHROME_BUILD_CONTENT_DIR + BUILD_TARGET],
['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web'] ['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web']
], ],
@ -592,19 +610,20 @@ target.browsertest = function(options) {
echo('### Running browser tests'); echo('### Running browser tests');
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json', var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
PDF_BROWSERS = env['PDF_BROWSERS'] || 'resources/browser_manifests/browser_manifest.json'; PDF_BROWSERS = env['PDF_BROWSERS'] ||
'resources/browser_manifests/browser_manifest.json';
if (!test('-f', 'test/' + PDF_BROWSERS)) { if (!test('-f', 'test/' + PDF_BROWSERS)) {
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.'); echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
echo('Try copying one of the examples in test/resources/browser_manifests/'); echo('Copy one of the examples in test/resources/browser_manifests/');
exit(1); exit(1);
} }
var reftest = (options && options.noreftest) ? '' : '--reftest'; var reftest = (options && options.noreftest) ? '' : '--reftest';
cd('test'); cd('test');
exec(PYTHON_BIN + ' -u test.py '+reftest+' --browserManifestFile=' + PDF_BROWSERS + exec(PYTHON_BIN + ' -u test.py ' + reftest + ' --browserManifestFile=' +
' --manifestFile=' + PDF_TEST, {async: true}); PDF_BROWSERS + ' --manifestFile=' + PDF_TEST, {async: true});
}; };
// //
@ -615,17 +634,18 @@ target.unittest = function(options, callback) {
echo(); echo();
echo('### Running unit tests'); echo('### Running unit tests');
var PDF_BROWSERS = env['PDF_BROWSERS'] || 'resources/browser_manifests/browser_manifest.json'; var PDF_BROWSERS = env['PDF_BROWSERS'] ||
'resources/browser_manifests/browser_manifest.json';
if (!test('-f', 'test/' + PDF_BROWSERS)) { if (!test('-f', 'test/' + PDF_BROWSERS)) {
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.'); echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
echo('Try copying one of the examples in test/resources/browser_manifests/'); echo('Copy one of the examples in test/resources/browser_manifests/');
exit(1); exit(1);
} }
callback = callback || function() {}; callback = callback || function() {};
cd('test'); cd('test');
exec(PYTHON_BIN + ' -u test.py --unitTest --browserManifestFile=' + PDF_BROWSERS, exec(PYTHON_BIN + ' -u test.py --unitTest --browserManifestFile=' +
{async: true}, callback); PDF_BROWSERS, {async: true}, callback);
}; };
// //
@ -637,17 +657,18 @@ target.botmakeref = function() {
echo('### Creating reference images'); echo('### Creating reference images');
var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json', var PDF_TEST = env['PDF_TEST'] || 'test_manifest.json',
PDF_BROWSERS = env['PDF_BROWSERS'] || 'resources/browser_manifests/browser_manifest.json'; PDF_BROWSERS = env['PDF_BROWSERS'] ||
'resources/browser_manifests/browser_manifest.json';
if (!test('-f', 'test/' + PDF_BROWSERS)) { if (!test('-f', 'test/' + PDF_BROWSERS)) {
echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.'); echo('Browser manifest file test/' + PDF_BROWSERS + ' does not exist.');
echo('Try copying one of the examples in test/resources/browser_manifests/'); echo('Copy one of the examples in test/resources/browser_manifests/');
exit(1); exit(1);
} }
cd('test'); cd('test');
exec(PYTHON_BIN + ' -u test.py --masterMode --noPrompts --browserManifestFile=' + PDF_BROWSERS, exec(PYTHON_BIN + ' -u test.py --masterMode --noPrompts ' +
{async: true}); '--browserManifestFile=' + PDF_BROWSERS, {async: true});
}; };

View File

@ -574,8 +574,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var flags = properties.flags; var flags = properties.flags;
var differences = []; var differences = [];
var baseEncoding = !!(flags & FontFlags.Symbolic) ? var baseEncoding = Encodings.StandardEncoding;
Encodings.symbolsEncoding : Encodings.StandardEncoding; // 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 :
Encodings.MacRomanEncoding;
}
var hasEncoding = dict.has('Encoding'); var hasEncoding = dict.has('Encoding');
if (hasEncoding) { if (hasEncoding) {
var encoding = dict.get('Encoding'); var encoding = dict.get('Encoding');

View File

@ -135,12 +135,10 @@ var WorkerMessageHandler = {
{ {
url: source.url, url: source.url,
progress: function getPDFProgress(evt) { progress: function getPDFProgress(evt) {
if (evt.lengthComputable) { handler.send('DocProgress', {
handler.send('DocProgress', { loaded: evt.loaded,
loaded: evt.loaded, total: evt.lengthComputable ? evt.total : void(0)
total: evt.total });
});
}
}, },
error: function getPDFError(e) { error: function getPDFError(e) {
handler.send('DocError', 'Unexpected server response of ' + handler.send('DocError', 'Unexpected server response of ' +

View File

@ -1025,6 +1025,28 @@ canvas {
border-bottom-right-radius: 2px; border-bottom-right-radius: 2px;
} }
#loadingBar .progress.indeterminate {
width: 100%;
height: 25px;
background-image: -moz-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
background-image: -webkit-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
background-image: -ms-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
background-image: -o-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
background-size: 75px 25px;
-moz-animation: progressIndeterminate 1s linear infinite;
-webkit-animation: progressIndeterminate 1s linear infinite;
}
@-moz-keyframes progressIndeterminate {
from { background-position: 0px 0px; }
to { background-position: 75px 0px; }
}
@-webkit-keyframes progressIndeterminate {
from { background-position: 0px 0px; }
to { background-position: 75px 0px; }
}
.textLayer { .textLayer {
position: absolute; position: absolute;
left: 0; left: 0;

View File

@ -60,7 +60,6 @@ var ProgressBar = (function ProgressBarClosure() {
this.height = opts.height || 100; this.height = opts.height || 100;
this.width = opts.width || 100; this.width = opts.width || 100;
this.units = opts.units || '%'; this.units = opts.units || '%';
this.percent = opts.percent || 0;
// Initialize heights // Initialize heights
this.div.style.height = this.height + this.units; this.div.style.height = this.height + this.units;
@ -69,10 +68,18 @@ var ProgressBar = (function ProgressBarClosure() {
ProgressBar.prototype = { ProgressBar.prototype = {
updateBar: function ProgressBar_updateBar() { updateBar: function ProgressBar_updateBar() {
if (this._indeterminate) {
this.div.classList.add('indeterminate');
return;
}
var progressSize = this.width * this._percent / 100; var progressSize = this.width * this._percent / 100;
if (this._percent > 95) if (this._percent > 95)
this.div.classList.add('full'); this.div.classList.add('full');
else
this.div.classList.remove('full');
this.div.classList.remove('indeterminate');
this.div.style.width = progressSize + this.units; this.div.style.width = progressSize + this.units;
}, },
@ -82,6 +89,7 @@ var ProgressBar = (function ProgressBarClosure() {
}, },
set percent(val) { set percent(val) {
this._indeterminate = isNaN(val);
this._percent = clamp(val, 0, 100); this._percent = clamp(val, 0, 100);
this.updateBar(); this.updateBar();
} }
@ -572,6 +580,10 @@ var PDFView = {
} }
} }
} }
var loadingBox = document.getElementById('loadingBox');
loadingBox.setAttribute('hidden', 'true');
//#if !(FIREFOX || MOZCENTRAL) //#if !(FIREFOX || MOZCENTRAL)
var errorWrapper = document.getElementById('errorWrapper'); var errorWrapper = document.getElementById('errorWrapper');
errorWrapper.removeAttribute('hidden'); errorWrapper.removeAttribute('hidden');