diff --git a/lib/QRCode.js b/lib/QRCode.js index 80f81ce3..b2f09cb6 100644 --- a/lib/QRCode.js +++ b/lib/QRCode.js @@ -80,34 +80,34 @@ export default class QRCode extends Component { var logoY = ((this.props.size/2)-(this.props.logoSize/2)); var logoSize = this.props.logoSize; - var pieces = []; - var nonPieces = []; - //Add the SVG element of each piece in the body of the QR Code - for (var y = 0; y < length; y++) { - for (var x = 0; x < length; x++) { - var module = modules[x][y]; - var px = (x * xsize + this.props.padding * xsize); - var py = (y * ysize + this.props.padding * ysize); + var makePieces = (params) => { + var invert = Boolean(params && params.invert); + var result = []; - //TODO: Add function to compute if pieces overlap with circular logos (more complex. Must see if tl or br is inside the radius from the centre of the circle (pythagoras theorem?)) - var overlapsWithLogo = ( + for (var y = 0; y < length; y++) { + for (var x = 0; x < length; x++) { + var module = Boolean(modules[x][y]); + var px = (x * xsize + this.props.padding * xsize); + var py = (y * ysize + this.props.padding * ysize); - px>logoX && px<(logoX+logoSize) && py>logoY && py<(logoY+logoSize) ||//Piece's top left is inside the logo area - (px+xsize)>logoX && (px+xsize)<(logoX+logoSize) && (py+ysize)>logoY && (py+ysize)<(logoY+logoSize)//Piece's bottom right is inside the logo area + //TODO: Add function to compute if pieces overlap with circular logos (more complex. Must see if tl or br is inside the radius from the centre of the circle (pythagoras theorem?)) + var overlapsWithLogo = ( - ); + px>logoX && px<(logoX+logoSize) && py>logoY && py<(logoY+logoSize) ||//Piece's top left is inside the logo area + (px+xsize)>logoX && (px+xsize)<(logoX+logoSize) && (py+ysize)>logoY && (py+ysize)<(logoY+logoSize)//Piece's bottom right is inside the logo area - if(!this.props.logo || (this.props.logo && !overlapsWithLogo)){ + ); - if (module) { - pieces.push(this.getPiece(x,y,modules)); - } - else{ - nonPieces.push(this.getPiece(x,y,modules)); + if(!this.props.logo || (this.props.logo && !overlapsWithLogo)){ + + if (module !== invert) { + result.push(this.getPiece(x,y,modules)); + } } } } + return result; } if(this.props.backgroundImage){ @@ -118,7 +118,7 @@ export default class QRCode extends Component { - {nonPieces} + {makePieces({invert: true})} @@ -132,7 +132,7 @@ export default class QRCode extends Component { - {pieces} + {makePieces()} @@ -151,7 +151,7 @@ export default class QRCode extends Component { - {pieces} + {makePieces()}