Skip to content

Commit

Permalink
Fix coding style in web/text_layer_builder.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffleupagus committed Mar 10, 2014
1 parent 9e0ed5c commit 5dcc924
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions web/text_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ var TextLayerBuilder = function textLayerBuilder(options) {
this.viewport = options.viewport;
this.isViewerInPresentationMode = options.isViewerInPresentationMode;

if(typeof PDFFindController === 'undefined') {
window.PDFFindController = null;
if (typeof PDFFindController === 'undefined') {
window.PDFFindController = null;
}

if(typeof this.lastScrollSource === 'undefined') {
this.lastScrollSource = null;
if (typeof this.lastScrollSource === 'undefined') {
this.lastScrollSource = null;
}

this.beginLayout = function textLayerBuilderBeginLayout() {
Expand All @@ -67,8 +67,9 @@ var TextLayerBuilder = function textLayerBuilder(options) {
// No point in rendering so many divs as it'd make the browser unusable
// even after the divs are rendered
var MAX_TEXT_DIVS_TO_RENDER = 100000;
if (textDivs.length > MAX_TEXT_DIVS_TO_RENDER)
if (textDivs.length > MAX_TEXT_DIVS_TO_RENDER) {
return;
}

for (var i = 0, ii = textDivs.length; i < ii; i++) {
var textDiv = textDivs[i];
Expand Down Expand Up @@ -100,16 +101,17 @@ var TextLayerBuilder = function textLayerBuilder(options) {
// run it right away
var RENDER_DELAY = 200; // in ms
var self = this;
var lastScroll = this.lastScrollSource === null ?
0 : this.lastScrollSource.lastScroll;
var lastScroll = (this.lastScrollSource === null ?
0 : this.lastScrollSource.lastScroll);

if (Date.now() - lastScroll > RENDER_DELAY) {
// Render right away
this.renderLayer();
} else {
// Schedule
if (this.renderTimer)
if (this.renderTimer) {
clearTimeout(this.renderTimer);
}
this.renderTimer = setTimeout(function() {
self.setupRenderLayoutTimer();
}, RENDER_DELAY);
Expand All @@ -127,8 +129,8 @@ var TextLayerBuilder = function textLayerBuilder(options) {

textDiv.style.fontSize = fontHeight + 'px';
textDiv.style.fontFamily = geom.fontFamily;
var fontAscent = geom.ascent ? geom.ascent * fontHeight :
geom.descent ? (1 + geom.descent) * fontHeight : fontHeight;
var fontAscent = (geom.ascent ? geom.ascent * fontHeight :
(geom.descent ? (1 + geom.descent) * fontHeight : fontHeight));
textDiv.style.left = (geom.x + (fontAscent * Math.sin(geom.angle))) + 'px';
textDiv.style.top = (geom.y - (fontAscent * Math.cos(geom.angle))) + 'px';

Expand All @@ -140,8 +142,9 @@ var TextLayerBuilder = function textLayerBuilder(options) {
this.insertDivContent = function textLayerUpdateTextContent() {
// Only set the content of the divs once layout has finished, the content
// for the divs is available and content is not yet set on the divs.
if (!this.layoutDone || this.divContentDone || !this.textContent)
if (!this.layoutDone || this.divContentDone || !this.textContent) {
return;
}

this.divContentDone = true;

Expand Down Expand Up @@ -180,8 +183,8 @@ var TextLayerBuilder = function textLayerBuilder(options) {
var iIndex = 0;
var bidiTexts = this.textContent;
var end = bidiTexts.length - 1;
var queryLen = PDFFindController === null ?
0 : PDFFindController.state.query.length;
var queryLen = (PDFFindController === null ?
0 : PDFFindController.state.query.length);

var lastDivIdx = -1;
var pos;
Expand Down Expand Up @@ -240,14 +243,14 @@ var TextLayerBuilder = function textLayerBuilder(options) {
var bidiTexts = this.textContent;
var textDivs = this.textDivs;
var prevEnd = null;
var isSelectedPage = PDFFindController === null ?
false : (this.pageIdx === PDFFindController.selected.pageIdx);
var isSelectedPage = (PDFFindController === null ?
false : (this.pageIdx === PDFFindController.selected.pageIdx));

var selectedMatchIdx = PDFFindController === null ?
-1 : PDFFindController.selected.matchIdx;
var selectedMatchIdx = (PDFFindController === null ?
-1 : PDFFindController.selected.matchIdx);

var highlightAll = PDFFindController === null ?
false : PDFFindController.state.highlightAll;
var highlightAll = (PDFFindController === null ?
false : PDFFindController.state.highlightAll);

var infty = {
divIdx: -1,
Expand Down Expand Up @@ -346,8 +349,9 @@ var TextLayerBuilder = function textLayerBuilder(options) {

this.updateMatches = function textLayerUpdateMatches() {
// Only show matches, once all rendering is done.
if (!this.renderingDone)
if (!this.renderingDone) {
return;
}

// Clear out all matches.
var matches = this.matches;
Expand All @@ -367,14 +371,14 @@ var TextLayerBuilder = function textLayerBuilder(options) {
clearedUntilDivIdx = match.end.divIdx + 1;
}

if (PDFFindController === null || !PDFFindController.active)
if (PDFFindController === null || !PDFFindController.active) {
return;
}

// Convert the matches on the page controller into the match format used
// for the textLayer.
this.matches = matches =
this.convertMatches(PDFFindController === null ?
[] : (PDFFindController.pageMatches[this.pageIdx] || []));
this.matches = matches = (this.convertMatches(PDFFindController === null ?
[] : (PDFFindController.pageMatches[this.pageIdx] || [])));

this.renderMatches(this.matches);
};
Expand Down

0 comments on commit 5dcc924

Please sign in to comment.