Fix the driver.js file to handle new TextLayer infrastructure

This commit is contained in:
Julian Viereck 2012-09-16 07:46:29 -07:00
parent 36d358fff8
commit e7894ca07d

View File

@ -159,6 +159,7 @@ NullTextLayerBuilder.prototype = {
function SimpleTextLayerBuilder(ctx, viewport) { function SimpleTextLayerBuilder(ctx, viewport) {
this.ctx = ctx; this.ctx = ctx;
this.viewport = viewport; this.viewport = viewport;
this.textCounter = 0;
} }
SimpleTextLayerBuilder.prototype = { SimpleTextLayerBuilder.prototype = {
beginLayout: function SimpleTextLayerBuilder_BeginLayout() { beginLayout: function SimpleTextLayerBuilder_BeginLayout() {
@ -180,14 +181,18 @@ SimpleTextLayerBuilder.prototype = {
ctx.stroke(); ctx.stroke();
ctx.fill(); ctx.fill();
var textContent = bidi(text, -1); var textContent = this.textContent.text[this.textCounter];
ctx.font = fontHeight + 'px ' + fontName; ctx.font = fontHeight + 'px ' + fontName;
ctx.fillStyle = 'black'; ctx.fillStyle = 'black';
ctx.fillText(textContent, text.geom.x, text.geom.y); ctx.fillText(textContent, text.geom.x, text.geom.y);
this.textCounter ++;
},
setTextContent: function SimpleTextLayerBuilder_SetTextContent(textContent) {
this.textContent = textContent;
} }
}; };
function nextPage(task, loadError) { function nextPage(task, loadError) {
var failure = loadError || ''; var failure = loadError || '';
@ -245,6 +250,10 @@ function nextPage(task, loadError) {
drawContext = dummyCanvas.getContext('2d'); drawContext = dummyCanvas.getContext('2d');
// ... text builder will draw its content on the test canvas // ... text builder will draw its content on the test canvas
textLayerBuilder = new SimpleTextLayerBuilder(ctx, viewport); textLayerBuilder = new SimpleTextLayerBuilder(ctx, viewport);
page.getTextContent().then(function(textContent) {
textLayerBuilder.setTextContent(textContent);
});
} else { } else {
drawContext = ctx; drawContext = ctx;
textLayerBuilder = new NullTextLayerBuilder(); textLayerBuilder = new NullTextLayerBuilder();