Skip to content

Refactoring text layer builder and converting text layer builder to a class #4991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

timvandermeij
Copy link
Contributor

This work is needed for cleaning up the text layer and for separating the text layer builder from the PDF find controller. This PR consists of four commits for easier reviewing.

The first commit:

  • fixes code style and properly names functions;
  • moves constants to the top of the file;
  • reduces unnecessary typeof usage;
  • caches loop variables;
  • reduces unnecessary in usage;
  • uses strict equalities where possible;
  • removes an old TODO;
  • uses more descriptive variable names;
  • removes the highlightDiv and appendText functions as appendText was just a direct call to appendTextToDiv and highlightDiv has been inlined because in code it is clear what is does, so this saves some function calls.

The second commit:

  • converts the text layer builder to a class.

The third commit:

  • refactors PDFFindController in the text layer builder, thereby removing the last typeof in this file.

The fourth commit:

  • updates the text selection example to remove unnecessary includes.

var textDiv = textDivs[i];
if ('isWhitespace' in textDiv.dataset) {
if (textDiv.dataset.isWhitespace) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it matters in this particular instance, but these expressions aren't actually equal. It needs to be: textDiv.dataset.isWhitespace !== undefined (or textDiv.dataset['isWhitespace'] !== undefined).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does not matter in this case, but to be sure to not change the viewer's behavior I will change it. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in new commit.

@yurydelendik
Copy link
Contributor

can you refactor it to be in the following format:

var TextLayerBuilder = (function TextLayerBuilderClosure() {
  function TextLayerBuilder(options) { ... }
  TextLayerBuilder.prototype = {
    ...
    renderMatches: function TextLayerBuilder_renderMatches(matches) {
    },
    ...
  };
  return TextLayerBuilder;
})();

After that it's easy step/commit to replace PDFFindController to this.findController

@timvandermeij timvandermeij changed the title Refactoring text layer builder [WIP] Refactoring text layer builder Jun 23, 2014
@timvandermeij timvandermeij changed the title [WIP] Refactoring text layer builder Refactoring text layer builder Jun 23, 2014
@timvandermeij timvandermeij changed the title Refactoring text layer builder Refactoring text layer builder and converting text layer builder to a class Jun 23, 2014
@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/3351d620a825bbb/output.txt

@yurydelendik
Copy link
Contributor

Looks good. Can you see if you can change text-selection example to remove findbar and findcontroller links?

yurydelendik added a commit that referenced this pull request Jun 23, 2014
…oring

Refactoring text layer builder and converting text layer builder to a class
@yurydelendik yurydelendik merged commit 6d86c92 into mozilla:master Jun 23, 2014
@yurydelendik
Copy link
Contributor

Thank you

@timvandermeij timvandermeij deleted the text-layer-builder-refactoring branch June 23, 2014 21:03
@timvandermeij timvandermeij added this to the 2014 Q3 milestone Jun 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants