From 7911b6deda1f73814eb20d3462e5dafd60f124d0 Mon Sep 17 00:00:00 2001 From: Michal Szczepanski Date: Tue, 17 Oct 2023 02:31:39 +0200 Subject: [PATCH] fix: firefox fill - show bug information --- .../pin/draw/draw-area.component.ts | 20 +++++++++++++++++-- .../components/pin/draw/tool/fill.draw.ts | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/common/components/pin/draw/draw-area.component.ts b/src/common/components/pin/draw/draw-area.component.ts index 553149f..fa94c9b 100644 --- a/src/common/components/pin/draw/draw-area.component.ts +++ b/src/common/components/pin/draw/draw-area.component.ts @@ -15,6 +15,7 @@ * along with this program. If not, see . */ import { DrawToolDto, ObjDrawDataDto } from '../../../model/obj/obj-draw.dto'; +import { BrowserApi } from '@pinmenote/browser-api'; import { DrawDataModel } from '../model/pin-draw-edit.model'; import { EraserDraw } from './tool/eraser.draw'; import { FillDraw } from './tool/fill.draw'; @@ -23,6 +24,7 @@ import { ObjPointDto } from '../../../model/obj/obj-utils.dto'; import { PencilDraw } from './tool/pencil.draw'; import { PinEditModel } from '../model/pin-edit.model'; import { applyStylesToElement } from '../../../style.utils'; +import { fnConsoleLog } from '../../../fn/fn-console'; const canvasStyles = { position: 'absolute', @@ -188,8 +190,22 @@ no javascript enabled - drawing not working`; EraserDraw.raster(points, this.model.draw.size, this.rasterCtx); break; case DrawToolDto.Fill: - points = FillDraw.fill({ x: e.offsetX, y: e.offsetY }, this.model.draw.color, this.drawCtx); - FillDraw.raster(points, this.model.draw.color, this.rasterCtx); + try { + points = FillDraw.fill({ x: e.offsetX, y: e.offsetY }, this.model.draw.color, this.drawCtx); + FillDraw.raster(points, this.model.draw.color, this.rasterCtx); + } catch (e) { + fnConsoleLog('drawOne->error', e); + if ( + !BrowserApi.isChrome && + e instanceof DOMException && + e.message.startsWith('CanvasRenderingContext2D.putImageData') + ) { + alert( + 'Firefox problem - see details under this bug url https://bugzilla.mozilla.org/show_bug.cgi?id=1853273' + ); + return; + } + } break; } // clear draw canvas diff --git a/src/common/components/pin/draw/tool/fill.draw.ts b/src/common/components/pin/draw/tool/fill.draw.ts index 2a3b139..b1985b8 100644 --- a/src/common/components/pin/draw/tool/fill.draw.ts +++ b/src/common/components/pin/draw/tool/fill.draw.ts @@ -66,7 +66,7 @@ export class FillDraw { stack.push({ x: point.x, y: point.y - 1 }); } } - const imData = new ImageData(new Uint8ClampedArray(pixelData), width, height); + const imData = new ImageData(pixelData, width, height); ctx.putImageData(imData, 0, 0); return [from];