Merge pull request #16713 from calixteman/draw_bg
Draw correctly background images in ref tests
This commit is contained in:
commit
dca4bc0f24
@ -61,16 +61,12 @@ function loadStyles(styles) {
|
|||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeSVG(svgElement, ctx) {
|
function loadImage(svg_xml, ctx) {
|
||||||
// We need to have UTF-8 encoded XML.
|
|
||||||
const svg_xml = unescape(
|
|
||||||
encodeURIComponent(new XMLSerializer().serializeToString(svgElement))
|
|
||||||
);
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = "data:image/svg+xml;base64," + btoa(svg_xml);
|
img.src = "data:image/svg+xml;base64," + btoa(svg_xml);
|
||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
ctx.drawImage(img, 0, 0);
|
ctx?.drawImage(img, 0, 0);
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
img.onerror = function (e) {
|
img.onerror = function (e) {
|
||||||
@ -79,6 +75,19 @@ function writeSVG(svgElement, ctx) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function writeSVG(svgElement, ctx) {
|
||||||
|
// We need to have UTF-8 encoded XML.
|
||||||
|
const svg_xml = unescape(
|
||||||
|
encodeURIComponent(new XMLSerializer().serializeToString(svgElement))
|
||||||
|
);
|
||||||
|
if (svg_xml.includes("background-image: url("data:image")) {
|
||||||
|
// Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1844414
|
||||||
|
// we load the image two times.
|
||||||
|
await loadImage(svg_xml, null);
|
||||||
|
}
|
||||||
|
return loadImage(svg_xml, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
async function inlineImages(node, silentErrors = false) {
|
async function inlineImages(node, silentErrors = false) {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user