Skip to content

Commit

Permalink
fix(pattern): rename CanvasPatternObject to ImagePatternObject.
Browse files Browse the repository at this point in the history
  • Loading branch information
plainheart committed May 17, 2021
1 parent d30bcf7 commit 3c2fb9a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/canvas/graphic.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/graphic/Pattern.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Expand All @@ -36,7 +36,7 @@ export interface SVGPatternObject extends PatternObjectBase {
svgHeight?: number
}

export type PatternObject = CanvasPatternObject | SVGPatternObject
export type PatternObject = ImagePatternObject | SVGPatternObject

class Pattern {

Expand Down
5 changes: 0 additions & 5 deletions src/svg/helper/PatternManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,3 @@ export default class PatternManager extends Definable {
}

}

type CachedImageObj = {
width: number,
height: number
};

0 comments on commit 3c2fb9a

Please sign in to comment.