From 0f6291c7b9361fc8c9b6eb2223034b17b78f3df2 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 18 Dec 2011 12:53:30 -0600 Subject: [PATCH 1/7] Move text layer UI to viewer.js; fixes adding div with single char; replaces innerHTML to textContent --- src/canvas.js | 50 +++++++------------------------------------------- web/viewer.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/canvas.js b/src/canvas.js index cd49c88b1..75165855c 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -255,8 +255,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } // Scale so that canvas units are the same as PDF user space units this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height); - this.textDivs = []; - this.textLayerQueue = []; + + if (this.textLayer) + this.textLayer.beginLayout(); }, executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR, @@ -320,27 +321,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { endDrawing: function canvasGraphicsEndDrawing() { this.ctx.restore(); - var textLayer = this.textLayer; - if (!textLayer) - 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); + if (this.textLayer) + this.textLayer.endLayout(); }, // Graphics state @@ -630,24 +612,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { 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) { var ctx = this.ctx; var current = this.current; @@ -753,7 +717,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } if (textSelection) - this.pushTextDivs(text); + this.textLayer.appendText(text, font.loadedName, fontSize); return text; }, @@ -819,7 +783,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } if (textSelection) - this.pushTextDivs(text); + this.textLayer.appendText(text, font.loadedName, fontSize); }, nextLineShowText: function canvasGraphicsNextLineShowText(text) { this.nextLine(); diff --git a/web/viewer.js b/web/viewer.js index daf0174ab..afaf03e04 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -595,7 +595,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, this.updateStats(); if (this.onAfterDraw) this.onAfterDraw(); - }).bind(this), textLayer + }).bind(this), new TextLayerBuilder(textLayer) ); setupLinks(this.content, this.scale); @@ -726,6 +726,53 @@ var DocumentOutlineView = function documentOutlineView(outline) { } }; +var TextLayerBuilder = function textLayerBuilder(textLayerDiv) { + this.textLayerDiv = textLayerDiv; + + this.beginLayout = function textLayerBuilderBeginLayout() { + this.textDivs = []; + this.textLayerQueue = []; + }; + + this.endLayout = function textLayerBuilderEndLayout() { + var self = this; + var textDivs = this.textDivs; + var textLayerDiv = this.textLayerDiv; + 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 + textLayerDiv.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); + }; + + this.appendText = function textLayerBuilderAppendText(text, + fontName, fontSize) { + var textDiv = document.createElement('div'); + + // vScale and hScale already contain the scaling to pixel units + var fontHeight = fontSize * text.geom.vScale; + textDiv.dataset.canvasWidth = text.canvasWidth * text.geom.hScale; + + textDiv.style.fontSize = fontHeight + 'px'; + textDiv.style.fontFamily = fontName || 'sans-serif'; + textDiv.style.left = text.geom.x + 'px'; + textDiv.style.top = (text.geom.y - fontHeight) + 'px'; + textDiv.textContent = text.str; + textDiv.dataset.textLength = text.length; + this.textDivs.push(textDiv); + }; +}; + window.addEventListener('load', function webViewerLoad(evt) { var params = document.location.search.substring(1).split('&'); for (var i = 0; i < params.length; i++) { From a52aacab5a8925350e3208a575080f243ff48ccf Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 18 Dec 2011 16:15:53 -0600 Subject: [PATCH 2/7] Fix the text layer testing --- test/driver.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/driver.js b/test/driver.js index 64fceee90..85d25658a 100644 --- a/test/driver.js +++ b/test/driver.js @@ -165,9 +165,14 @@ function nextPage(task, loadError) { canvas.height = pageHeight * pdfToCssUnitsCoef; clear(ctx); - // using non-attached to the document div to test + // using the text layer builder that does nothing to test // text layer creation operations - var textLayer = document.createElement('div'); + var textLayerBuilder = { + beginLayout: function nullTextLayerBuilderBeginLayout() {}, + endLayout: function nullTextLayerBuilderEndLayout() {}, + appendText: function nullTextLayerBuilderAppendText(text, fontName, + fontSize) {} + }; page.startRendering( ctx, @@ -177,7 +182,7 @@ function nextPage(task, loadError) { failureMessage = 'render : ' + error.message; snapshotCurrentPage(task, failureMessage); }, - textLayer + textLayerBuilder ); } catch (e) { failure = 'page setup : ' + e.toString(); From 440a47e5934d85b945ebc0da78a7ef7d59325136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=A4rcker?= Date: Tue, 27 Dec 2011 11:49:11 +0100 Subject: [PATCH 3/7] fixed viewer.css to support Opera's linear gradients and transitions --- web/viewer.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/viewer.css b/web/viewer.css index 0b64d9d86..072b2c033 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -15,6 +15,7 @@ body { /* === Toolbar === */ #controls { background-color: #eee; + background: -o-linear-gradient(bottom,#eee 0%,#fff 100%); background: -moz-linear-gradient(center bottom, #eee 0%, #fff 100%); background: -webkit-gradient(linear, left bottom, left top, color-stop(0.0, #ddd), color-stop(1.0, #fff)); border-bottom: 1px solid #666; @@ -82,6 +83,7 @@ span#info { bottom: 18px; left: -290px; transition: left 0.25s ease-in-out 1s; + -o-transition: left 0.25s ease-in-out 1s; -moz-transition: left 0.25s ease-in-out 1s; -webkit-transition: left 0.25s ease-in-out 1s; z-index: 1; @@ -90,6 +92,7 @@ span#info { #sidebar:hover { left: 0px; transition: left 0.25s ease-in-out 0s; + -o-transition: left 0.25s ease-in-out 0s; -moz-transition: left 0.25s ease-in-out 0s; -webkit-transition: left 0.25s ease-in-out 0s; } From cbf4c0393f4296cf24b1898b7f795ee8033f5b11 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 30 Dec 2011 19:32:35 -0600 Subject: [PATCH 4/7] Replace nbsp entity with character code --- src/canvas.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/canvas.js b/src/canvas.js index 0f7abdddf..a1c4fb40c 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -711,7 +711,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { width += charWidth; - text.str += glyph.unicode === ' ' ? ' ' : glyph.unicode; + text.str += glyph.unicode === ' ' ? '\u00A0' : glyph.unicode; text.length++; text.canvasWidth += charWidth; } @@ -763,7 +763,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { if (e < 0 && text.geom.spaceWidth > 0) { // avoid div by zero var numFakeSpaces = Math.round(-e / text.geom.spaceWidth); if (numFakeSpaces > 0) { - text.str += ' '; + text.str += '\u00A0'; text.length++; } } @@ -773,7 +773,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { if (textSelection) { if (shownText.str === ' ') { - text.str += ' '; + text.str += '\u00A0'; } else { text.str += shownText.str; } From 77e900da111fa7a8cbce90c21d219cc9042e0b02 Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Tue, 3 Jan 2012 19:11:13 +0100 Subject: [PATCH 5/7] Add #findTableCode to CCITTFaxStream's prototype, fixing issue #1015 --- src/stream.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/stream.js b/src/stream.js index d996f5c91..5397830e2 100644 --- a/src/stream.js +++ b/src/stream.js @@ -1856,8 +1856,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { // values. The first array element indicates whether a valid code is being // returned. The second array element is the actual code. The third array // element indicates whether EOF was reached. - var findTableCode = function ccittFaxStreamFindTableCode(start, end, table, - limit) { + CCITTFaxStream.prototype.findTableCode = + function ccittFaxStreamFindTableCode(start, end, table, limit) { + var limitValue = limit || 0; for (var i = start; i <= end; ++i) { @@ -1890,7 +1891,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { return p[1]; } } else { - var result = findTableCode(1, 7, twoDimTable); + var result = this.findTableCode(1, 7, twoDimTable); if (result[0] && result[2]) return result[1]; } @@ -1919,11 +1920,11 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { return p[1]; } } else { - var result = findTableCode(1, 9, whiteTable2); + var result = this.findTableCode.call(1, 9, whiteTable2); if (result[0]) return result[1]; - result = findTableCode(11, 12, whiteTable1); + result = this.findTableCode(11, 12, whiteTable1); if (result[0]) return result[1]; } @@ -1952,15 +1953,15 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { return p[1]; } } else { - var result = findTableCode(2, 6, blackTable3); + var result = this.findTableCode(2, 6, blackTable3); if (result[0]) return result[1]; - result = findTableCode(7, 12, blackTable2, 64); + result = this.findTableCode(7, 12, blackTable2, 64); if (result[0]) return result[1]; - result = findTableCode(10, 13, blackTable1); + result = this.findTableCode(10, 13, blackTable1); if (result[0]) return result[1]; } From 7fd0dbbc172a127398ae2867d13f1bf890f1c00a Mon Sep 17 00:00:00 2001 From: Saebekassebil Date: Tue, 3 Jan 2012 19:38:45 +0100 Subject: [PATCH 6/7] Typdoh --- src/stream.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/stream.js b/src/stream.js index 5397830e2..8d3f0f5bb 100644 --- a/src/stream.js +++ b/src/stream.js @@ -1860,7 +1860,6 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { function ccittFaxStreamFindTableCode(start, end, table, limit) { var limitValue = limit || 0; - for (var i = start; i <= end; ++i) { var code = this.lookBits(i); if (code == EOF) @@ -1920,7 +1919,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { return p[1]; } } else { - var result = this.findTableCode.call(1, 9, whiteTable2); + var result = this.findTableCode(1, 9, whiteTable2); if (result[0]) return result[1]; From 8635a694a23ab621f669152c8ba672342e1cbddb Mon Sep 17 00:00:00 2001 From: Artur Adib Date: Wed, 4 Jan 2012 14:49:37 -0500 Subject: [PATCH 7/7] Adding test PDF --- test/pdfs/issue1015.pdf.link | 1 + test/test_manifest.json | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 test/pdfs/issue1015.pdf.link diff --git a/test/pdfs/issue1015.pdf.link b/test/pdfs/issue1015.pdf.link new file mode 100644 index 000000000..0878ab443 --- /dev/null +++ b/test/pdfs/issue1015.pdf.link @@ -0,0 +1 @@ +http://faculty.washington.edu/fidelr/RayaPubs/TheCaseStudyMethod.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index dbb83604b..684f7aa2d 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -381,5 +381,12 @@ "md5": "7e6027a02ff78577f74dccdf84e37189", "rounds": 1, "type": "eq" + }, + { "id": "issue1015", + "file": "pdfs/issue1015.pdf", + "md5": "b61503d1b445742b665212866afb60e2", + "rounds": 1, + "link": true, + "type": "eq" } ]