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);
|
||||
}
|
||||
|
||||
function writeSVG(svgElement, ctx) {
|
||||
// We need to have UTF-8 encoded XML.
|
||||
const svg_xml = unescape(
|
||||
encodeURIComponent(new XMLSerializer().serializeToString(svgElement))
|
||||
);
|
||||
function loadImage(svg_xml, ctx) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.src = "data:image/svg+xml;base64," + btoa(svg_xml);
|
||||
img.onload = function () {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
ctx?.drawImage(img, 0, 0);
|
||||
resolve();
|
||||
};
|
||||
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) {
|
||||
const promises = [];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user