Skip to content

Commit

Permalink
Fix: Scaling canvas context when the canvas re-scales (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Aug 29, 2017
1 parent 2318581 commit 1bfa954
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/annotations/doc/__tests__/docAnnotatorUtil-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ describe('lib/annotations/doc/docAnnotatorUtil', () => {

beforeEach(() => {
stubs.annotationLayer = document.createElement('canvas');
stubs.context = {
scale: sandbox.stub()
};
sandbox.stub(stubs.annotationLayer, 'getContext').returns(stubs.context);

stubs.pageEl = {
getBoundingClientRect: sandbox.stub().returns({
width,
Expand Down Expand Up @@ -252,6 +257,7 @@ describe('lib/annotations/doc/docAnnotatorUtil', () => {
expect(scaledCanvas.height).equals(stubs.canvasHeight * pxRatio);
expect(scaledCanvas.style.width).equals(`${width}px`);
expect(scaledCanvas.style.height).equals(`${stubs.canvasHeight}px`);
expect(stubs.annotationLayer.getContext).to.be.called;
});
});

Expand Down
3 changes: 3 additions & 0 deletions src/lib/annotations/doc/docAnnotatorUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ export function scaleCanvas(pageEl, annotationLayerEl) {
if (pxRatio !== 1) {
scaledCanvas.style.width = `${width}px`;
scaledCanvas.style.height = `${height}px`;

const context = annotationLayerEl.getContext('2d');
context.scale(pxRatio, pxRatio);
}

return scaledCanvas;
Expand Down

0 comments on commit 1bfa954

Please sign in to comment.