MCPcopy
hub / github.com/baidu/amis / customDrawWithCache

Method customDrawWithCache

packages/office-viewer/src/excel/render/Canvas.ts:403–426  ·  view source on GitHub ↗

* 运行绘制并缓存

(
    cacheKey: string,
    x: number,
    y: number,
    width: number,
    height: number,
    func: (ctx: OffscreenCanvasRenderingContext2D, ratio: number) => void
  )

Source from the content-addressed store, hash-verified

401 * 运行绘制并缓存
402 */
403 async customDrawWithCache(
404 cacheKey: string,
405 x: number,
406 y: number,
407 width: number,
408 height: number,
409 func: (ctx: OffscreenCanvasRenderingContext2D, ratio: number) => void
410 ): Promise<void> {
411 return new Promise<void>((resolve, reject) => {
412 const ratio = this.ratio * this.zoom;
413 const cache = this.imageCache.get(cacheKey);
414 if (cache) {
415 this.ctx.drawImage(cache, x, y, width, height);
416 resolve();
417 return;
418 }
419 const imageBitmap = drawOffscreenCanvas(ratio, width, height, ctx => {
420 func(ctx, ratio);
421 });
422 this.ctx.drawImage(imageBitmap, x, y, width, height);
423 this.imageCache.set(cacheKey, imageBitmap);
424 resolve();
425 });
426 }
427
428 /**
429 * 清空缓存

Callers 1

drawSparklineFunction · 0.80

Calls 5

drawOffscreenCanvasFunction · 0.90
resolveFunction · 0.85
drawImageMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected