Skip to content

Commit

Permalink
Merge pull request #1797 from googlefonts/copy-bg-image-as-image-issu…
Browse files Browse the repository at this point in the history
…e1796

[background image] On copy, put background image as image data on the clipboard
  • Loading branch information
justvanrossum authored Nov 16, 2024
2 parents 1d67e6c + 8dab5ad commit b246b30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/fontra/client/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,12 @@ export async function writeToClipboard(clipboardObject) {

const clipboardItemObject = {};
for (const [key, value] of Object.entries(clipboardObject)) {
clipboardItemObject[key] = new Blob([value], {
type: key,
});
if (value instanceof Blob) {
assert(key === value.type);
clipboardItemObject[key] = value;
} else {
clipboardItemObject[key] = new Blob([value], { type: key });
}
}

try {
Expand Down
16 changes: 16 additions & 0 deletions src/fontra/views/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1833,10 +1833,26 @@ export class EditorController {
"web image/svg+xml": svgString,
"web fontra/static-glyph": jsonString,
};

await this._addBackgroundImageToClipboard(clipboardObject, backgroundImageData);

await writeToClipboard(clipboardObject);
}
}

async _addBackgroundImageToClipboard(clipboardObject, backgroundImageData) {
if (
this.sceneController.selection.size == 1 &&
this.sceneController.selection.has("backgroundImage/0") &&
backgroundImageData &&
Object.keys(backgroundImageData).length == 1
) {
const res = await fetch(Object.values(backgroundImageData)[0]);
const blob = await res.blob();
clipboardObject[blob.type] = blob;
}
}

_prepareCopyOrCutLayers(varGlyph, doCut) {
let varGlyphController;
if (!varGlyph) {
Expand Down

0 comments on commit b246b30

Please sign in to comment.