(pattern: PatternObject)
| 97 | return pattern; |
| 98 | |
| 99 | function setPatternnSource(pattern: PatternObject) { |
| 100 | const keys = [dpr]; |
| 101 | let isValidKey = true; |
| 102 | for (let i = 0; i < decalKeys.length; ++i) { |
| 103 | const value = (decalOpt as any)[decalKeys[i]]; |
| 104 | if (value != null |
| 105 | && !isArray(value) |
| 106 | && !isString(value) |
| 107 | && !isNumber(value) |
| 108 | && typeof value !== 'boolean' |
| 109 | ) { |
| 110 | isValidKey = false; |
| 111 | break; |
| 112 | } |
| 113 | keys.push(value); |
| 114 | } |
| 115 | |
| 116 | let cacheKey; |
| 117 | if (isValidKey) { |
| 118 | cacheKey = keys.join(',') + (isSVG ? '-svg' : ''); |
| 119 | const cache = decalCache.get(cacheKey); |
| 120 | if (cache) { |
| 121 | isSVG ? (pattern as SVGPatternObject).svgElement = cache as SVGVNode |
| 122 | : (pattern as ImagePatternObject).image = cache as HTMLCanvasElement; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | const dashArrayX = normalizeDashArrayX(decalOpt.dashArrayX); |
| 127 | const dashArrayY = normalizeDashArrayY(decalOpt.dashArrayY); |
| 128 | const symbolArray = normalizeSymbolArray(decalOpt.symbol); |
| 129 | const lineBlockLengthsX = getLineBlockLengthX(dashArrayX); |
| 130 | const lineBlockLengthY = getLineBlockLengthY(dashArrayY); |
| 131 | |
| 132 | const canvas = !isSVG && platformApi.createCanvas(); |
| 133 | const svgRoot: SVGVNode = isSVG && { |
| 134 | tag: 'g', |
| 135 | attrs: {}, |
| 136 | key: 'dcl', |
| 137 | children: [] |
| 138 | }; |
| 139 | const pSize = getPatternSize(); |
| 140 | let ctx: CanvasRenderingContext2D; |
| 141 | if (canvas) { |
| 142 | canvas.width = pSize.width * dpr; |
| 143 | canvas.height = pSize.height * dpr; |
| 144 | ctx = canvas.getContext('2d'); |
| 145 | } |
| 146 | brushDecal(); |
| 147 | |
| 148 | if (isValidKey) { |
| 149 | decalCache.put(cacheKey, canvas || svgRoot); |
| 150 | } |
| 151 | |
| 152 | (pattern as ImagePatternObject).image = canvas; |
| 153 | (pattern as SVGPatternObject).svgElement = svgRoot; |
| 154 | (pattern as SVGPatternObject).svgWidth = pSize.width; |
| 155 | (pattern as SVGPatternObject).svgHeight = pSize.height; |
| 156 |
no test coverage detected
searching dependent graphs…