diff --git a/src/canvas/graphic.ts b/src/canvas/graphic.ts index 838ec1ff5..6f2806fc2 100644 --- a/src/canvas/graphic.ts +++ b/src/canvas/graphic.ts @@ -1,7 +1,7 @@ import Displayable, { DEFAULT_COMMON_STYLE } from '../graphic/Displayable'; import PathProxy from '../core/PathProxy'; import { GradientObject } from '../graphic/Gradient'; -import { CanvasPatternObject, InnerCanvasPatternObject, PatternObject } from '../graphic/Pattern'; +import { ImagePatternObject, InnerImagePatternObject, PatternObject } from '../graphic/Pattern'; import { LinearGradientObject } from '../graphic/LinearGradient'; import { RadialGradientObject } from '../graphic/RadialGradient'; import { ZRCanvasRenderingContext } from '../core/types'; @@ -58,10 +58,10 @@ function doStrokePath(ctx: CanvasRenderingContext2D, style: PathStyleProps) { export function createCanvasPattern( this: void, ctx: CanvasRenderingContext2D, - pattern: CanvasPatternObject, + pattern: ImagePatternObject, el: {dirty: () => void} ): CanvasPattern { - const image = createOrUpdateImage(pattern.image, (pattern as InnerCanvasPatternObject).__image, el); + const image = createOrUpdateImage(pattern.image, (pattern as InnerImagePatternObject).__image, el); if (isImageReady(image)) { const canvasPattern = ctx.createPattern(image, pattern.repeat || 'repeat'); if ( @@ -132,14 +132,14 @@ function brushPath(ctx: CanvasRenderingContext2D, el: Path, style: PathStyleProp if (hasFillPattern) { // Pattern might be null if image not ready (even created from dataURI) fillPattern = (el.__dirty || !el.__canvasFillPattern) - ? createCanvasPattern(ctx, fill as CanvasPatternObject, el) + ? createCanvasPattern(ctx, fill as ImagePatternObject, el) : el.__canvasFillPattern; el.__canvasFillPattern = fillPattern; } if (hasStrokePattern) { // Pattern might be null if image not ready (even created from dataURI) strokePattern = (el.__dirty || !el.__canvasStrokePattern) - ? createCanvasPattern(ctx, stroke as CanvasPatternObject, el) + ? createCanvasPattern(ctx, stroke as ImagePatternObject, el) : el.__canvasStrokePattern; el.__canvasStrokePattern = fillPattern; } diff --git a/src/graphic/Pattern.ts b/src/graphic/Pattern.ts index da746220f..c3821abf3 100644 --- a/src/graphic/Pattern.ts +++ b/src/graphic/Pattern.ts @@ -1,6 +1,6 @@ import { ImageLike } from '../core/types'; -type CanvasPatternRepeat = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' +type ImagePatternRepeat = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' export interface PatternObjectBase { // type is now unused, so make it optional @@ -15,11 +15,11 @@ export interface PatternObjectBase { scaleY?: number } -export interface CanvasPatternObject extends PatternObjectBase { - repeat?: CanvasPatternRepeat +export interface ImagePatternObject extends PatternObjectBase { + repeat?: ImagePatternRepeat } -export interface InnerCanvasPatternObject extends CanvasPatternObject { +export interface InnerImagePatternObject extends ImagePatternObject { // Cached image. Which is created in the canvas painter. __image?: ImageLike } @@ -36,7 +36,7 @@ export interface SVGPatternObject extends PatternObjectBase { svgHeight?: number } -export type PatternObject = CanvasPatternObject | SVGPatternObject +export type PatternObject = ImagePatternObject | SVGPatternObject class Pattern { diff --git a/src/svg/helper/PatternManager.ts b/src/svg/helper/PatternManager.ts index 524b791f5..81c166a33 100644 --- a/src/svg/helper/PatternManager.ts +++ b/src/svg/helper/PatternManager.ts @@ -216,8 +216,3 @@ export default class PatternManager extends Definable { } } - -type CachedImageObj = { - width: number, - height: number -};