1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 07:38:07 +02:00

Merge pull request #6551 from yurydelendik/subaa

[api-minor] Enables subpixel anti-aliasing for most of the content.
This commit is contained in:
Yury Delendik 2015-11-17 19:45:32 -06:00
commit 194994a289
7 changed files with 111 additions and 55 deletions

View file

@ -164,8 +164,7 @@ var PDFPageView = (function PDFPageViewClosure() {
var isScalingRestricted = false;
if (this.canvas && PDFJS.maxCanvasPixels > 0) {
var ctx = this.canvas.getContext('2d');
var outputScale = getOutputScale(ctx);
var outputScale = this.outputScale;
var pixelsInViewport = this.viewport.width * this.viewport.height;
var maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport);
if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) *
@ -309,6 +308,7 @@ var PDFPageView = (function PDFPageViewClosure() {
var canvas = document.createElement('canvas');
canvas.id = 'page' + this.id;
canvas.setAttribute('hidden', 'hidden');
canvasWrapper.appendChild(canvas);
if (this.annotationLayer && this.annotationLayer.div) {
// annotationLayer needs to stay on top
@ -316,10 +316,15 @@ var PDFPageView = (function PDFPageViewClosure() {
} else {
div.appendChild(canvasWrapper);
}
var isCanvasHidden = true;
this.canvas = canvas;
var ctx = canvas.getContext('2d');
//#if MOZCENTRAL || FIREFOX || GENERIC
canvas.mozOpaque = true;
//#endif
var ctx = canvas.getContext('2d', {alpha: false});
var outputScale = getOutputScale(ctx);
this.outputScale = outputScale;
if (PDFJS.useOnlyCssZoom) {
var actualSizeViewport = viewport.clone({scale: CSS_UNITS});
@ -372,14 +377,6 @@ var PDFPageView = (function PDFPageViewClosure() {
}
this.textLayer = textLayer;
if (outputScale.scaled) {
//#if !(MOZCENTRAL || FIREFOX)
// Used by the mozCurrentTransform polyfill in src/display/canvas.js.
ctx._transformMatrix = [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
//#endif
ctx.scale(outputScale.sx, outputScale.sy);
}
var resolveRenderPromise, rejectRenderPromise;
var promise = new Promise(function (resolve, reject) {
resolveRenderPromise = resolve;
@ -459,12 +456,19 @@ var PDFPageView = (function PDFPageViewClosure() {
};
return;
}
if (isCanvasHidden) {
self.canvas.removeAttribute('hidden');
isCanvasHidden = false;
}
cont();
};
}
var transform = !outputScale.scaled ? null :
[outputScale.sx, 0, 0, outputScale.sy, 0, 0];
var renderContext = {
canvasContext: ctx,
transform: transform,
viewport: this.viewport,
// intent: 'default', // === 'display'
};

View file

@ -44,7 +44,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
// Since this is a temporary canvas, we need to fill the canvas with a white
// background ourselves. |_getPageDrawContext| uses CSS rules for this.
var ctx = tempCanvas.getContext('2d');
//#if MOZCENTRAL || FIREFOX || GENERIC
tempCanvas.mozOpaque = true;
//#endif
var ctx = tempCanvas.getContext('2d', {alpha: false});
ctx.save();
ctx.fillStyle = 'rgb(255, 255, 255)';
ctx.fillRect(0, 0, width, height);
@ -184,7 +187,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
var canvas = document.createElement('canvas');
this.canvas = canvas;
var ctx = canvas.getContext('2d');
//#if MOZCENTRAL || FIREFOX || GENERIC
canvas.mozOpaque = true;
//#endif
var ctx = canvas.getContext('2d', {alpha: false});
var outputScale = getOutputScale(ctx);
canvas.width = (this.canvasWidth * outputScale.sx) | 0;

View file

@ -73,7 +73,10 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
var textDivs = this.textDivs;
var textDivsLength = textDivs.length;
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
//#if MOZCENTRAL || FIREFOX || GENERIC
canvas.mozOpaque = true;
//#endif
var ctx = canvas.getContext('2d', {alpha: false});
// No point in rendering many divs as it would make the browser
// unusable even after the divs are rendered.