@@ -158,37 +158,6 @@ class CanvasConstructor {
158158 return this ;
159159 }
160160
161- /**
162- * Add a circle or semi circle.
163- * @param {number } x The position x in the center of the circle.
164- * @param {number } y The position y in the center of the ircle.
165- * @param {number } radius The radius for the clip.
166- * @returns {CanvasConstructor }
167- * @chainable
168- */
169- addCircle ( x , y , radius ) {
170- this . context . beginPath ( ) ;
171- this . context . arc ( x , y , radius , 0 , Math . PI * 2 , false ) ;
172- this . context . closePath ( ) ;
173- this . context . fill ( ) ;
174- return this ;
175- }
176-
177- /**
178- * Add a rectangle.
179- * @param {number } x The position x to start drawing the element.
180- * @param {number } y The position y to start drawing the element.
181- * @param {number } width The width of the element.
182- * @param {number } height The heigth of the element.
183- * @returns {CanvasConstructor }
184- * @chainable
185- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillRect
186- */
187- addRect ( x , y , width , height ) {
188- this . context . fillRect ( x , y , width , height ) ;
189- return this ;
190- }
191-
192161 /**
193162 * Add a text.
194163 * @param {string } text The text to write.
@@ -459,7 +428,19 @@ class CanvasConstructor {
459428 }
460429
461430 /**
462- * Create a round clip.
431+ * Add a circle or semi circle.
432+ * @param {number } x The position x in the center of the circle.
433+ * @param {number } y The position y in the center of the ircle.
434+ * @param {number } radius The radius for the clip.
435+ * @returns {CanvasConstructor }
436+ * @chainable
437+ */
438+ addCircle ( x , y , radius ) {
439+ return this . createRoundPath ( x , y , radius ) . fill ( ) ;
440+ }
441+
442+ /**
443+ * Create a round path.
463444 * @param {number } x The position x in the center of the clip's circle.
464445 * @param {number } y The position y in the center of the clip's circle.
465446 * @param {number } radius The radius for the clip.
@@ -468,16 +449,29 @@ class CanvasConstructor {
468449 * @returns {CanvasConstructor }
469450 * @chainable
470451 */
471- createRoundClip ( x , y , radius , start = 0 , angle = Math . PI * 2 ) {
452+ createRoundPath ( x , y , radius , start = 0 , angle = Math . PI * 2 ) {
472453 this . context . save ( ) ;
473454 this . context . beginPath ( ) ;
474455 this . context . arc ( x , y , radius , start , angle , false ) ;
475- this . context . clip ( ) ;
476456 return this ;
477457 }
478458
479459 /**
480460 * Create a round clip.
461+ * @param {number } x The position x in the center of the clip's circle.
462+ * @param {number } y The position y in the center of the clip's circle.
463+ * @param {number } radius The radius for the clip.
464+ * @param {number } [start=0] The degree in radians to start drawing the circle.
465+ * @param {number } [angle=Math.PI * 2] The degree in radians to finish drawing the circle, defaults to a full circle.
466+ * @returns {CanvasConstructor }
467+ * @chainable
468+ */
469+ createRoundClip ( x , y , radius , start = 0 , angle = Math . PI * 2 ) {
470+ return this . createRoundPath ( x , y , radius , start , angle ) . clip ( ) ;
471+ }
472+
473+ /**
474+ * Create a round path.
481475 * @param {number } x The position x to start drawing clip.
482476 * @param {number } y The position y to start drawing clip.
483477 * @param {number } width The width of clip.
@@ -486,7 +480,7 @@ class CanvasConstructor {
486480 * @returns {CanvasConstructor }
487481 * @chainable
488482 */
489- createBeveledClip ( x , y , width , height , radius ) {
483+ createBeveledPath ( x , y , width , height , radius ) {
490484 if ( width > 0 && height > 0 ) {
491485 radius = Math . min ( radius , width / 2 , height / 2 ) ;
492486 this . context . beginPath ( ) ;
@@ -505,6 +499,35 @@ class CanvasConstructor {
505499 return this ;
506500 }
507501
502+ /**
503+ * Create a round clip.
504+ * @param {number } x The position x to start drawing clip.
505+ * @param {number } y The position y to start drawing clip.
506+ * @param {number } width The width of clip.
507+ * @param {number } height The heigth of clip.
508+ * @param {number } radius The radius for clip's rounded borders.
509+ * @returns {CanvasConstructor }
510+ * @chainable
511+ */
512+ createBeveledClip ( x , y , width , height , radius ) {
513+ return this . createBeveledPath ( x , y , width , height , radius ) . clip ( ) ;
514+ }
515+
516+ /**
517+ * Add a rectangle.
518+ * @param {number } x The position x to start drawing the element.
519+ * @param {number } y The position y to start drawing the element.
520+ * @param {number } width The width of the element.
521+ * @param {number } height The heigth of the element.
522+ * @returns {CanvasConstructor }
523+ * @chainable
524+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillRect
525+ */
526+ addRect ( x , y , width , height ) {
527+ this . context . fillRect ( x , y , width , height ) ;
528+ return this ;
529+ }
530+
508531 /**
509532 * Set a color for the canvas' context.
510533 * @param {string } color A canvas' color resolvable.
@@ -992,7 +1015,11 @@ class CanvasConstructor {
9921015 * @returns {CanvasConstructor }
9931016 */
9941017 static registerFont ( path , family ) {
995- Canvas . registerFont ( path , { family } ) ;
1018+ if ( family && typeof family === 'object' && Array . isArray ( family ) === false && 'family' in family )
1019+ Canvas . registerFont ( path , family ) ;
1020+ else
1021+ Canvas . registerFont ( path , { family } ) ;
1022+
9961023 return this ;
9971024 }
9981025
0 commit comments