[Pkg-javascript-commits] [pdf.js] 07/204: Don't scale single-char text divs.
David Prévot
taffit at moszumanska.debian.org
Sat Oct 25 18:50:24 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 cd61aad24fc88b24fbc2a253237f9a01f8019b6d
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date: Wed Aug 20 19:08:15 2014 -0700
Don't scale single-char text divs.
This change makes scrolling noticeably smoother on files with many
single-char text divs, such as the one in #1045. The trade-off is that
the visual appearance of text selection in such documents is slightly
worse, because more text divs overlap.
This change also uses `scaleX(N)` instead of `scale(N, 1)`. This might
be marginally more efficient in terms of JS string concatenation.
---
web/text_layer_builder.js | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js
index 666ebc9..bc27bb8 100644
--- a/web/text_layer_builder.js
+++ b/web/text_layer_builder.js
@@ -83,14 +83,21 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
var width = ctx.measureText(textDiv.textContent).width;
if (width > 0) {
textLayerFrag.appendChild(textDiv);
- // Dataset values come of type string.
- var textScale = textDiv.dataset.canvasWidth / width;
+ var transform;
+ if (textDiv.dataset.canvasWidth !== undefined) {
+ // Dataset values come of type string.
+ var textScale = textDiv.dataset.canvasWidth / width;
+ transform = 'scaleX(' + textScale + ')';
+ } else {
+ transform = '';
+ }
var rotation = textDiv.dataset.angle;
- var transform = 'scale(' + textScale + ', 1)';
if (rotation) {
transform = 'rotate(' + rotation + 'deg) ' + transform;
}
- CustomStyle.setProp('transform' , textDiv, transform);
+ if (transform) {
+ CustomStyle.setProp('transform' , textDiv, transform);
+ }
}
}
@@ -165,10 +172,15 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
if (angle !== 0) {
textDiv.dataset.angle = angle * (180 / Math.PI);
}
- if (style.vertical) {
- textDiv.dataset.canvasWidth = geom.height * this.viewport.scale;
- } else {
- textDiv.dataset.canvasWidth = geom.width * this.viewport.scale;
+ // We don't bother scaling single-char text divs, because it has very
+ // little effect on text highlighting. This makes scrolling on docs with
+ // lots of such divs a lot faster.
+ if (textDiv.textContent.length > 1) {
+ if (style.vertical) {
+ textDiv.dataset.canvasWidth = geom.height * this.viewport.scale;
+ } else {
+ textDiv.dataset.canvasWidth = geom.width * this.viewport.scale;
+ }
}
},
--
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