fix encoding of embed data & compress (#2240)

This commit is contained in:
David Luzar 2020-10-15 21:31:21 +02:00 committed by GitHub
parent e8a39b5f84
commit b3263c2a69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 483 additions and 122 deletions

View file

@ -19,8 +19,6 @@ import { serializeAsJSON } from "./json";
import { ExportType } from "../scene/types";
import { restore } from "./restore";
import { ImportedDataState } from "./types";
import { MIME_TYPES } from "../constants";
import { stringToBase64 } from "../base64";
export { loadFromBlob } from "./blob";
export { saveAsJSON, loadFromJSON } from "./json";
@ -302,21 +300,17 @@ export const exportCanvas = async (
return window.alert(t("alerts.cannotExportEmptyCanvas"));
}
if (type === "svg" || type === "clipboard-svg") {
let metadata = "";
if (appState.exportEmbedScene && type === "svg") {
metadata += `<!-- payload-type:${MIME_TYPES.excalidraw} -->`;
metadata += "<!-- payload-start -->";
metadata += await stringToBase64(serializeAsJSON(elements, appState));
metadata += "<!-- payload-end -->";
}
const tempSvg = exportToSvg(elements, {
exportBackground,
viewBackgroundColor,
exportPadding,
shouldAddWatermark,
metadata,
metadata:
appState.exportEmbedScene && type === "svg"
? await (await import("./image")).encodeSvgMetadata({
text: serializeAsJSON(elements, appState),
})
: undefined,
});
if (type === "svg") {
await fileSave(new Blob([tempSvg.outerHTML], { type: "image/svg+xml" }), {
@ -345,9 +339,9 @@ export const exportCanvas = async (
tempCanvas.toBlob(async (blob) => {
if (blob) {
if (appState.exportEmbedScene) {
blob = await (await import("./png")).encodeTEXtChunk(blob, {
keyword: MIME_TYPES.excalidraw,
text: serializeAsJSON(elements, appState),
blob = await (await import("./image")).encodePngMetadata({
blob,
metadata: serializeAsJSON(elements, appState),
});
}