andreasgal/pdf.js — Issue #646: Code organization
Author: arturadib
Created: 2011-10-10 20:23:44+00:00
State: open
Labels: 1-other

I've spent quite some time "reverse-engineering" our file `pdf.js`, mostly trying to understand class dependency and purpose so we can break up our 7,000-line-long file into smaller parts. Hopefully I'll also add some comments/documentation along the way.

The original goal was simply to factor out our Canvas backend so I could hack on a new HTML5 backend experiment for text selection, but this turned into a bit of a dependency nightmare that I couldn't quite wrap my head around. So now the goal is to refactor the code to make it more readily understandable by beginner contributors like myself and others (see Issue #559).

The breakdown I'm proposing is as below. **Please correct any misunderstanding in the logical arrangement here!** The arrows indicate class dependency (i.e. instantiation), and the numbers indicate the order in which a few select (major) calls take place:

+ Full size Image: http://i.imgur.com/0o8bN.png

![the-web](http://i.imgur.com/0o8bN.png)

I know we have a major web worker patch probably landing soon (#635), which will change some of this. I'm not exactly sure how to proceed. I can conceivably revisit this map after the patch lands, but my understanding is that the patch itself is largely a work-in-progress and there are some additional "refactoring" necessary.

The plan was for @brendandahl and myself to do this reorg together while I'm in MV, but I wanted to check with everyone and see what the best plan might be.

So to sum up what I'm asking:

+ Please let me know if the logical breakdown makes sense
+ Is everyone OK with breaking up `pdf.js` into the proposed files?
+ What's the best plan-of-action for tackling this change + Julian's web worker stuff?
+ Is next week OK with everyone? That might require pausing all pull requests until our patch lands.

Thanks! Hopefully this will be useful for the project.

@cgjones @brendandahl @jviereck @vingtetun @notmasteryet @andreasgal @devongovett