Skip to content

Commit

Permalink
Allow context to be refreshed after rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Jul 2, 2017
1 parent 0532d19 commit 9932116
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/postproc/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class CanvasRenderer extends Postprocessor{
this.slant = 0;
this.sourceFile = "";
this.tm = null;
this.word = "";
this.wordX = 0;
this.wordY = 0;
this.x = 0;
this.y = 0;
this.zoom = 1;
Expand Down Expand Up @@ -138,8 +135,11 @@ class CanvasRenderer extends Postprocessor{



renderPage(pageIndex, context){
this.context = context;
renderPage(pageIndex, context = null, clear = true){
if(null !== context)
this.context = context;
if(clear)
this.clearPage();

// Cap index to available page range
const max = this.pages.length - 1;
Expand All @@ -150,7 +150,7 @@ class CanvasRenderer extends Postprocessor{
this.page = this.pages[pageIndex];

const aspectRatio = this.pageHeight / this.pageWidth;
const {canvas} = context;
const {canvas} = this.context;
canvas.height = canvas.width * aspectRatio;

for(const [type, data] of this.page){
Expand All @@ -163,6 +163,12 @@ class CanvasRenderer extends Postprocessor{
}


clearPage(){
const {canvas} = this.context;
this.context.clearRect(0, 0, canvas.width, canvas.height);
}


drawArc(args){
const h0 = this.x * this.scale;
const v0 = this.y * this.scale;
Expand Down

0 comments on commit 9932116

Please sign in to comment.