From b5f952a63a0b9d12aca626dde12b774d1736df48 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 9 Oct 2012 08:25:41 -0500 Subject: [PATCH] Fixes font debugger; text builder api refactoring --- src/canvas.js | 15 +++++++++------ test/driver.js | 7 +++---- web/viewer.js | 9 ++++----- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/canvas.js b/src/canvas.js index 9ccc7317e..982ffb8c3 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -646,7 +646,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ctx.transform.apply(ctx, fontMatrix); ctx.scale(textHScale, 1); }, - getTextGeometry: function CanvasGraphics_getTextGeometry() { + createTextGeometry: function CanvasGraphics_createTextGeometry() { var geometry = {}; var ctx = this.ctx; var font = this.current.font; @@ -660,6 +660,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { geometry.vScale = tr[1] - bl[1]; } geometry.spaceWidth = font.spaceWidth; + geometry.fontName = font.loadedName; + geometry.fontFamily = font.fallbackName; + geometry.fontSize = this.current.fontSize; return geometry; }, @@ -693,7 +696,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { if (textSelection) { this.save(); ctx.scale(1, -1); - geom = this.getTextGeometry(); + geom = this.createTextGeometry(); this.restore(); } for (var i = 0; i < glyphsLength; ++i) { @@ -734,7 +737,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { lineWidth /= scale; if (textSelection) - geom = this.getTextGeometry(); + geom = this.createTextGeometry(); if (fontSizeScale != 1.0) { ctx.scale(fontSizeScale, fontSizeScale); @@ -792,7 +795,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { if (textSelection) { geom.canvasWidth = canvasWidth; - this.textLayer.appendText(font.fallbackName, fontSize, geom); + this.textLayer.appendText(geom); } return canvasWidth; @@ -821,7 +824,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ctx.scale(textHScale, 1); } else this.applyTextTransforms(); - geom = this.getTextGeometry(); + geom = this.createTextGeometry(); ctx.restore(); } @@ -845,7 +848,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { if (textSelection) { geom.canvasWidth = canvasWidth; - this.textLayer.appendText(font.fallbackName, fontSize, geom); + this.textLayer.appendText(geom); } }, nextLineShowText: function CanvasGraphics_nextLineShowText(text) { diff --git a/test/driver.js b/test/driver.js index 0997c7485..df5494021 100644 --- a/test/driver.js +++ b/test/driver.js @@ -168,11 +168,10 @@ SimpleTextLayerBuilder.prototype = { endLayout: function SimpleTextLayerBuilder_EndLayout() { this.ctx.restore(); }, - appendText: function SimpleTextLayerBuilder_AppendText(fontName, fontSize, - geom) { + appendText: function SimpleTextLayerBuilder_AppendText(geom) { var ctx = this.ctx, viewport = this.viewport; // vScale and hScale already contain the scaling to pixel units - var fontHeight = fontSize * geom.vScale; + var fontHeight = geom.fontSize * geom.vScale; ctx.beginPath(); ctx.strokeStyle = 'red'; ctx.fillStyle = 'yellow'; @@ -182,7 +181,7 @@ SimpleTextLayerBuilder.prototype = { ctx.fill(); var textContent = this.textContent.bidiTexts[this.textCounter].str; - ctx.font = fontHeight + 'px ' + fontName; + ctx.font = fontHeight + 'px ' + geom.fontFamily; ctx.fillStyle = 'black'; ctx.fillText(textContent, geom.x, geom.y); diff --git a/web/viewer.js b/web/viewer.js index 30e55a451..e718efbaa 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -2303,17 +2303,16 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) { } }; - this.appendText = function textLayerBuilderAppendText(fontName, fontSize, - geom) { + this.appendText = function textLayerBuilderAppendText(geom) { var textDiv = document.createElement('div'); // vScale and hScale already contain the scaling to pixel units - var fontHeight = fontSize * geom.vScale; + var fontHeight = geom.fontSize * geom.vScale; textDiv.dataset.canvasWidth = geom.canvasWidth * geom.hScale; - textDiv.dataset.fontName = fontName; + textDiv.dataset.fontName = geom.fontName; textDiv.style.fontSize = fontHeight + 'px'; - textDiv.style.fontFamily = fontName; + textDiv.style.fontFamily = geom.fontFamily; textDiv.style.left = geom.x + 'px'; textDiv.style.top = (geom.y - fontHeight) + 'px';