Skip to content

Commit

Permalink
Split files into worker and main thread pieces.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandahl committed Aug 12, 2013
1 parent e5cd027 commit 5ecce49
Show file tree
Hide file tree
Showing 41 changed files with 815 additions and 784 deletions.
36 changes: 10 additions & 26 deletions examples/acroforms/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,16 @@
<head>
<!-- In production, only one script (pdf.js) is necessary -->
<!-- In production, change the content of PDFJS.workerSrc below -->
<script type="text/javascript" src="../../src/network.js"></script>
<script type="text/javascript" src="../../src/chunked_stream.js"></script>
<script type="text/javascript" src="../../src/pdf_manager.js"></script>
<script type="text/javascript" src="../../src/core.js"></script>
<script type="text/javascript" src="../../src/util.js"></script>
<script type="text/javascript" src="../../src/api.js"></script>
<script type="text/javascript" src="../../src/canvas.js"></script>
<script type="text/javascript" src="../../src/obj.js"></script>
<script type="text/javascript" src="../../src/annotation.js"></script>
<script type="text/javascript" src="../../src/function.js"></script>
<script type="text/javascript" src="../../src/charsets.js"></script>
<script type="text/javascript" src="../../src/cidmaps.js"></script>
<script type="text/javascript" src="../../src/colorspace.js"></script>
<script type="text/javascript" src="../../src/crypto.js"></script>
<script type="text/javascript" src="../../src/evaluator.js"></script>
<script type="text/javascript" src="../../src/fonts.js"></script>
<script type="text/javascript" src="../../src/glyphlist.js"></script>
<script type="text/javascript" src="../../src/image.js"></script>
<script type="text/javascript" src="../../src/metrics.js"></script>
<script type="text/javascript" src="../../src/parser.js"></script>
<script type="text/javascript" src="../../src/pattern.js"></script>
<script type="text/javascript" src="../../src/stream.js"></script>
<script type="text/javascript" src="../../src/worker.js"></script>
<script type="text/javascript" src="../../external/jpgjs/jpg.js"></script>
<script type="text/javascript" src="../../src/jpx.js"></script>
<script type="text/javascript" src="../../src/jbig2.js"></script>
<script type="text/javascript" src="../../src/shared/util.js"></script>
<script type="text/javascript" src="../../src/shared/colorspace.js"></script>
<script type="text/javascript" src="../../src/shared/pattern.js"></script>
<script type="text/javascript" src="../../src/shared/function.js"></script>
<script type="text/javascript" src="../../src/shared/annotation.js"></script>
<script type="text/javascript" src="../../src/display/api.js"></script>
<script type="text/javascript" src="../../src/display/metadata.js"></script>
<script type="text/javascript" src="../../src/display/canvas.js"></script>
<script type="text/javascript" src="../../src/display/font_loader.js"></script>
<script type="text/javascript" src="../../src/display/font_renderer.js"></script>

<script type="text/javascript">
// Specify the main script used to create a new PDF.JS web worker.
Expand Down
36 changes: 10 additions & 26 deletions examples/helloworld/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,16 @@
<head>
<!-- In production, only one script (pdf.js) is necessary -->
<!-- In production, change the content of PDFJS.workerSrc below -->
<script type="text/javascript" src="../../src/network.js"></script>
<script type="text/javascript" src="../../src/chunked_stream.js"></script>
<script type="text/javascript" src="../../src/pdf_manager.js"></script>
<script type="text/javascript" src="../../src/core.js"></script>
<script type="text/javascript" src="../../src/util.js"></script>
<script type="text/javascript" src="../../src/api.js"></script>
<script type="text/javascript" src="../../src/canvas.js"></script>
<script type="text/javascript" src="../../src/obj.js"></script>
<script type="text/javascript" src="../../src/annotation.js"></script>
<script type="text/javascript" src="../../src/function.js"></script>
<script type="text/javascript" src="../../src/charsets.js"></script>
<script type="text/javascript" src="../../src/cidmaps.js"></script>
<script type="text/javascript" src="../../src/colorspace.js"></script>
<script type="text/javascript" src="../../src/crypto.js"></script>
<script type="text/javascript" src="../../src/evaluator.js"></script>
<script type="text/javascript" src="../../src/fonts.js"></script>
<script type="text/javascript" src="../../src/glyphlist.js"></script>
<script type="text/javascript" src="../../src/image.js"></script>
<script type="text/javascript" src="../../src/metrics.js"></script>
<script type="text/javascript" src="../../src/parser.js"></script>
<script type="text/javascript" src="../../src/pattern.js"></script>
<script type="text/javascript" src="../../src/stream.js"></script>
<script type="text/javascript" src="../../src/worker.js"></script>
<script type="text/javascript" src="../../external/jpgjs/jpg.js"></script>
<script type="text/javascript" src="../../src/jpx.js"></script>
<script type="text/javascript" src="../../src/jbig2.js"></script>
<script type="text/javascript" src="../../src/shared/util.js"></script>
<script type="text/javascript" src="../../src/shared/colorspace.js"></script>
<script type="text/javascript" src="../../src/shared/pattern.js"></script>
<script type="text/javascript" src="../../src/shared/function.js"></script>
<script type="text/javascript" src="../../src/shared/annotation.js"></script>
<script type="text/javascript" src="../../src/display/api.js"></script>
<script type="text/javascript" src="../../src/display/metadata.js"></script>
<script type="text/javascript" src="../../src/display/canvas.js"></script>
<script type="text/javascript" src="../../src/display/font_loader.js"></script>
<script type="text/javascript" src="../../src/display/font_renderer.js"></script>

<script type="text/javascript">
// Specify the main script used to create a new PDF.JS web worker.
Expand Down
153 changes: 88 additions & 65 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
BUILD_DIR = 'build/',
SRC_DIR = 'src/',
BUILD_TARGET = BUILD_DIR + 'pdf.js',
BUILD_WORKER_TARGET = BUILD_DIR + 'pdf.worker.js',
BUILD_TARGETS = [BUILD_TARGET, BUILD_WORKER_TARGET],
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/',
CHROME_BUILD_DIR = BUILD_DIR + '/chrome/',
EXTENSION_SRC_DIR = 'extensions/',
Expand Down Expand Up @@ -107,7 +109,7 @@ target.generic = function() {
['web/locale', GENERIC_DIR + '/web']
],
preprocess: [
[BUILD_TARGET, GENERIC_DIR + BUILD_TARGET],
[BUILD_TARGETS, GENERIC_DIR + BUILD_DIR],
[COMMON_WEB_FILES_PREPROCESS, GENERIC_DIR + '/web']
]
};
Expand Down Expand Up @@ -231,72 +233,93 @@ target.bundle = function(args) {
cd(ROOT_DIR);
echo();
echo('### Bundling files into ' + BUILD_TARGET);
var reg = /\n\/\* -\*- Mode(.|\n)*?Mozilla Foundation(.|\n)*?'use strict';/g;

var SRC_FILES =
['network.js',
'chunked_stream.js',
'pdf_manager.js',
'core.js',
'util.js',
'api.js',
'canvas.js',
'obj.js',
'annotation.js',
'function.js',
'charsets.js',
'cidmaps.js',
'colorspace.js',
'crypto.js',
'evaluator.js',
'fonts.js',
'font_renderer.js',
'glyphlist.js',
'image.js',
'metrics.js',
'parser.js',
'pattern.js',
'stream.js',
'worker.js',
'jpx.js',
'jbig2.js',
'bidi.js',
'metadata.js'];

for (var i = 0, length = excludes.length; i < length; ++i) {
var exclude = excludes[i];
var index = SRC_FILES.indexOf(exclude);
if (index >= 0) {
SRC_FILES.splice(index, 1);
function bundle(filename, dir, SRC_FILES, EXT_SRC_FILES) {
for (var i = 0, length = excludes.length; i < length; ++i) {
var exclude = excludes[i];
var index = SRC_FILES.indexOf(exclude);
if (index >= 0) {
SRC_FILES.splice(index, 1);
}
}
}

var EXT_SRC_FILES = [
'../external/jpgjs/jpg.js'];
var bundle = cat(SRC_FILES),
bundleVersion = EXTENSION_VERSION,
bundleBuild = exec('git log --format="%h" -n 1',
{silent: true}).output.replace('\n', '');

crlfchecker.checkIfCrlfIsPresent(SRC_FILES);

// Strip out all the vim/license headers.
bundle = bundle.replace(reg, '');

// Append external files last since we don't want to modify them.
bundle += cat(EXT_SRC_FILES);

// This just preprocesses the empty pdf.js file, we don't actually want to
// preprocess everything yet since other build targets use this file.
builder.preprocess(filename, dir,
{BUNDLE: bundle,
BUNDLE_VERSION: bundleVersion,
BUNDLE_BUILD: bundleBuild});
}

if (!test('-d', BUILD_DIR))
mkdir(BUILD_DIR);

cd(SRC_DIR);
var bundle = cat(SRC_FILES),
bundleVersion = EXTENSION_VERSION,
bundleBuild = exec('git log --format="%h" -n 1',
{silent: true}).output.replace('\n', '');

crlfchecker.checkIfCrlfIsPresent(SRC_FILES);
var MAIN_SRC_FILES = [
'shared/util.js',
'shared/colorspace.js',
'shared/pattern.js',
'shared/function.js',
'shared/annotation.js',
'display/api.js',
'display/metadata.js',
'display/canvas.js',
'display/font_loader.js',
'display/font_renderer.js'
];

var WORKER_SRC_FILES = [
'shared/util.js',
'shared/pattern.js',
'shared/function.js',
'shared/annotation.js',
'core/network.js',
'core/chunked_stream.js',
'core/pdf_manager.js',
'core/core.js',
'core/obj.js',
'core/charsets.js',
'core/cidmaps.js',
'shared/colorspace.js',
'core/crypto.js',
'core/evaluator.js',
'core/fonts.js',
'core/glyphlist.js',
'core/image.js',
'core/metrics.js',
'core/parser.js',
'core/stream.js',
'core/worker.js',
'core/jpx.js',
'core/jbig2.js',
'core/bidi.js'
];

// Strip out all the vim/license headers.
var reg = /\n\/\* -\*- Mode(.|\n)*?Mozilla Foundation(.|\n)*?'use strict';/g;
bundle = bundle.replace(reg, '');
var EXT_SRC_FILES = [
'../external/jpgjs/jpg.js'
];

// Append external files last since we don't want to modify them.
bundle += cat(EXT_SRC_FILES);
cd(SRC_DIR);

// This just preprocesses the empty pdf.js file, we don't actually want to
// preprocess everything yet since other build targets use this file.
builder.preprocess('pdf.js', ROOT_DIR + BUILD_TARGET,
{BUNDLE: bundle,
BUNDLE_VERSION: bundleVersion,
BUNDLE_BUILD: bundleBuild});
bundle('pdf.js', ROOT_DIR + BUILD_TARGET, MAIN_SRC_FILES, []);
var srcCopy = ROOT_DIR + BUILD_DIR + 'pdf.worker.js.temp';
cp('pdf.js', srcCopy);
bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, WORKER_SRC_FILES,
EXT_SRC_FILES);
rm(srcCopy);
};

function cleanupJSSource(file) {
Expand Down Expand Up @@ -382,7 +405,7 @@ target.firefox = function() {
FIREFOX_AMO_EXTENSION_NAME = 'pdf.js.amo.xpi';

target.locale();
target.bundle({ excludes: ['network.js'] });
target.bundle({ excludes: ['core/network.js'] });
cd(ROOT_DIR);

// Clear out everything in the firefox extension build directory
Expand All @@ -408,8 +431,8 @@ target.firefox = function() {
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
[BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR + BUILD_TARGET],
[SRC_DIR + 'network.js', FIREFOX_BUILD_CONTENT_DIR]
[BUILD_TARGETS, FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR],
[SRC_DIR + 'core/network.js', FIREFOX_BUILD_CONTENT_DIR]
],
preprocessCSS: [
['firefox', 'web/viewer.css',
Expand Down Expand Up @@ -494,7 +517,7 @@ target.mozcentral = function() {
'content',
'LICENSE'];

target.bundle({ excludes: ['network.js'] });
target.bundle({ excludes: ['core/network.js'] });
cd(ROOT_DIR);

// Clear out everything in the firefox extension build directory
Expand Down Expand Up @@ -522,8 +545,8 @@ target.mozcentral = function() {
],
preprocess: [
[COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
[BUILD_TARGET, MOZCENTRAL_CONTENT_DIR + BUILD_TARGET],
[SRC_DIR + 'network.js', MOZCENTRAL_CONTENT_DIR]
[BUILD_TARGETS, MOZCENTRAL_CONTENT_DIR + BUILD_DIR],
[SRC_DIR + 'core/network.js', MOZCENTRAL_CONTENT_DIR]
],
preprocessCSS: [
['firefox', 'web/viewer.css', MOZCENTRAL_CONTENT_DIR + '/web/viewer.css']
Expand Down Expand Up @@ -596,7 +619,7 @@ target.b2g = function() {
],
preprocess: [
['web/viewer.js', B2G_BUILD_CONTENT_DIR + '/web'],
[BUILD_TARGET, B2G_BUILD_CONTENT_DIR + BUILD_TARGET]
[BUILD_TARGETS, B2G_BUILD_CONTENT_DIR + BUILD_DIR]
]
};
builder.build(setup);
Expand Down Expand Up @@ -640,7 +663,7 @@ target.chrome = function() {
['web/locale', CHROME_BUILD_CONTENT_DIR + '/web']
],
preprocess: [
[BUILD_TARGET, CHROME_BUILD_CONTENT_DIR + BUILD_TARGET],
[BUILD_TARGETS, CHROME_BUILD_CONTENT_DIR + BUILD_DIR],
[COMMON_WEB_FILES_PREPROCESS, CHROME_BUILD_CONTENT_DIR + '/web']
]
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 2 additions & 19 deletions src/core.js → src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,14 @@
* limitations under the License.
*/
/* globals assertWellFormed, calculateMD5, Catalog, error, info, isArray,
isArrayBuffer, isDict, isName, isStream, isString, Lexer,
isArrayBuffer, isName, isStream, isString, Lexer,
Linearization, NullStream, PartialEvaluator, shadow, Stream,
StreamsSequenceStream, stringToPDFString, TODO, Util, warn, XRef,
StreamsSequenceStream, stringToPDFString, Util, XRef,
MissingDataException, Promise, Annotation, ObjectLoader, OperatorList
*/

'use strict';

var globalScope = (typeof window === 'undefined') ? this : window;

var isWorker = (typeof window == 'undefined');

var ERRORS = 0, WARNINGS = 1, INFOS = 5;
var verbosity = WARNINGS;

// The global PDFJS object exposes the API
// In production, it will be declared outside a global wrapper
// In development, it will be declared here
if (!globalScope.PDFJS) {
globalScope.PDFJS = {};
}

globalScope.PDFJS.pdfBug = false;


var Page = (function PageClosure() {

function Page(pdfManager, xref, pageIndex, pageDict, ref) {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/evaluator.js → src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
/* globals assert, assertWellFormed, ColorSpace, Dict, Encodings, error,
ErrorFont, Font, FONT_IDENTITY_MATRIX, fontCharsToUnicode, FontFlags,
IDENTITY_MATRIX, info, isArray, isCmd, isDict, isEOF, isName, isNum,
info, isArray, isCmd, isDict, isEOF, isName, isNum,
isStream, isString, JpegStream, Lexer, Metrics, Name, Parser,
Pattern, PDFImage, PDFJS, serifFonts, stdFontMap, symbolsFonts,
TilingPattern, TODO, warn, Util, MissingDataException, Promise,
TilingPattern, TODO, warn, Util, Promise,
RefSetCache, isRef */

'use strict';
Expand Down
Loading

0 comments on commit 5ecce49

Please sign in to comment.