diff --git a/demo/node/make_image.js b/demo/node/make_image.js index b0a519a45..8744fd594 100644 --- a/demo/node/make_image.js +++ b/demo/node/make_image.js @@ -13,7 +13,9 @@ let outdir = ''; if (process?.argv && process.argv[2]) outdir = process.argv[2]; -function processResults(name, title, svg, pdf, png) { +function processResults(name, title, svg, svg_ref, svg_diff, + pdf, pdf_ref, pdf_diff, + png, png_ref, png_diff) { console.log(`${title} ${name}.svg ${svg.length} ${name}.pdf ${pdf.byteLength} ${name}.png ${png.byteLength}`); if (svg.length) @@ -21,15 +23,24 @@ function processResults(name, title, svg, pdf, png) { else console.error(`Fail to create SVG for ${title}`); + if (Math.abs(svg.length - svg_ref) > svg_diff) + console.error(`${name}.svg length ${svg.length} differs too much from reference ${svg_ref}`); + if (pdf.byteLength) writeFileSync(`${outdir+name}.pdf`, pdf); else console.error(`Fail to create PDF for ${title}`); + if (Math.abs(pdf.byteLength - pdf_ref) > pdf_diff) + console.error(`${name}.pdf length ${pdf.byteLength} differs too much from reference ${pdf_ref}`); + if (png.byteLength) writeFileSync(`${outdir+name}.png`, png); else console.error(`Fail to create PNG for ${title}`); + + if (Math.abs(png.byteLength - png_ref) > png_diff) + console.error(`${name}.png length ${png.byteLength} differs too much from reference ${png_ref}`); } @@ -48,26 +59,26 @@ const svg1 = await makeSVG({ object: hpxpy, option: 'col', width, height }), pdf1buf = await makeImage({ format: 'pdf', as_buffer: true, object: hpxpy, option: 'col', width, height }), png1buf = await makeImage({ format: 'png', as_buffer: true, object: hpxpy, option: 'col', width, height }); -processResults('hist2d', 'histogram col drawing', svg1, pdf1buf, png1buf); +processResults('hist2d', 'histogram col drawing', svg1, 13179, 100, pdf1buf, 33456, 500, png1buf, 56707, 20000); // testing 3D graphics const svg2 = await makeSVG({ object: hpxpy, option: 'lego2', width, height }), pdf2buf = await makeImage({ format: 'pdf', as_buffer: true, object: hpxpy, option: 'lego2', width, height }), png2buf = await makeImage({ format: 'png', as_buffer: true, object: hpxpy, option: 'lego2', width, height }); -processResults('lego', 'histogram lego drawing', svg2, pdf2buf, png2buf); +processResults('lego', 'histogram lego drawing', svg2, 57225, 20000, pdf2buf, 3086057, 1000000, png2buf, 88824, 30000); // testing geometry const svg3 = await makeSVG({ object: geom, option: '', width, height }), pdf3buf = await makeImage({ format: 'pdf', as_buffer: true, object: geom, option: '', width, height }), png3buf = await makeImage({ format: 'png', as_buffer: true, object: geom, option: '', width, height }); -processResults('geom', 'geometry drawing', svg3, pdf3buf, png3buf); +processResults('geom', 'geometry drawing', svg3, 92099, 20000, pdf3buf, 68967, 20000, png3buf, 68967, 20000); // testing latex with special symbols const svg4 = await makeSVG({ object: latex, option: '', width, height }), pdf4buf = await makeImage({ format: 'pdf', as_buffer: true, object: latex, option: '', width, height }), png4buf = await makeImage({ format: 'png', as_buffer: true, object: latex, option: '', width, height }); -processResults('latex', 'Canvas with latex and symbols.ttf', svg4, pdf4buf, png4buf); +processResults('latex', 'Canvas with latex and symbols.ttf', svg4, 5608, 100, pdf4buf, 9388, 500, png4buf, 41620, 15000);