浏览代码

Add a check for a Safari bug

Drawing an SVGImageElement to a canvas goes haywire. This checks for
that behavior and warns about it, and turns off the fine-grained
selection logic.
master
Fen Dweller 3 年前
父节点
当前提交
ac3b8a70b5
共有 3 个文件被更改,包括 31 次插入1 次删除
  1. +2
    -0
      macrovision.html
  2. +22
    -1
      macrovision.js
  3. +7
    -0
      media/test-circle.svg

+ 2
- 0
macrovision.html 查看文件

@@ -253,6 +253,8 @@
</div>
</div>

<img id="webkitBugTest" src="./media/test-circle.svg" style="position:absolute; top: -1000px; width: 500px; height: 500px" />

</body>

</html>

+ 22
- 1
macrovision.js 查看文件

@@ -51,6 +51,8 @@ let rulers = [];

let currentRuler = undefined;

let webkitCanvasBug = false;

const tagDefs = {
"anthro": "Anthro",
"feral": "Feral",
@@ -2050,10 +2052,14 @@ function rotate(point, angle) {

const testCtx = testCanvas.getContext("2d");
function testClick(event) {
const target = event.target;

if (webkitCanvasBug)
{
return clickDown(target.parentElement, event.clientX, event.clientY);
}
testCtx.save();

const target = event.target;
if (rulerMode) {
return;
}
@@ -4333,6 +4339,21 @@ document.addEventListener("DOMContentLoaded", () => {

document.querySelector("#search-box").addEventListener("change", e => doSearch(e.target.value));

// Webkit doesn't draw resized SVGs correctly. It will always draw them at their intrinsic size, I think
// This checks for that.
webkitBugTest.onload = () => {
testCtx.canvas.width = 500;
testCtx.canvas.height = 500;
testCtx.clearRect(0, 0, 500, 500);
testCtx.drawImage(webkitBugTest, 0, 0, 500, 500);
webkitCanvasBug = testCtx.getImageData(250, 250, 1, 1).data[3] == 0

if (webkitCanvasBug) {
toast("Heads up: Safari can't select through gaps or take screenshots (check the console for info!)")
console.log("Webkit messes up the process of drawing an SVG image to a canvas. This is important for both selecting things (it lets you click through a gap and hit something else) and for taking screenshots (since it needs to render them to a canvas). Sorry :(")
}
}

});

let searchText = "";


+ 7
- 0
media/test-circle.svg 查看文件

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="100" height="100" viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve">
<g>
<circle cx="50" cy="50" r="50"/>
</g>
</svg>

正在加载...
取消
保存