Skip to content

Commit

Permalink
Implement printing
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau committed Jan 22, 2024
1 parent 808c1c6 commit f79ce42
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 23 deletions.
35 changes: 33 additions & 2 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,44 @@
font-family: sans-serif;
text-align: center;
padding-top: 10vw;
cursor: pointer;
}
#continue {
z-index: 100;
display: none;
}
#printerpage {
position: fixed;
top: 0; left: 0; bottom: 0; right: 0;
}
#printedimage {
width: 100%;
height: 100%;
object-fit: contain;
}
@media screen {
#printerpage {
display: none;
}
}
@media print {
@page {
size: A4;
margin: 0;
}
html, body {
width: 210mm;
height: 100%;
}
* {
background: transparent !important;
}
body > * {
display: none !important;
}
#printerpage {
display: block !important;
}
}
#logo {
width: 20vw;
height: 20vw;
Expand All @@ -32,7 +64,6 @@ canvas.b3daccel {
}
canvas {
position: fixed;
cursor: default;
}
.pixelated {
image-rendering: -moz-crisp-edges;
Expand Down
69 changes: 49 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<br>
<img id="logo" src="index.png"><br>
</div>
<div id="printerpage">
<img id="printedimage">
</div>
<script src="vm/plopp-mpeg3-plugin.js"></script>
<script src="vm/plopp-b3daccel-plugin.js"></script>
<script src="vm/plopp-b3dengine-plugin.js"></script>
Expand All @@ -39,7 +42,7 @@
// TODO:
// [x] - implement primJPEGWriteImage, required for:
// [ ] - photo/wallpaper export
// [ ] - printing
// [x] - printing
// [ ] - ecard sending (?)

// the main reason for requiring a click
Expand All @@ -50,10 +53,9 @@
Squeak.fsck = function() {};
// reload templates if from older version
if (Squeak.Settings["squeak-template:/Plopp"] && !Squeak.Settings["squeak-template:/Plopp"].includes("Contents/Resources")) {
var all = Object.keys(Squeak.Settings);
for (var i = 0; i < all.length; i++) {
var key = all[i];
if (key.startsWith("squeak-template:/jasmine")) {
const all = Object.keys(Squeak.Settings);
for (const key of all) {
if (key.startsWith("squeak-template:/Plopp")) {
delete Squeak.Settings[key];
}
}
Expand All @@ -71,52 +73,79 @@
window.PloppAudio = new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA");
// for some reason, timing is more accurate on iOS
// if we play through an audio context
var audioCtx = Squeak.startAudioOut();
var node = audioCtx.createMediaElementSource(PloppAudio);
node.connect(audioCtx.destination);
const audioCtx = Squeak.startAudioOut();
const audioNode = audioCtx.createMediaElementSource(PloppAudio);
audioNode.connect(audioCtx.destination);
PloppAudio.play();
// pretend to be unix
Squeak.platformName = "unix";
// emulate system calls
// we need a temp directory for printing
Squeak.dirCreate("/tmp");
// emulate unix system calls
Squeak.registerExternalModule('libc.so', {
getModuleName() { return "libc.so (plopp)"; },
setInterpreter(proxy) { this.vm = proxy.vm; return true; },
getenv(v) {
if (v === "HOME") return "/Plopp/user";
console.warn("UNIMPLEMENTED getenv: " + v);
debugger
},
system(command) {
var argv = command.split(" ").map(a => a.replace(/^'(.*)'$/, "$1"));
const argv = command.split(" ").map(a => a.replace(/^'(.*)'$/, "$1"));
if (argv[0] === "/SqueakJS/openbrowser.sh") {
var url = argv[1].replace(/^file:\/\/\/SqueakJS\/Plopp\//, "Contents/Resources/");
const url = argv[1].replace(/^file:\/\/\/SqueakJS\/Plopp\//, "Contents/Resources/");
window.open(url);
return 0;
}
if (argv[0] === "/SqueakJS/print.sh") {
var file = argv[1];
// e.g. /tmp/plopp.jpg
console.warn("UNIMPLEMENTED print: " + file);
let file = argv[1]; // e.g. /tmp/plopp.jpg
let unfreeze = this.vm.freeze();
let url;
const proceed = () => {
if (file) { Squeak.fileDelete(file); file = null; }
if (url) { URL.revokeObjectURL(url); url = null; }
if (unfreeze) { unfreeze(); unfreeze = null; }
};
Squeak.fileGet(file,
data => {
const blob = new Blob([data], {type: "image/jpeg"});
url = URL.createObjectURL(blob);
const img = document.getElementById("printedimage");
img.src = url;
img.onload = () => {
window.print();
img.src = "";
proceed();
};
img.onerror = () => {
console.warn("print: failed to load " + file);
proceed();
};
}, err => {
console.warn("print: failed to get " + file);
file = null;
proceed();
});
return 0;
}
if (argv[0] === '/SqueakJS/setdesktop.sh') {
var file = argv[1];
// e.g. /Plopp/user/Plopp/plopp-wallpaper106128440.jpg
const file = argv[1]; // e.g. /Plopp/user/Plopp/plopp-wallpaper106128440.jpg
console.warn("UNIMPLEMENTED setdesktop: " + file);
return 0;
}
console.warn("UNIMPLEMENTED system: " + command);
console.warn("UNIMPLEMENTED system command: " + command);
debugger
return 1;
},
});
var url = "Contents/Resources/plopp.image";
SqueakJS.runSqueak(url, sqCanvas, {
SqueakJS.runSqueak("Contents/Resources/plopp.image", sqCanvas, {
appName: "Plopp",
fixedWidth: 800,
fixedHeight: 600,
fullscreen: true,
spinner: sqSpinner,
root: "/Plopp",
templates: { "/Plopp": "./" },
templates: { "/Plopp": "." },
});
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion vm/squeak.js

Large diffs are not rendered by default.

0 comments on commit f79ce42

Please sign in to comment.