|
|
@ -255,8 +255,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
// Scale so that canvas units are the same as PDF user space units
|
|
|
|
// Scale so that canvas units are the same as PDF user space units
|
|
|
|
this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height); |
|
|
|
this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height); |
|
|
|
this.textDivs = []; |
|
|
|
|
|
|
|
this.textLayerQueue = []; |
|
|
|
if (this.textLayer) |
|
|
|
|
|
|
|
this.textLayer.beginLayout(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR, |
|
|
|
executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR, |
|
|
@ -320,27 +321,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
endDrawing: function canvasGraphicsEndDrawing() { |
|
|
|
endDrawing: function canvasGraphicsEndDrawing() { |
|
|
|
this.ctx.restore(); |
|
|
|
this.ctx.restore(); |
|
|
|
|
|
|
|
|
|
|
|
var textLayer = this.textLayer; |
|
|
|
if (this.textLayer) |
|
|
|
if (!textLayer) |
|
|
|
this.textLayer.endLayout(); |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
var textDivs = this.textDivs; |
|
|
|
|
|
|
|
this.textLayerTimer = setInterval(function renderTextLayer() { |
|
|
|
|
|
|
|
if (textDivs.length === 0) { |
|
|
|
|
|
|
|
clearInterval(self.textLayerTimer); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var textDiv = textDivs.shift(); |
|
|
|
|
|
|
|
if (textDiv.dataset.textLength > 1) { // avoid div by zero
|
|
|
|
|
|
|
|
textLayer.appendChild(textDiv); |
|
|
|
|
|
|
|
// Adjust div width (via letterSpacing) to match canvas text
|
|
|
|
|
|
|
|
// Due to the .offsetWidth calls, this is slow
|
|
|
|
|
|
|
|
textDiv.style.letterSpacing = |
|
|
|
|
|
|
|
((textDiv.dataset.canvasWidth - textDiv.offsetWidth) / |
|
|
|
|
|
|
|
(textDiv.dataset.textLength - 1)) + 'px'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, 0); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// Graphics state
|
|
|
|
// Graphics state
|
|
|
@ -630,24 +612,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
return geometry; |
|
|
|
return geometry; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
pushTextDivs: function canvasGraphicsPushTextDivs(text) { |
|
|
|
|
|
|
|
var div = document.createElement('div'); |
|
|
|
|
|
|
|
var fontSize = this.current.fontSize; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// vScale and hScale already contain the scaling to pixel units
|
|
|
|
|
|
|
|
// as mozCurrentTransform reflects ctx.scale() changes
|
|
|
|
|
|
|
|
// (see beginDrawing())
|
|
|
|
|
|
|
|
var fontHeight = fontSize * text.geom.vScale; |
|
|
|
|
|
|
|
div.dataset.canvasWidth = text.canvasWidth * text.geom.hScale; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
div.style.fontSize = fontHeight + 'px'; |
|
|
|
|
|
|
|
div.style.fontFamily = this.current.font.loadedName || 'sans-serif'; |
|
|
|
|
|
|
|
div.style.left = text.geom.x + 'px'; |
|
|
|
|
|
|
|
div.style.top = (text.geom.y - fontHeight) + 'px'; |
|
|
|
|
|
|
|
div.innerHTML = text.str; |
|
|
|
|
|
|
|
div.dataset.textLength = text.length; |
|
|
|
|
|
|
|
this.textDivs.push(div); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
showText: function canvasGraphicsShowText(str, skipTextSelection) { |
|
|
|
showText: function canvasGraphicsShowText(str, skipTextSelection) { |
|
|
|
var ctx = this.ctx; |
|
|
|
var ctx = this.ctx; |
|
|
|
var current = this.current; |
|
|
|
var current = this.current; |
|
|
@ -753,7 +717,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (textSelection) |
|
|
|
if (textSelection) |
|
|
|
this.pushTextDivs(text); |
|
|
|
this.textLayer.appendText(text, font.loadedName, fontSize); |
|
|
|
|
|
|
|
|
|
|
|
return text; |
|
|
|
return text; |
|
|
|
}, |
|
|
|
}, |
|
|
@ -819,7 +783,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (textSelection) |
|
|
|
if (textSelection) |
|
|
|
this.pushTextDivs(text); |
|
|
|
this.textLayer.appendText(text, font.loadedName, fontSize); |
|
|
|
}, |
|
|
|
}, |
|
|
|
nextLineShowText: function canvasGraphicsNextLineShowText(text) { |
|
|
|
nextLineShowText: function canvasGraphicsNextLineShowText(text) { |
|
|
|
this.nextLine(); |
|
|
|
this.nextLine(); |
|
|
|