feat: a PNG that records 200 DPI or more offers its own size, Manter, and the Prumo says if it was kept (Rodada 5, A1)

The Site reads the pHYs chunk of a loose art; at 200 DPI or more the
size in the file is the default width and a Manter button sits before
the table sizes (also when the art is turned 90 degrees). The source
carries saved_width_cm and saved_dpi, used only by the Prumo report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-30 11:11:21 -03:00
parent 7e33e6fb1d
commit 7fc091a1bd
8 changed files with 121 additions and 4 deletions

View File

@@ -192,6 +192,30 @@ async function dimensoesImagem(file){
}
return null;
}
// The PNG may record its own resolution in the pHYs chunk. A loose art that
// says 200 DPI or more has a real size in pixels ÷ DPI, offered as "Manter";
// below 200 DPI, or without the chunk, it says nothing. Never throws.
async function dpiSalvoPng(file){
try{
if(!file || !(file.size>0)) return null;
const b=new Uint8Array(await file.slice(0,Math.min(file.size,4*1048576)).arrayBuffer());
if(!(b.length>=8 && b[0]===0x89 && b[1]===0x50 && b[2]===0x4E && b[3]===0x47)) return null;
const u32=i=>((b[i]<<24)>>>0)+(b[i+1]<<16)+(b[i+2]<<8)+b[i+3];
let i=8;
while(i+12<=b.length){
const len=u32(i), tipo=String.fromCharCode(...b.slice(i+4,i+8));
if(tipo==='pHYs'){
if(len<9 || i+8+len>b.length) return null;
const ppmX=u32(i+8), ppmY=u32(i+12), unidade=b[i+16];
if(unidade===1 && ppmX>0 && ppmX===ppmY) return Math.round(ppmX*0.0254);
return null;
}
if(tipo==='IDAT' || tipo==='IEND') return null;
i+=12+len;
}
return null;
}catch(e){ return null; }
}
// A small copy of a large PNG, read as a stream: the file is inflated in
// pieces and only every n-th pixel of every n-th row is kept, so memory stays
// at a few MB whatever the file's size. It is the preview. Given the sheet's
@@ -748,6 +772,12 @@ function pintaArtes(){
'A arte entra na folha pela medida, e a equipe confere antes de imprimir. Em PNG, a prévia aparece.</p>';
const mini = a.miniSrc ? '<img src="'+escapeHTML(a.miniSrc)+'" alt="">' : '<span>'+escapeHTML(extDe(a.f.name))+'</span>';
const sub = a.cm>0 && (a.src||a.semPrevia) ? (a.q>1? a.q+' × ' : '')+'<b>'+n1(a.cm)+' × '+n1(a.cm*propDe(a))+' cm</b>' : '';
// Girada, a largura na folha é a altura salva no arquivo.
const salvo = a.cmSalvo ? Math.round((a.giro? a.cmSalvo*(a.prop||1) : a.cmSalvo)*10)/10 : 0;
const manter = salvo && salvo<=larguraFilme()
? '<button class="tm'+(Math.abs(a.cm-salvo)<0.05?' on':'')+'" data-tam="'+i+'" data-t="'+salvo+'">'+
'Manter '+n1(salvo)+' × '+n1(salvo*propDe(a))+' cm</button>'
: '';
return '<div class="rep art2'+(a===recemChegada?' nova':'')+'" data-arte="'+i+'">'+
'<div class="repTopo"><div class="miniF">'+mini+'</div><div class="repInfo">'+
'<div class="l1"><b>'+escapeHTML(a.f.name)+'</b>'+(a===recemChegada?'<em class="novaT">nova</em>':'')+
@@ -769,7 +799,7 @@ function pintaArtes(){
'<button class="gr'+(a.giro?' on':'')+'" data-giro="'+i+'" title="Girar 90°" aria-label="Girar 90°">'+icone('girar')+'</button>'+
(espelhavel() ? '<button class="gr'+(a.esp?' on':'')+'" data-esp="'+i+'" title="Espelhar" aria-label="Espelhar">'+icone('espelhar')+'</button>' : '')+'</span>'+
(sub? '<div class="conta">'+sub+'</div>' : '')+
'<div class="atalhos">'+(TAMANHOS[larguraFilme()]||[]).map(t=>'<button class="tm'+
'<div class="atalhos">'+manter+(TAMANHOS[larguraFilme()]||[]).map(t=>'<button class="tm'+
(Math.abs(a.cm-t)<0.05?' on':'')+'" data-tam="'+i+'" data-t="'+t+'">'+n1(t)+' cm</button>').join('')+'</div>'+
'</div>'+
'</div>';