Skip to content

Commit 34c51cc

Browse files
committed
- Fixed: eyedropper and various other function broken in Safari 16 and older
- Fixed: brush strokes too thin in Safari 16 and older
1 parent 4d2305d commit 34c51cc

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/app/script/bb/input/pointer-listener.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ function correctPointerEvent(
179179
}
180180
// Spec: If there's no pressure support, pressure is 0.5.
181181
// https://w3c.github.io/pointerevents/#dom-pointerevent-pressure
182-
if (event.pointerType === 'mouse' && event.pressure === 0.5) {
182+
// & in older Safari (<=16) it seems to be "mouse" and 0.
183+
if (event.pointerType === 'mouse' && (event.pressure === 0.5 || event.pressure === 0)) {
183184
correctedObj.pressure = 1;
184185
customPressure = 1;
185186
}

src/app/script/klecks/canvas/eyedropper.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ export class Eyedropper {
1616
}
1717

1818
const canvas = BB.canvas(1, 1);
19-
const ctx = BB.ctx(canvas, { willReadFrequently: true });
19+
const ctx = BB.ctx(canvas);
2020
ctx.imageSmoothingEnabled = false;
2121

22-
const layerCanvas = BB.canvas(1, 1);
23-
const layerCtx = BB.ctx(layerCanvas);
24-
layerCtx.imageSmoothingEnabled = false;
25-
const imageData = new ImageData(1, 1);
26-
2722
const tilesX = Math.ceil(composed.size.width / HISTORY_TILE_SIZE);
2823
const tileCol = Math.floor(x / HISTORY_TILE_SIZE);
2924
const tileRow = Math.floor(y / HISTORY_TILE_SIZE);
@@ -44,6 +39,7 @@ export class Eyedropper {
4439
return;
4540
}
4641
const tile = layer.tiles[tileIndex];
42+
let fillStyle = '';
4743
if (tile instanceof ImageData) {
4844
let tileWidth = HISTORY_TILE_SIZE;
4945
if (composed.size.width % HISTORY_TILE_SIZE !== 0 && tileCol === tilesX - 1) {
@@ -52,20 +48,24 @@ export class Eyedropper {
5248
const pixelIndex =
5349
(y % HISTORY_TILE_SIZE) * tileWidth + (x % HISTORY_TILE_SIZE);
5450

55-
imageData.data[0] = tile.data[pixelIndex * 4];
56-
imageData.data[1] = tile.data[pixelIndex * 4 + 1];
57-
imageData.data[2] = tile.data[pixelIndex * 4 + 2];
58-
imageData.data[3] = tile.data[pixelIndex * 4 + 3];
59-
layerCtx.putImageData(imageData, 0, 0);
51+
if (tile.data[pixelIndex * 4 + 3] === 0) {
52+
return;
53+
}
54+
55+
fillStyle = BB.ColorConverter.toRgbaStr({
56+
r: tile.data[pixelIndex * 4],
57+
g: tile.data[pixelIndex * 4 + 1],
58+
b: tile.data[pixelIndex * 4 + 2],
59+
a: tile.data[pixelIndex * 4 + 3],
60+
});
6061
} else {
61-
layerCtx.clearRect(0, 0, 1, 1);
62-
layerCtx.fillStyle = tile.fill;
63-
layerCtx.fillRect(0, 0, 1, 1);
62+
fillStyle = tile.fill;
6463
}
6564

65+
ctx.fillStyle = fillStyle;
6666
ctx.globalAlpha = layer.opacity;
6767
ctx.globalCompositeOperation = layer.mixModeStr;
68-
ctx.drawImage(layerCanvas, 0, 0);
68+
ctx.fillRect(0, 0, 1, 1);
6969
});
7070

7171
const imData = ctx.getImageData(0, 0, 1, 1);

0 commit comments

Comments
 (0)