feat: a ready sheet prints at its real size, centred on the film, with the customer's confirmation (Marcus, 2026-12-02)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m55s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m43s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m55s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m43s
Replaces 7111995 (only 57,0 cm entered; a whole order of 56,5-56,9 cm
sheets was refused, DTF-WEB-2C). Marcus's rules, for Arquivo por metro,
Premium (57 cm) and UV (27 cm):
1. A known width up to the film (PNG recording 200 DPI or more, or a PDF
page) enters at its real size, centred, billed by its real height.
2. Narrower: his warning before the cart, confirmation required
(Imprimir no tamanho real / Enviar outro arquivo); recorded in the
Prumo report ("cliente confirmou folha de 35,8 cm no tamanho real") and
shown in the cart and payment summaries.
3. Wider than the film: refused with his message.
4. Unknown width: taken as the film's, DPI from the pixels; 200 or more
with a confirmation, under 200 refused with the artes avulsas hint.
Within 0,1 cm of the film counts as the film. The server checks it all
again at checkout (sheet_width_issue, centred placement, size_confirmed).
Also ops.stretched_sheets: the ready-sheet orders since 16/10 laid out
wider than their real width (number, real width, factor), for Marcus.
Contract: output/revisao/contrato-folha-real.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -162,15 +162,36 @@ try{
|
||||
else{$('inp').files=dt.files;$('inp').dispatchEvent(new Event('change',{bubbles:true}));}
|
||||
};
|
||||
// A genuine mounted sheet spans the film width with printable resolution,
|
||||
// on a transparent background; or with a solid one, or a residue dot.
|
||||
// on a transparent background; or with a solid one, or a residue dot. The
|
||||
// pHYs chunk makes its real width known, as a sheet exported at 300 DPI.
|
||||
window.comDpi=async(blob,ppm=11811)=>{
|
||||
const b=new Uint8Array(await blob.arrayBuffer());
|
||||
const crc=c=>{let x=0xffffffff;for(const v of c){x^=v;for(let k=0;k<8;k++)x=x&1?0xedb88320^(x>>>1):x>>>1;}return (x^0xffffffff)>>>0;};
|
||||
let i=8;
|
||||
while(i+8<=b.length){
|
||||
const len=((b[i]<<24)>>>0)+(b[i+1]<<16)+(b[i+2]<<8)+b[i+3];
|
||||
const tipo=String.fromCharCode(...b.slice(i+4,i+8));
|
||||
if(tipo==='IDAT'){
|
||||
const ch=new Uint8Array(21), dv=new DataView(ch.buffer);
|
||||
dv.setUint32(0,9);ch.set([0x70,0x48,0x59,0x73],4);
|
||||
dv.setUint32(8,ppm);dv.setUint32(12,ppm);ch[16]=1;
|
||||
dv.setUint32(17,crc(ch.subarray(4,17)));
|
||||
const out=new Uint8Array(b.length+21);
|
||||
out.set(b.subarray(0,i),0);out.set(ch,i);out.set(b.subarray(i),i+21);
|
||||
return new Blob([out],{type:'image/png'});
|
||||
}
|
||||
i+=12+len;
|
||||
}
|
||||
return blob;
|
||||
};
|
||||
window.sendSheet=async({fundo=false,ponto=false}={})=>{
|
||||
const cm=larguraFilme(), px=Math.ceil(cm/2.54*150);
|
||||
const cm=larguraFilme(), px=Math.ceil(cm/2.54*300);
|
||||
const c=document.createElement('canvas');c.width=px;c.height=Math.round(px*0.6);
|
||||
const ctx=c.getContext('2d');
|
||||
if(fundo){ctx.fillStyle='white';ctx.fillRect(0,0,c.width,c.height);}
|
||||
ctx.fillStyle='#222';ctx.fillRect(40,40,px/4,px/4);
|
||||
if(ponto)ctx.fillRect(Math.round(px*0.8),Math.round(c.height/2),4,4);
|
||||
const blob=await new Promise(r=>c.toBlob(r,'image/png'));
|
||||
const blob=await window.comDpi(await new Promise(r=>c.toBlob(r,'image/png')));
|
||||
const dt=new DataTransfer();dt.items.add(new File([blob],'folha-montada.png',{type:'image/png'}));
|
||||
$('inp').files=dt.files;$('inp').dispatchEvent(new Event('change',{bubbles:true}));
|
||||
};
|
||||
@@ -223,8 +244,9 @@ try{
|
||||
'files beyond the 4 GB upload limit are rejected before browser analysis');
|
||||
// A PNG above the browser's ~32k-pixel height limit cannot be checked here:
|
||||
// it is refused with a clear message instead of being accepted as 0 DPI.
|
||||
await evaluate(`(()=>{const h=new Uint8Array(33);h.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0,0,0,13,0x49,0x48,0x44,0x52]);
|
||||
await evaluate(`(()=>{const h=new Uint8Array(54);h.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0,0,0,13,0x49,0x48,0x44,0x52]);
|
||||
const v=new DataView(h.buffer);v.setUint32(16,6732);v.setUint32(20,35433);h.set([8,6,0,0,0],24);
|
||||
v.setUint32(33,9);h.set([0x70,0x48,0x59,0x73],37);v.setUint32(41,11811);v.setUint32(45,11811);h[49]=1;
|
||||
const f=new File([h],'folha-grande.png');Object.defineProperty(f,'size',{value:900*1048576});return sel([f]);})()`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'tall sheet refused');
|
||||
assert.equal(await evaluate(`folhas[0].measurementError.includes('PNG alto')`),true);
|
||||
@@ -232,34 +254,83 @@ try{
|
||||
// A ready textile sheet whose real width is known (PNG pHYs >= 200 DPI, or a
|
||||
// PDF page) must be 57 cm wide: otherwise it leaves the list and a dialog
|
||||
// names it. A hand-made PNG header with a pHYs chunk, read by its header.
|
||||
await evaluate(`window.pngLargura=async(w,ppm)=>{
|
||||
const b=new Uint8Array(54);b.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A]);
|
||||
await evaluate(`window.pngLargura=async(w,ppm,h=10339,nome='folha-larga.png')=>{
|
||||
const comDpi=ppm!=null, b=new Uint8Array(comDpi?54:33);
|
||||
b.set([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A]);
|
||||
const v=new DataView(b.buffer);
|
||||
v.setUint32(8,13);b.set([0x49,0x48,0x44,0x52],12);
|
||||
v.setUint32(16,w);v.setUint32(20,10339);b.set([8,6,0,0,0],24);
|
||||
v.setUint32(33,9);b.set([0x70,0x48,0x59,0x73],37);
|
||||
v.setUint32(41,ppm);v.setUint32(45,ppm);b[49]=1;
|
||||
const f=new File([b],'folha-larga.png',{type:'image/png'});
|
||||
v.setUint32(16,w);v.setUint32(20,h);b.set([8,6,0,0,0],24);
|
||||
if(comDpi){v.setUint32(33,9);b.set([0x70,0x48,0x59,0x73],37);
|
||||
v.setUint32(41,ppm);v.setUint32(45,ppm);b[49]=1;}
|
||||
const f=new File([b],nome,{type:'image/png'});
|
||||
Object.defineProperty(f,'size',{value:900*1048576});
|
||||
return sel([f]);}`);
|
||||
// S1/S2: 35,8 cm at 300 DPI enters at its real size and asks for confirmation.
|
||||
await evaluate(`pngLargura(4227,11811)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && $('larguraDlg').open`),'wrong-width sheet opens dialog');
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && $('tamanhoDlg').open`),'narrow sheet opens the size dialog');
|
||||
assert.equal(await evaluate(`$('tamanhoTit').textContent`),'folha-larga.png');
|
||||
const tamanhoTxt=await evaluate(`$('tamanhoTxt').textContent`);
|
||||
assert.match(tamanhoTxt,/35,8 cm/);
|
||||
assert.match(tamanhoTxt,/0,88 m/);
|
||||
assert.match(tamanhoTxt,/R\$ 21,90\/m/);
|
||||
assert.equal(await evaluate(`$('tamanhoOk').textContent`),'Imprimir no tamanho real');
|
||||
// While unconfirmed, "Adicionar ao carrinho" says so and adds nothing.
|
||||
assert.deepEqual(await evaluate(`(()=>{const antes=pedido.length;$('qOk').disabled=false;$('qOk').click();
|
||||
return {added:pedido.length-antes,msg:$('qmsg').textContent.includes('Confirme o tamanho')};})()`),
|
||||
{added:0,msg:true});
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`!$('tamanhoDlg').open && folhas[0]?.confirmado===true`),'narrow sheet confirmed');
|
||||
assert.ok(Math.abs(await evaluate(`folhas[0].med.larg`)-35.79)<0.02);
|
||||
assert.equal(await evaluate(`$('larguraDlg').open`),false);
|
||||
await waitFor(()=>evaluate(`itemAtual?.production?.sources[0]?.size_confirmed===true`),
|
||||
'confirmed size goes to the cart source');
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
// S3: "Enviar outro arquivo" takes the sheet out of the list.
|
||||
await evaluate(`pngLargura(4227,11811)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && $('tamanhoDlg').open`),'narrow sheet opens again');
|
||||
await click('#tamanhoOutro');
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && !$('tamanhoDlg').open`),'send another removes the sheet');
|
||||
// S6: 61,0 cm does not fit the film: it leaves and the width dialog names it.
|
||||
await evaluate(`pngLargura(7200,11811,10339,'folha-larga.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && $('larguraDlg').open`),'too-wide sheet opens the width dialog');
|
||||
assert.deepEqual(await evaluate(`({itens:$('larguraLista').children.length,
|
||||
texto:$('larguraLista').textContent})`),
|
||||
{itens:1,texto:'folha-larga.png: 35,8 cm (300 DPI)'});
|
||||
texto:$('larguraLista').textContent,titulo:$('larguraTit').textContent})`),
|
||||
{itens:1,texto:'folha-larga.png: tem 61,0 cm e não cabe em 57 cm.',
|
||||
titulo:'A folha não cabe no filme de 57 cm'});
|
||||
await click('#larguraOk');
|
||||
await waitFor(()=>evaluate(`!$('larguraDlg').open && $('larguraLista').children.length===0`),
|
||||
'width dialog closes and clears the list');
|
||||
// 6732 px at 300 DPI is 57 cm within tolerance: accepted as today.
|
||||
// S5: 6732 px at 300 DPI is 57 cm within tolerance: no dialog, real width.
|
||||
await evaluate(`pngLargura(6732,11811)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].med`),'57 cm sheet accepted');
|
||||
assert.equal(await evaluate(`$('larguraDlg').open`),false);
|
||||
assert.equal(await evaluate(`folhas[0].med.larg`),57);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].med && !$('tamanhoDlg').open && !$('larguraDlg').open`),
|
||||
'57 cm sheet accepted');
|
||||
assert.ok(Math.abs(await evaluate(`folhas[0].med.larg`)-56.998)<0.01);
|
||||
assert.equal(await evaluate(`!!folhas[0].confirmado`),false);
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
// Under 200 DPI the file says nothing about its real width: today's rule.
|
||||
await evaluate(`pngLargura(4227,3780)`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].med`),'low-DPI sheet follows today rule');
|
||||
assert.equal(await evaluate(`$('larguraDlg').open`),false);
|
||||
// S7: without pHYs the width is unknown, so it assumes the film and asks.
|
||||
await evaluate(`pngLargura(6732,null,10339,'folha-sem-dpi.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && $('tamanhoDlg').open`),'unknown width opens the size dialog');
|
||||
assert.equal(await evaluate(`$('tamanhoTit').textContent`),'folha-sem-dpi.png');
|
||||
assert.match(await evaluate(`$('tamanhoTxt').textContent`),
|
||||
/57 cm de largura e 87,5 cm de altura \(300 DPI\)/);
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`folhas[0]?.confirmado===true && !$('tamanhoDlg').open`),'unknown width confirmed');
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
// S8: unknown width with less than 200 DPI is refused by resolution.
|
||||
await evaluate(`pngLargura(2154,null,10339,'folha-baixa.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===0 && $('avisoTipo').textContent.includes('abaixo do mínimo de 200')`),
|
||||
'unknown width under 200 DPI is refused');
|
||||
assert.match(await evaluate(`$('avisoTipo').textContent`),/artes avulsas/);
|
||||
// S13: several sheets needing a dialog are answered one at a time, in order.
|
||||
await evaluate(`pngLargura(4227,11811,10339,'folha-a.png')`);
|
||||
await waitFor(()=>evaluate(`$('tamanhoDlg').open && $('tamanhoTit').textContent==='folha-a.png'`),'first sheet in order');
|
||||
await evaluate(`pngLargura(4300,11811,10339,'folha-b.png')`);
|
||||
await waitFor(()=>evaluate(`folhas.length===2`),'second sheet queued');
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`$('tamanhoDlg').open && $('tamanhoTit').textContent==='folha-b.png'`),'second sheet next');
|
||||
await click('#tamanhoOk');
|
||||
await waitFor(()=>evaluate(`!$('tamanhoDlg').open && folhas.length===2 && folhas.every(x=>x.confirmado)`),
|
||||
'each sheet answered on its own');
|
||||
await evaluate(`folhas=[];pintaFolha()`);
|
||||
await evaluate(`pickTipo('avulsa')`);
|
||||
assert.equal(await evaluate('modo'),'avulsa');
|
||||
@@ -458,11 +529,9 @@ try{
|
||||
// Parsed geometry honors inherited MediaBox, CropBox, rotation and UserUnit.
|
||||
// Extra pages and unreadable PDFs must never fall through to manual pricing.
|
||||
const pdfFile=(data,name='sheet.pdf')=>`new File([Uint8Array.from(atob(${data}),c=>c.charCodeAt(0))],${JSON.stringify(name)},{type:'application/pdf'})`;
|
||||
// Geometry alone: measured under UV, where the 57 cm rule does not apply.
|
||||
const rotated=await evaluate(`(async()=>{const m=modo;modo='uvfile';
|
||||
try{return await medirFolha(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))});}
|
||||
finally{modo=m;}})()`);
|
||||
assert.deepEqual(rotated,{larg:50.8,alt:25.4,fonte:'página do PDF · UserUnit 2'});
|
||||
// A 50,8 cm page on the 57 cm film: real size, asking for confirmation.
|
||||
const rotated=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))})`);
|
||||
assert.deepEqual(rotated,{larg:50.8,alt:25.4,fonte:'página do PDF · UserUnit 2',confirmar:'estreita'});
|
||||
const rendered=await evaluate(`rasterizarPdf(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))},50.8,25.4).then(r=>({ok:!!r.tela,error:r.erro||null}))`);
|
||||
assert.deepEqual(rendered,{ok:true,error:null});
|
||||
// A PDF sheet gets the same ink map, rendered in strips: a blank page is all transparent.
|
||||
@@ -475,13 +544,17 @@ try{
|
||||
assert.equal(beyondSpec.rejected,true);assert.match(beyondSpec.reason,/508 cm/);
|
||||
const broken=await evaluate(`medirFolha(new File(['broken'],'broken.pdf',{type:'application/pdf'}))`);
|
||||
assert.equal(broken.rejected,true);
|
||||
// A PDF page is a known real width too: 30 cm is refused, 57 cm is accepted.
|
||||
// A PDF page is a known real width too: 30 cm enters narrow with confirmation,
|
||||
// 57 cm enters as the film, and 60 cm does not fit.
|
||||
const pdfWide=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 850.394 360]'}))})`);
|
||||
assert.equal(!!pdfWide.larguraErrada,true);
|
||||
assert.ok(Math.abs(pdfWide.larguraErrada.cm-30)<0.01);
|
||||
assert.equal(pdfWide.larguraErrada.dpi,null);
|
||||
assert.equal(pdfWide.confirmar,'estreita');
|
||||
assert.ok(Math.abs(pdfWide.larg-30)<0.01);
|
||||
const pdfTooWide=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 1700.787 360]'}))})`);
|
||||
assert.equal(!!pdfTooWide.largaDemais,true);
|
||||
assert.ok(Math.abs(pdfTooWide.largaDemais.cm-60)<0.01);
|
||||
const pdfOk=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 1615.748 360]'}))})`);
|
||||
assert.ok(Math.abs(pdfOk.larg-57)<0.01);
|
||||
assert.equal(pdfOk.confirmar,undefined);
|
||||
await click('#bVoltar');await click('[data-modo="file"]');
|
||||
await evaluate(`sel([${pdfFile(pdfData({pages:2}),'two-pages.pdf')}])`);
|
||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'multipage PDF refusal');
|
||||
|
||||
Reference in New Issue
Block a user