@@ -85,7 +85,10 @@ var AwesomeQR = /** @class */ (function () {
85
85
}
86
86
} ) ;
87
87
}
88
- if ( _options . dotScale ) {
88
+ if ( _options . dotScale !== null && _options . dotScale !== undefined ) {
89
+ if ( _options . dotScale <= 0 || _options . dotScale > 1 ) {
90
+ throw new Error ( "dotScale should be in range (0, 1]." ) ;
91
+ }
89
92
_options . components . data . scale = _options . dotScale ;
90
93
_options . components . timing . scale = _options . dotScale ;
91
94
_options . components . alignment . scale = _options . dotScale ;
@@ -170,8 +173,6 @@ var AwesomeQR = /** @class */ (function () {
170
173
AwesomeQR . _drawAlignProtector = function ( canvasContext , centerX , centerY , nSize ) {
171
174
canvasContext . clearRect ( ( centerX - 2 ) * nSize , ( centerY - 2 ) * nSize , 5 * nSize , 5 * nSize ) ;
172
175
canvasContext . fillRect ( ( centerX - 2 ) * nSize , ( centerY - 2 ) * nSize , 5 * nSize , 5 * nSize ) ;
173
- // canvasContext.clearRect((centerX - 2) * nWidth, (centerY - 2) * nHeight, 5 * nWidth, 5 * nHeight);
174
- // canvasContext.fillRect((centerX - 2) * nWidth, (centerY - 2) * nHeight, 5 * nWidth, 5 * nHeight);
175
176
} ;
176
177
AwesomeQR . _drawAlign = function ( canvasContext , centerX , centerY , nSize , xyOffset , dotScale , colorDark , hasProtector ) {
177
178
if ( xyOffset === void 0 ) { xyOffset = 0 ; }
@@ -199,7 +200,7 @@ var AwesomeQR = /** @class */ (function () {
199
200
AwesomeQR . prototype . _draw = function ( ) {
200
201
var _a , _b , _c , _d , _e , _f , _g , _h , _j , _k , _l , _m , _o , _p , _q , _r , _s , _t , _u ;
201
202
return __awaiter ( this , void 0 , void 0 , function ( ) {
202
- var nCount , rawSize , rawMargin , margin , rawViewportSize , whiteMargin , backgroundDimming , nSize , viewportSize , size , mainCanvas , mainCanvasContext , dotScale , backgroundCanvas , backgroundCanvasContext , parsedGIFBackground , gifFrames , gif , r , g , b , count , i , c , backgroundImage , avgRGB , alignmentPatternCenters , dataScale , dataXyOffset , row , col , bIsDark , isBlkPosCtr , isTiming , isProtected , i , nLeft , nTop , inAgnRange , cornerAlignmentCenter , protectorStyle , i , j , agnX , agnY , timingScale , timingXyOffset , i , cornerAlignmentScale , cornerAlignmentXyOffset , alignmentScale , alignmentXyOffset , i , j , agnX , agnY , logoImage , logoScale , logoMargin , logoCornerRadius , logoSize , x , y , gifOutput_1 , backgroundCanvas_1 , backgroundCanvasContext_1 , patchCanvas_1 , patchCanvasContext_1 , patchData_1 , u8array , binary , outCanvas , outCanvasContext ;
203
+ var nCount , rawSize , rawMargin , margin , rawViewportSize , whiteMargin , backgroundDimming , nSize , viewportSize , size , mainCanvas , mainCanvasContext , backgroundCanvas , backgroundCanvasContext , parsedGIFBackground , gifFrames , gif , r , g , b , count , i , c , backgroundImage , avgRGB , alignmentPatternCenters , dataScale , dataXyOffset , row , col , bIsDark , isBlkPosCtr , isTiming , isProtected , i , nLeft , nTop , inAgnRange , cornerAlignmentCenter , protectorStyle , i , j , agnX , agnY , timingScale , timingXyOffset , i , cornerAlignmentScale , cornerAlignmentXyOffset , alignmentScale , alignmentXyOffset , i , j , agnX , agnY , logoImage , logoScale , logoMargin , logoCornerRadius , logoSize , x , y , oldGlobalCompositeOperation , gifOutput_1 , backgroundCanvas_1 , backgroundCanvasContext_1 , patchCanvas_1 , patchCanvasContext_1 , patchData_1 , u8array , binary , outCanvas , outCanvasContext ;
203
204
return __generator ( this , function ( _v ) {
204
205
switch ( _v . label ) {
205
206
case 0 :
@@ -218,12 +219,8 @@ var AwesomeQR = /** @class */ (function () {
218
219
size = viewportSize + 2 * margin ;
219
220
mainCanvas = canvas_1 . createCanvas ( size , size ) ;
220
221
mainCanvasContext = mainCanvas . getContext ( "2d" ) ;
221
- dotScale = this . options . dotScale ;
222
222
this . _clear ( ) ;
223
- if ( dotScale <= 0 || dotScale > 1 ) {
224
- throw new Error ( "Scale should be in range (0, 1]." ) ;
225
- }
226
- // Leave room for margin
223
+ // Translate to make the top and left margins off the viewport
227
224
mainCanvasContext . save ( ) ;
228
225
mainCanvasContext . translate ( margin , margin ) ;
229
226
backgroundCanvas = canvas_1 . createCanvas ( size , size ) ;
@@ -389,7 +386,6 @@ var AwesomeQR = /** @class */ (function () {
389
386
continue ;
390
387
}
391
388
else {
392
- // mainCanvasContext.fillStyle = "rgba(0, 0, 0, .2)";
393
389
AwesomeQR . _drawAlign ( mainCanvasContext , agnX , agnY , nSize , alignmentXyOffset , alignmentScale , this . options . colorDark , ( ( _u = ( _t = this . options . components ) === null || _t === void 0 ? void 0 : _t . alignment ) === null || _u === void 0 ? void 0 : _u . protectors ) || false ) ;
394
390
}
395
391
}
@@ -418,21 +414,31 @@ var AwesomeQR = /** @class */ (function () {
418
414
if ( logoCornerRadius < 0 ) {
419
415
logoCornerRadius = 0 ;
420
416
}
421
- mainCanvasContext . restore ( ) ;
422
417
logoSize = viewportSize * logoScale ;
423
418
x = 0.5 * ( size - logoSize ) ;
424
419
y = x ;
420
+ // Restore the canvas
421
+ // After restoring, the top and left margins should be taken into account
422
+ mainCanvasContext . restore ( ) ;
423
+ // Clean the area that the logo covers (including margins)
425
424
mainCanvasContext . fillStyle = "#FFFFFF" ;
426
425
mainCanvasContext . save ( ) ;
427
- AwesomeQR . _prepareRoundedCornerClip ( mainCanvasContext , x - logoMargin , y - logoMargin , logoSize + 2 * logoMargin , logoSize + 2 * logoMargin , logoCornerRadius ) ;
426
+ AwesomeQR . _prepareRoundedCornerClip ( mainCanvasContext , x - logoMargin , y - logoMargin , logoSize + 2 * logoMargin , logoSize + 2 * logoMargin , logoCornerRadius + logoMargin ) ;
428
427
mainCanvasContext . clip ( ) ;
428
+ oldGlobalCompositeOperation = mainCanvasContext . globalCompositeOperation ;
429
+ mainCanvasContext . globalCompositeOperation = "destination-out" ;
429
430
mainCanvasContext . fill ( ) ;
431
+ mainCanvasContext . globalCompositeOperation = oldGlobalCompositeOperation ;
430
432
mainCanvasContext . restore ( ) ;
433
+ // Draw logo image
431
434
mainCanvasContext . save ( ) ;
432
435
AwesomeQR . _prepareRoundedCornerClip ( mainCanvasContext , x , y , logoSize , logoSize , logoCornerRadius ) ;
433
436
mainCanvasContext . clip ( ) ;
434
437
mainCanvasContext . drawImage ( logoImage , x , y , logoSize , logoSize ) ;
435
438
mainCanvasContext . restore ( ) ;
439
+ // Re-translate the canvas to translate the top and left margins into invisible area
440
+ mainCanvasContext . save ( ) ;
441
+ mainCanvasContext . translate ( margin , margin ) ;
436
442
_v . label = 6 ;
437
443
case 6 :
438
444
if ( ! ! parsedGIFBackground ) {
@@ -529,7 +535,7 @@ var AwesomeQR = /** @class */ (function () {
529
535
backgroundDimming : "rgba(0,0,0,0)" ,
530
536
logoImage : undefined ,
531
537
logoScale : 0.2 ,
532
- logoMargin : 6 ,
538
+ logoMargin : 4 ,
533
539
logoCornerRadius : 8 ,
534
540
whiteMargin : true ,
535
541
components : AwesomeQR . defaultComponentOptions ,
0 commit comments