Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't scale single-char text divs. #5221

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions web/text_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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;
}
}
},

Expand Down