From 12b799cd024f62861235d3b11a68ebf4020c0a52 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Sat, 23 Jun 2012 15:52:30 +0200 Subject: [PATCH 1/3] Use a canvas to measure the width of the text layer div instead of using the slow offsetWidth property --- web/viewer.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index d371c3242..05aec6075 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1498,6 +1498,9 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) { var renderInterval = 0; var resumeInterval = 500; // in ms + var canvas = document.createElement('canvas'); + var ctx = canvas.getContext('2d'); + // Render the text layer, one div at a time function renderTextLayer() { if (textDivs.length === 0) { @@ -1511,9 +1514,12 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) { if (textDiv.dataset.textLength > 1) { // avoid div by zero // Adjust div width to match canvas text - // Due to the .offsetWidth calls, this is slow - // This needs to come after appending to the DOM - var textScale = textDiv.dataset.canvasWidth / textDiv.offsetWidth; + + ctx.font = textDiv.style.fontSize + ' sans-serif'; + var width = ctx.measureText(textDiv.textContent).width; + + var textScale = textDiv.dataset.canvasWidth / width; + CustomStyle.setProp('transform' , textDiv, 'scale(' + textScale + ', 1)'); CustomStyle.setProp('transformOrigin' , textDiv, '0% 0%'); From e6b75f4a569de815074a45add212b4b23322c47a Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 17 Jul 2012 13:42:49 -0700 Subject: [PATCH 2/3] Also check abbreviation for colorspace in jpegs. --- src/stream.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stream.js b/src/stream.js index 5e4b3a47e..bd239dacc 100644 --- a/src/stream.js +++ b/src/stream.js @@ -852,7 +852,7 @@ var JpegStream = (function JpegStreamClosure() { */ JpegStream.prototype.isNativelySupported = function JpegStream_isNativelySupported(xref, res) { - var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res); + var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res); // when bug 674619 lands, let's check if browser can do // normal cmyk and then we won't need to decode in JS if (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') @@ -867,7 +867,7 @@ var JpegStream = (function JpegStreamClosure() { */ JpegStream.prototype.isNativelyDecodable = function JpegStream_isNativelyDecodable(xref, res) { - var cs = ColorSpace.parse(this.dict.get('ColorSpace'), xref, res); + var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res); var numComps = cs.numComps; if (numComps == 1 || numComps == 3) return true; From 8705d8851fe44551160d6cda4ed830b38c436b61 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Thu, 19 Jul 2012 10:58:07 -0700 Subject: [PATCH 3/3] Add reftest for undefined colorspace. --- test/pdfs/issue1419.pdf.link | 1 + test/test_manifest.json | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 test/pdfs/issue1419.pdf.link diff --git a/test/pdfs/issue1419.pdf.link b/test/pdfs/issue1419.pdf.link new file mode 100644 index 000000000..7fe9f28bc --- /dev/null +++ b/test/pdfs/issue1419.pdf.link @@ -0,0 +1 @@ +http://www.meal-a-day.asia/sites/default/files/Meal-a-Day%20Asia-Pacific%20Biennial%20Report%202012%20v1.01.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 4a0595348..ffcf10bed 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -604,6 +604,15 @@ "link": true, "type": "eq" }, + { "id": "issue1419.pdf", + "file": "pdfs/issue1419.pdf", + "md5": "b5b6c6405d7b48418bccf97277957664", + "rounds": 1, + "link": true, + "pageLimit": 1, + "skipPages": [1], + "type": "eq" + }, { "id": "issue1317", "file": "pdfs/issue1317.pdf", "md5": "6fb46275b30c48c8985617d4f86199e3",