Browse Source

simplify adding of textdivs to DOM as queue is no longer needed

Adil Allawi 14 years ago
parent
commit
b921486bce
  1. 38
      src/canvas.js

38
src/canvas.js

@ -257,9 +257,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height); this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height);
this.textDivs = []; this.textDivs = [];
this.textLayerQueue = []; this.textLayerQueue = [];
// Prevent textLayerQueue from being rendered while rendering a new page
if (this.textLayerTimer)
clearInterval(this.textLayerTimer);
}, },
executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR, executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR,
@ -328,12 +325,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
return; return;
var self = this; var self = this;
var textDivIndex = 0; var textDivs = this.textDivs;
var renderTextLayer = function canvasRenderTextLayer() { this.textLayerTimer = setInterval(function renderTextLayer() {
var finished = false; if (textDivs.length === 0) {
var textDivs = self.textDivs; clearInterval(self.textLayerTimer);
if (textDivIndex < textDivs.length) { return;
var textDiv = textDivs[textDivIndex++]; }
var textDiv = textDivs.shift();
if (textDiv.dataset.textLength > 1) { // avoid div by zero if (textDiv.dataset.textLength > 1) { // avoid div by zero
textLayer.appendChild(textDiv); textLayer.appendChild(textDiv);
// Adjust div width (via letterSpacing) to match canvas text // Adjust div width (via letterSpacing) to match canvas text
@ -342,27 +340,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
((textDiv.dataset.canvasWidth - textDiv.offsetWidth) / ((textDiv.dataset.canvasWidth - textDiv.offsetWidth) /
(textDiv.dataset.textLength - 1)) + 'px'; (textDiv.dataset.textLength - 1)) + 'px';
} }
} }, 0);
else
finished = true;
return finished;
}
var textLayerQueue = this.textLayerQueue;
textLayerQueue.push(renderTextLayer);
// Lazy textLayer rendering (to prevent UI hangs)
// Only render queue if activity has stopped, where "no activity" ==
// "no beginDrawing() calls in the last N ms"
this.textLayerTimer = setInterval(function renderTextLayerQueue() {
// Render most recent (==most relevant) layers first
for (var i = textLayerQueue.length - 1; i >= 0; i--) {
var finished = textLayerQueue[i].call();
if (finished)
textLayerQueue.splice(i, 1);
}
if (textLayerQueue.length == 0)
clearInterval(self.textLayerTimer);
}, 1);
}, },
// Graphics state // Graphics state

Loading…
Cancel
Save