[Pkg-javascript-commits] [pdf.js] 59/141: Fixes text-selection example
David Prévot
taffit at moszumanska.debian.org
Sat Apr 19 22:40:30 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 9c84bfa416975a016e4309833ccdb78b2b0db490
Author: Yury Delendik <ydelendik at mozilla.com>
Date: Wed Apr 9 20:52:21 2014 -0500
Fixes text-selection example
---
examples/text-selection/js/minimal.js | 41 ++++++++++++++++-------------------
src/display/api.js | 2 --
2 files changed, 19 insertions(+), 24 deletions(-)
diff --git a/examples/text-selection/js/minimal.js b/examples/text-selection/js/minimal.js
index b25bf4f..2faf337 100644
--- a/examples/text-selection/js/minimal.js
+++ b/examples/text-selection/js/minimal.js
@@ -14,8 +14,13 @@
// you actually end up selecting.
window.onload = function () {
+ if (typeof PDFJS === 'undefined') {
+ alert('Built version of pdf.js is not found\nPlease run `node make generic`');
+ return;
+ }
+
var scale = 1.5; //Set this to whatever you want. This is basically the "zoom" factor for the PDF.
- PDFJS.workerSrc = '../../src/worker_loader.js';
+ PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
function loadPdf(pdfPath) {
var pdf = PDFJS.getDocument(pdfPath);
@@ -33,38 +38,30 @@ window.onload = function () {
// Set the canvas height and width to the height and width of the viewport
var canvas = $canvas.get(0);
var context = canvas.getContext("2d");
- canvas.height = viewport.height;
- canvas.width = viewport.width;
+
+ // The following few lines of code set up scaling on the context if we are on a HiDPI display
+ var outputScale = getOutputScale(context);
+ canvas.width = (Math.floor(viewport.width) * outputScale.sx) | 0;
+ canvas.height = (Math.floor(viewport.height) * outputScale.sy) | 0;
+ canvas.style.width = Math.floor(viewport.width) + 'px';
+ canvas.style.height = Math.floor(viewport.height) + 'px';
// Append the canvas to the pdf container div
var $pdfContainer = jQuery("#pdfContainer");
- $pdfContainer.css("height", canvas.height + "px").css("width", canvas.width + "px");
+ $pdfContainer.css("height", canvas.style.height)
+ .css("width", canvas.style.width);
$pdfContainer.append($canvas);
var canvasOffset = $canvas.offset();
var $textLayerDiv = jQuery("<div />")
.addClass("textLayer")
- .css("height", viewport.height + "px")
- .css("width", viewport.width + "px")
+ .css("height", canvas.style.height)
+ .css("width", canvas.style.width)
.offset({
top: canvasOffset.top,
left: canvasOffset.left
});
- // The following few lines of code set up scaling on the context if we are on a HiDPI display
- var outputScale = getOutputScale(context);
- if (outputScale.scaled) {
- var cssScale = 'scale(' + (1 / outputScale.sx) + ', ' +
- (1 / outputScale.sy) + ')';
- CustomStyle.setProp('transform', canvas, cssScale);
- CustomStyle.setProp('transformOrigin', canvas, '0% 0%');
-
- if ($textLayerDiv.get(0)) {
- CustomStyle.setProp('transform', $textLayerDiv.get(0), cssScale);
- CustomStyle.setProp('transformOrigin', $textLayerDiv.get(0), '0% 0%');
- }
- }
-
context._scaleX = outputScale.sx;
context._scaleY = outputScale.sy;
if (outputScale.scaled) {
@@ -76,14 +73,14 @@ window.onload = function () {
page.getTextContent().then(function (textContent) {
var textLayer = new TextLayerBuilder({
textLayerDiv: $textLayerDiv.get(0),
+ viewport: viewport,
pageIndex: 0
});
textLayer.setTextContent(textContent);
var renderContext = {
canvasContext: context,
- viewport: viewport,
- textLayer: textLayer
+ viewport: viewport
};
page.render(renderContext);
diff --git a/src/display/api.js b/src/display/api.js
index aff296f..807cce7 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -444,8 +444,6 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @param {Object} params A parameter object that supports:
* {
* canvasContext(required): A 2D context of a DOM Canvas object.,
- * textLayer(optional): An object that has beginLayout, endLayout, and
- * appendText functions.,
* imageLayer(optional): An object that has beginLayout, endLayout and
* appendImage functions.,
* continueCallback(optional): A function that will be called each time
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list