feat: a 57 cm ready sheet whose real width is not 57 cm opens a pop-up and is not accepted (Marcus, 2026-12-01)
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 2m34s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Has been skipped
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 2m34s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Has been skipped
Order #177: a 35,8 cm sheet at 300 DPI was stretched to the film's 57 cm, the v0 Site rule for a ready sheet image. Marcus: a pop-up on upload, and neither a narrower nor a wider sheet is accepted. The real width is known for a PNG whose pHYs records 200 DPI or more (the A1 threshold) and for a PDF page; tolerance 0,1 cm (6732 px at 300 DPI is 56,998 cm). Arquivo por metro and Premium only. UV, a PNG without pHYs or under 200 DPI, and every existing order and approved cart are unchanged. Site: medirFolha refuses it, the sheet leaves the list (its upload stops), and #larguraDlg lists each refused file with its width and DPI; Entendi or Escape closes it and focus returns to the upload area; the thin-stroke dialog waits while it is open. Server: sheet_width_issue refuses the same cart at checkout (POST /api/quotes, 422), so a reorder or an edited page cannot get round it. Contract: output/revisao/contrato-largura-folha.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ from ..core import db
|
|||||||
from ..core.auth import owner
|
from ..core.auth import owner
|
||||||
from ..core.models import QuoteRequest
|
from ..core.models import QuoteRequest
|
||||||
from .. import quote_review
|
from .. import quote_review
|
||||||
from ..grade_check import Files, mismatch, proportion_issue, resolution_issue, source_dpi
|
from ..grade_check import Files, mismatch, proportion_issue, resolution_issue, sheet_width_issue, source_dpi
|
||||||
from ..runtime import freight, payment, quote_view, require_delivery_available, storage, upload_row
|
from ..runtime import freight, payment, quote_view, require_delivery_available, storage, upload_row
|
||||||
from ..scanning import require_clean
|
from ..scanning import require_clean
|
||||||
|
|
||||||
@@ -79,7 +79,8 @@ def create_quote(body: QuoteRequest, session_id=Depends(owner)):
|
|||||||
dpis.append(dpi)
|
dpis.append(dpi)
|
||||||
if dpis:
|
if dpis:
|
||||||
draft_item['source_dpi'] = round(min(dpis))
|
draft_item['source_dpi'] = round(min(dpis))
|
||||||
issue = proportion_issue(files, draft['items'], rows) or resolution_issue(files, draft['items'], rows)
|
issue = (proportion_issue(files, draft['items'], rows) or sheet_width_issue(files, draft['items'], rows)
|
||||||
|
or resolution_issue(files, draft['items'], rows))
|
||||||
if issue:
|
if issue:
|
||||||
raise HTTPException(422, issue)
|
raise HTTPException(422, issue)
|
||||||
note = mismatch(files, draft['items'], rows) if reason is None else None
|
note = mismatch(files, draft['items'], rows) if reason is None else None
|
||||||
|
|||||||
@@ -324,6 +324,87 @@ def proportion_issue(files, items, rows):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
# A ready sheet in the 57 cm textile products must be 57 cm wide where its real
|
||||||
|
# width is known (Marcus, 2026-12-01: a pop-up on upload and refused, narrower
|
||||||
|
# or wider). Known means a PNG whose pHYs records TRUSTED_DPI or more (the A1
|
||||||
|
# threshold, rodada 5) or a PDF page; anything else keeps the v0 rule (the
|
||||||
|
# image stretched to the film). output/revisao/contrato-largura-folha.md;
|
||||||
|
# the Site has the same numbers (web/site-config.js LARGURA_EXATA).
|
||||||
|
EXACT_SHEET_WIDTH_CM = {'file': 57.0, 'premium': 57.0}
|
||||||
|
SHEET_WIDTH_TOLERANCE_CM = 0.1
|
||||||
|
TRUSTED_DPI = 200
|
||||||
|
|
||||||
|
|
||||||
|
def png_saved_dpi(head):
|
||||||
|
"""The DPI a PNG records in its pHYs chunk, rounded as the Site rounds it
|
||||||
|
(web/site-pdf.js dpiSalvoPng: Math.round(pixels per metre × 0.0254)), or
|
||||||
|
None: not a PNG, no pHYs before the first IDAT, a unit that is not the
|
||||||
|
metre, X and Y that differ, or a chunk cut off by the head's end."""
|
||||||
|
if head[:8] != b'\x89PNG\r\n\x1a\n':
|
||||||
|
return None
|
||||||
|
offset = 8
|
||||||
|
while offset + 8 <= len(head):
|
||||||
|
length = struct.unpack('>I', head[offset:offset + 4])[0]
|
||||||
|
kind = head[offset + 4:offset + 8]
|
||||||
|
if kind in (b'IDAT', b'IEND'):
|
||||||
|
return None
|
||||||
|
end = offset + 8 + length
|
||||||
|
if end + 4 > len(head):
|
||||||
|
return None # chunk cut off by the head's end
|
||||||
|
if kind == b'pHYs':
|
||||||
|
if length < 9:
|
||||||
|
return None
|
||||||
|
ppm_x, ppm_y, unit = struct.unpack('>IIB', head[offset + 8:offset + 17])
|
||||||
|
if unit == 1 and ppm_x == ppm_y > 0:
|
||||||
|
return js_round(ppm_x * 0.0254)
|
||||||
|
return None
|
||||||
|
offset = end + 4
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def sheet_width_issue(files, items, rows):
|
||||||
|
"""Why a cart cannot be approved: a ready sheet of a 57 cm textile item
|
||||||
|
(EXACT_SHEET_WIDTH_CM) whose real width is off by more than
|
||||||
|
SHEET_WIDTH_TOLERANCE_CM, or None. A PNG's real width is its pixels ÷ its
|
||||||
|
pHYs DPI × 2.54 when that DPI is TRUSTED_DPI or more; a PDF's is the
|
||||||
|
source's width_cm (the page the Site measured). Anything else passes."""
|
||||||
|
for index, item in enumerate(items, 1):
|
||||||
|
mode = item.get('mode')
|
||||||
|
if mode not in EXACT_SHEET_WIDTH_CM:
|
||||||
|
continue
|
||||||
|
expected = EXACT_SHEET_WIDTH_CM[mode]
|
||||||
|
expected_text = f'{expected:g}'
|
||||||
|
for number, source in enumerate(item['production']['sources'], 1):
|
||||||
|
if source.get('kind') != 'sheet':
|
||||||
|
continue
|
||||||
|
row = rows.get(str(source['upload_id']))
|
||||||
|
if not row:
|
||||||
|
continue
|
||||||
|
name = row['name'].lower()
|
||||||
|
if name.endswith('.pdf'):
|
||||||
|
cm = float(source['width_cm'])
|
||||||
|
dpi = None
|
||||||
|
elif name.endswith('.png'):
|
||||||
|
dpi = png_saved_dpi(files.head(row))
|
||||||
|
if dpi is None or dpi < TRUSTED_DPI:
|
||||||
|
continue
|
||||||
|
size = image_size(files.head(row))
|
||||||
|
if not size or not all(size):
|
||||||
|
continue
|
||||||
|
cm = size[0] / dpi * 2.54
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
if abs(cm - expected) <= SHEET_WIDTH_TOLERANCE_CM:
|
||||||
|
continue
|
||||||
|
cm_text = f'{cm:.1f}'.replace('.', ',')
|
||||||
|
if dpi is None:
|
||||||
|
return (f'Item {index}: a folha {number} tem {cm_text} cm de largura. '
|
||||||
|
f'A folha montada precisa ter {expected_text} cm.')
|
||||||
|
return (f'Item {index}: a folha {number} tem {cm_text} cm de largura ({dpi} DPI). '
|
||||||
|
f'A folha montada precisa ter {expected_text} cm.')
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def mismatch(files, items, rows):
|
def mismatch(files, items, rows):
|
||||||
"""Why a cart's grades cannot be approved at checkout, or None."""
|
"""Why a cart's grades cannot be approved at checkout, or None."""
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|||||||
@@ -229,6 +229,38 @@ try{
|
|||||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'tall sheet refused');
|
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'tall sheet refused');
|
||||||
assert.equal(await evaluate(`folhas[0].measurementError.includes('PNG alto')`),true);
|
assert.equal(await evaluate(`folhas[0].measurementError.includes('PNG alto')`),true);
|
||||||
await evaluate(`folhas=[];pintaFolha()`);
|
await evaluate(`folhas=[];pintaFolha()`);
|
||||||
|
// 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]);
|
||||||
|
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'});
|
||||||
|
Object.defineProperty(f,'size',{value:900*1048576});
|
||||||
|
return sel([f]);}`);
|
||||||
|
await evaluate(`pngLargura(4227,11811)`);
|
||||||
|
await waitFor(()=>evaluate(`folhas.length===0 && $('larguraDlg').open`),'wrong-width sheet opens dialog');
|
||||||
|
assert.deepEqual(await evaluate(`({itens:$('larguraLista').children.length,
|
||||||
|
texto:$('larguraLista').textContent})`),
|
||||||
|
{itens:1,texto:'folha-larga.png: 35,8 cm (300 DPI)'});
|
||||||
|
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.
|
||||||
|
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 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);
|
||||||
|
await evaluate(`folhas=[];pintaFolha()`);
|
||||||
await evaluate(`pickTipo('avulsa')`);
|
await evaluate(`pickTipo('avulsa')`);
|
||||||
assert.equal(await evaluate('modo'),'avulsa');
|
assert.equal(await evaluate('modo'),'avulsa');
|
||||||
// JPG has no transparency: refused in loose artwork as in a sheet (Dropstar,
|
// JPG has no transparency: refused in loose artwork as in a sheet (Dropstar,
|
||||||
@@ -426,7 +458,10 @@ try{
|
|||||||
// Parsed geometry honors inherited MediaBox, CropBox, rotation and UserUnit.
|
// Parsed geometry honors inherited MediaBox, CropBox, rotation and UserUnit.
|
||||||
// Extra pages and unreadable PDFs must never fall through to manual pricing.
|
// 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'})`;
|
const pdfFile=(data,name='sheet.pdf')=>`new File([Uint8Array.from(atob(${data}),c=>c.charCodeAt(0))],${JSON.stringify(name)},{type:'application/pdf'})`;
|
||||||
const rotated=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))})`);
|
// 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'});
|
assert.deepEqual(rotated,{larg:50.8,alt:25.4,fonte:'página do PDF · UserUnit 2'});
|
||||||
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}))`);
|
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});
|
assert.deepEqual(rendered,{ok:true,error:null});
|
||||||
@@ -440,6 +475,13 @@ try{
|
|||||||
assert.equal(beyondSpec.rejected,true);assert.match(beyondSpec.reason,/508 cm/);
|
assert.equal(beyondSpec.rejected,true);assert.match(beyondSpec.reason,/508 cm/);
|
||||||
const broken=await evaluate(`medirFolha(new File(['broken'],'broken.pdf',{type:'application/pdf'}))`);
|
const broken=await evaluate(`medirFolha(new File(['broken'],'broken.pdf',{type:'application/pdf'}))`);
|
||||||
assert.equal(broken.rejected,true);
|
assert.equal(broken.rejected,true);
|
||||||
|
// A PDF page is a known real width too: 30 cm is refused, 57 cm is accepted.
|
||||||
|
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);
|
||||||
|
const pdfOk=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 1615.748 360]'}))})`);
|
||||||
|
assert.ok(Math.abs(pdfOk.larg-57)<0.01);
|
||||||
await click('#bVoltar');await click('[data-modo="file"]');
|
await click('#bVoltar');await click('[data-modo="file"]');
|
||||||
await evaluate(`sel([${pdfFile(pdfData({pages:2}),'two-pages.pdf')}])`);
|
await evaluate(`sel([${pdfFile(pdfData({pages:2}),'two-pages.pdf')}])`);
|
||||||
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'multipage PDF refusal');
|
await waitFor(()=>evaluate(`folhas.length===1 && !!folhas[0].measurementError`),'multipage PDF refusal');
|
||||||
@@ -448,7 +490,8 @@ try{
|
|||||||
assert.match(await evaluate(`$('lista').textContent`),/não pode ser orçado/);
|
assert.match(await evaluate(`$('lista').textContent`),/não pode ser orçado/);
|
||||||
// A ".cdr" that is a PDF (D-13) is renamed and measured as a PDF, not handled by hand.
|
// A ".cdr" that is a PDF (D-13) is renamed and measured as a PDF, not handled by hand.
|
||||||
await click('#bVoltar');await click('[data-modo="file"]');
|
await click('#bVoltar');await click('[data-modo="file"]');
|
||||||
await evaluate(`sel([${pdfFile(pdfData(),'folha.cdr')}])`);
|
// A 57 cm page: the ready-sheet width rule passes it, so this checks only the renaming.
|
||||||
|
await evaluate(`sel([${pdfFile(pdfData({media:'[0 0 1615.748 360]'}),'folha.cdr')}])`);
|
||||||
// Measured, and its ink check finished: a check still running repaints the list after the mode below changes.
|
// Measured, and its ink check finished: a check still running repaints the list after the mode below changes.
|
||||||
await waitFor(()=>evaluate(`folhas.length===1 && !!(folhas[0].med || folhas[0].measurementError) && folhas[0].pct==null`),'renamed PDF measured');
|
await waitFor(()=>evaluate(`folhas.length===1 && !!(folhas[0].med || folhas[0].measurementError) && folhas[0].pct==null`),'renamed PDF measured');
|
||||||
assert.deepEqual(await evaluate(`({name:folhas[0].f.name,measured:!!folhas[0].med,manual:folhaManual()})`),
|
assert.deepEqual(await evaluate(`({name:folhas[0].f.name,measured:!!folhas[0].med,manual:folhaManual()})`),
|
||||||
|
|||||||
@@ -242,5 +242,68 @@ class ProportionTests(unittest.TestCase):
|
|||||||
self.assertIsNone(grade_check.proportion_issue(files, items, rows))
|
self.assertIsNone(grade_check.proportion_issue(files, items, rows))
|
||||||
|
|
||||||
|
|
||||||
|
class SheetWidthTests(unittest.TestCase):
|
||||||
|
"""A 57 cm ready sheet must really be 57 cm wide where the file tells
|
||||||
|
(contrato-largura-folha.md), or the cart is refused."""
|
||||||
|
|
||||||
|
def cart(self, mode, name, width_cm=57):
|
||||||
|
source = {'upload_id': name, 'kind': 'sheet', 'width_cm': width_cm}
|
||||||
|
return [{'mode': mode, 'production': {'sources': [source]}}], {name: {'name': name}}
|
||||||
|
|
||||||
|
def test_a_narrow_png_is_refused(self):
|
||||||
|
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||||
|
items, rows = self.cart('file', 'sheet.png')
|
||||||
|
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||||
|
self.assertIn('35,8 cm', issue)
|
||||||
|
self.assertIn('300 DPI', issue)
|
||||||
|
|
||||||
|
def test_a_wide_png_is_refused(self):
|
||||||
|
files = FakeFiles({'sheet.png': encoded('PNG', (7200, 100), dpi=(300, 300))})
|
||||||
|
items, rows = self.cart('file', 'sheet.png')
|
||||||
|
self.assertIn('61,0 cm', grade_check.sheet_width_issue(files, items, rows))
|
||||||
|
|
||||||
|
def test_sheet_width_rounding_boundaries(self):
|
||||||
|
for width_px, refused in ((6732, False), (6721, False), (6720, True)):
|
||||||
|
files = FakeFiles({'sheet.png': encoded('PNG', (width_px, 100), dpi=(300, 300))})
|
||||||
|
items, rows = self.cart('file', 'sheet.png')
|
||||||
|
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||||
|
if refused:
|
||||||
|
self.assertIn('56,9 cm', issue)
|
||||||
|
else:
|
||||||
|
self.assertIsNone(issue, width_px)
|
||||||
|
|
||||||
|
def test_png_under_trusted_dpi_passes(self):
|
||||||
|
for options in ({}, {'dpi': (96, 96)}, {'dpi': (150, 150)}):
|
||||||
|
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), **options)})
|
||||||
|
items, rows = self.cart('file', 'sheet.png')
|
||||||
|
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows), options)
|
||||||
|
|
||||||
|
def test_only_the_57_cm_modes_are_checked(self):
|
||||||
|
files = FakeFiles({'sheet.png': encoded('PNG', (4227, 100), dpi=(300, 300))})
|
||||||
|
items, rows = self.cart('premium', 'sheet.png')
|
||||||
|
self.assertIn('35,8 cm', grade_check.sheet_width_issue(files, items, rows))
|
||||||
|
for mode in ('uvfile', 'avulsa'):
|
||||||
|
items, rows = self.cart(mode, 'sheet.png')
|
||||||
|
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows), mode)
|
||||||
|
|
||||||
|
def test_a_pdf_width_is_checked(self):
|
||||||
|
files = FakeFiles({})
|
||||||
|
items, rows = self.cart('file', 'sheet.pdf', width_cm=30)
|
||||||
|
issue = grade_check.sheet_width_issue(files, items, rows)
|
||||||
|
self.assertIn('30,0 cm', issue)
|
||||||
|
self.assertNotIn('DPI', issue)
|
||||||
|
for width_cm in (57, '56.95'):
|
||||||
|
items, rows = self.cart('file', 'sheet.pdf', width_cm=width_cm)
|
||||||
|
self.assertIsNone(grade_check.sheet_width_issue(files, items, rows), width_cm)
|
||||||
|
|
||||||
|
def test_png_saved_dpi(self):
|
||||||
|
head = encoded('PNG', (4227, 100), dpi=(300, 300))
|
||||||
|
self.assertEqual(grade_check.png_saved_dpi(head), 300)
|
||||||
|
self.assertIsNone(grade_check.png_saved_dpi(encoded('PNG', (4227, 100))))
|
||||||
|
self.assertIsNone(grade_check.png_saved_dpi(b'not a png at all'))
|
||||||
|
cut = head.index(b'pHYs') + 8 # four of the pHYs data bytes
|
||||||
|
self.assertIsNone(grade_check.png_saved_dpi(head[:cut]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -971,6 +971,14 @@ h2 em{font-style:normal;color:var(--laranja)}
|
|||||||
<div class="mistaBot"><button type="button" class="ec-go" id="linhaFim">Finalizar este pedido</button><button type="button" id="linhaTroca">Trocar o carrinho por este item</button></div>
|
<div class="mistaBot"><button type="button" class="ec-go" id="linhaFim">Finalizar este pedido</button><button type="button" id="linhaTroca">Trocar o carrinho por este item</button></div>
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
<dialog class="ampliaDlg mistaDlg" id="larguraDlg" aria-labelledby="larguraTit">
|
||||||
|
<div class="ampliaCab"><b id="larguraTit">A folha precisa ter 57 cm de largura</b></div>
|
||||||
|
<div class="mistaCorpo">
|
||||||
|
<ul id="larguraLista"></ul>
|
||||||
|
<p>Ajuste a largura da folha no seu programa para 57 cm e envie de novo.</p>
|
||||||
|
<div class="mistaBot"><button type="button" class="ec-go" id="larguraOk">Entendi</button></div>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
<dialog class="ampliaDlg" id="ampliaDlg" aria-labelledby="ampliaTit">
|
<dialog class="ampliaDlg" id="ampliaDlg" aria-labelledby="ampliaTit">
|
||||||
<div class="ampliaCab"><b id="ampliaTit">Sua folha</b>
|
<div class="ampliaCab"><b id="ampliaTit">Sua folha</b>
|
||||||
<button type="button" id="ampliaFecha" aria-label="Fechar"><svg class="ic" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button></div>
|
<button type="button" id="ampliaFecha" aria-label="Fechar"><svg class="ic" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button></div>
|
||||||
|
|||||||
@@ -114,6 +114,14 @@ const ACEITA={
|
|||||||
};
|
};
|
||||||
const MEDE=/[.](png|jpe?g|webp|gif|bmp|pdf)$/i;
|
const MEDE=/[.](png|jpe?g|webp|gif|bmp|pdf)$/i;
|
||||||
const DPI_RECUSA=96, DPI_AVISA=200; // régua aprovada pela Dropstar · 05/11/2026
|
const DPI_RECUSA=96, DPI_AVISA=200; // régua aprovada pela Dropstar · 05/11/2026
|
||||||
|
// A folha pronta dos produtos têxteis de 57 cm tem de ter 57 cm de largura
|
||||||
|
// quando a largura real é conhecida: abre um aviso e não entra (Marcus,
|
||||||
|
// 01/12). Conhecida é um PNG que grava DPI_TAMANHO_REAL ou mais (o limite do
|
||||||
|
// A1, rodada 5) ou a página de um PDF; o resto segue a regra da versão 0
|
||||||
|
// (esticada até o filme). output/revisao/contrato-largura-folha.md.
|
||||||
|
const LARGURA_EXATA={file:57, premium:57};
|
||||||
|
const LARGURA_TOLERANCIA_CM=0.1;
|
||||||
|
const DPI_TAMANHO_REAL=200;
|
||||||
// A especificação do PDF limita a página a 14.400 unidades — 200 pol, 508 cm.
|
// A especificação do PDF limita a página a 14.400 unidades — 200 pol, 508 cm.
|
||||||
// Passar disso só é válido com UserUnit (PDF 1.6+), que a maioria dos programas
|
// Passar disso só é válido com UserUnit (PDF 1.6+), que a maioria dos programas
|
||||||
// não escreve: o arquivo sai fora do padrão e só o gerador lê direito.
|
// não escreve: o arquivo sai fora do padrão e só o gerador lê direito.
|
||||||
|
|||||||
@@ -358,8 +358,17 @@ function medirFolha(file){
|
|||||||
return new Promise(res=>{
|
return new Promise(res=>{
|
||||||
const nome=(file.name||'').toLowerCase();
|
const nome=(file.name||'').toLowerCase();
|
||||||
if(/\.png$/.test(nome)){
|
if(/\.png$/.test(nome)){
|
||||||
dimensoesImagem(file).then(d=>{
|
dimensoesImagem(file).then(async d=>{
|
||||||
if(!d || !(d.w>0) || !(d.h>0)) return res({rejected:true,reason:'Não foi possível ler as dimensões do PNG. Exporte novamente.'});
|
if(!d || !(d.w>0) || !(d.h>0)) return res({rejected:true,reason:'Não foi possível ler as dimensões do PNG. Exporte novamente.'});
|
||||||
|
// Folha têxtil de 57 cm: se o PNG diz o DPI real, a largura tem de ser 57.
|
||||||
|
const exata=LARGURA_EXATA[modo];
|
||||||
|
if(exata!=null){
|
||||||
|
const dpi=await dpiSalvoPng(file);
|
||||||
|
if(dpi>=DPI_TAMANHO_REAL){
|
||||||
|
const cm=d.w/dpi*2.54;
|
||||||
|
if(Math.abs(cm-exata)>LARGURA_TOLERANCIA_CM) return res({larguraErrada:{cm, dpi}});
|
||||||
|
}
|
||||||
|
}
|
||||||
const L=larguraFilme(), measure={larg:L,alt:+(d.h/d.w*L).toFixed(1),
|
const L=larguraFilme(), measure={larg:L,alt:+(d.h/d.w*L).toFixed(1),
|
||||||
fonte:'dimensões do arquivo',dpiFolha:Math.round(d.w/(L/2.54)),px:d.w};
|
fonte:'dimensões do arquivo',dpiFolha:Math.round(d.w/(L/2.54)),px:d.w};
|
||||||
if(d.h>32767 || file.size>GRANDE_BYTES) return res({...measure,grande:true,tall:d.h>32767});
|
if(d.h>32767 || file.size>GRANDE_BYTES) return res({...measure,grande:true,tall:d.h>32767});
|
||||||
@@ -419,6 +428,10 @@ function medirFolha(file){
|
|||||||
const w=vp.width*unit*PT_CM, h=vp.height*unit*PT_CM;
|
const w=vp.width*unit*PT_CM, h=vp.height*unit*PT_CM;
|
||||||
if(!Number.isFinite(w) || !Number.isFinite(h) || w<=0 || h<=0 || h>6000)
|
if(!Number.isFinite(w) || !Number.isFinite(h) || w<=0 || h<=0 || h>6000)
|
||||||
return {rejected:true, reason:'Esta página é grande demais. Divida a folha em partes menores.'};
|
return {rejected:true, reason:'Esta página é grande demais. Divida a folha em partes menores.'};
|
||||||
|
// A página do PDF já diz a largura real: fora de 57 cm, recusa.
|
||||||
|
const exata=LARGURA_EXATA[modo];
|
||||||
|
if(exata!=null && Math.abs(w-exata)>LARGURA_TOLERANCIA_CM)
|
||||||
|
return {larguraErrada:{cm:w, dpi:null}};
|
||||||
// Keep precise geometry for the fit and quote; the UI rounds only
|
// Keep precise geometry for the fit and quote; the UI rounds only
|
||||||
// when displaying dimensions.
|
// when displaying dimensions.
|
||||||
return {larg:+w.toFixed(3), alt:+h.toFixed(3),
|
return {larg:+w.toFixed(3), alt:+h.toFixed(3),
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const TEXTO_MISTA={
|
|||||||
// avulsa: imprimir assim mesmo (C1), ou trocar o arquivo por dois.
|
// avulsa: imprimir assim mesmo (C1), ou trocar o arquivo por dois.
|
||||||
function perguntaMista(){
|
function perguntaMista(){
|
||||||
const dlg=$('mistaDlg');
|
const dlg=$('mistaDlg');
|
||||||
if(!dlg || dlg.open) return;
|
if(!dlg || dlg.open || $('larguraDlg')?.open) return;
|
||||||
const lista=ehFolha()?folhas:artes;
|
const lista=ehFolha()?folhas:artes;
|
||||||
const x=lista.find(y=>!y.mistaVista && mista(tracoDoArquivo(y)));
|
const x=lista.find(y=>!y.mistaVista && mista(tracoDoArquivo(y)));
|
||||||
if(!x) return;
|
if(!x) return;
|
||||||
|
|||||||
@@ -48,6 +48,19 @@ function recusa(lista){
|
|||||||
: '<b>'+exts+' não entra aqui.</b> Artes avulsas só aceitam PNG com '+
|
: '<b>'+exts+' não entra aqui.</b> Artes avulsas só aceitam PNG com '+
|
||||||
'fundo transparente. Para CDR, AI ou PSD, exporte em PNG ou use <b>Arquivo por metro</b>.';
|
'fundo transparente. Para CDR, AI ou PSD, exporte em PNG ou use <b>Arquivo por metro</b>.';
|
||||||
}
|
}
|
||||||
|
// Folha de 57 cm com largura real conhecida e diferente: sai da lista e o
|
||||||
|
// diálogo junta os arquivos, um por linha, até o cliente fechar.
|
||||||
|
function recusaLargura(nome, {cm, dpi}){
|
||||||
|
const dlg=$('larguraDlg'); if(!dlg) return;
|
||||||
|
const lista=$('larguraLista');
|
||||||
|
const li=document.createElement('li');
|
||||||
|
li.textContent=nome+': '+n1(cm)+' cm'+(dpi==null?'':' ('+dpi+' DPI)');
|
||||||
|
lista.appendChild(li);
|
||||||
|
const ok=$('larguraOk');
|
||||||
|
ok.onclick=()=>dlg.close();
|
||||||
|
dlg.onclose=()=>{ lista.textContent=''; const z=$('zona'); if(z) z.focus(); agendaAvaliacao(); };
|
||||||
|
if(!dlg.open){ dlg.showModal(); ok.focus(); }
|
||||||
|
}
|
||||||
const Z=$('zona'), I=$('inp');
|
const Z=$('zona'), I=$('inp');
|
||||||
Z.addEventListener('click',()=>I.click());
|
Z.addEventListener('click',()=>I.click());
|
||||||
Z.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){I.click();e.preventDefault();}});
|
Z.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){I.click();e.preventDefault();}});
|
||||||
@@ -196,6 +209,14 @@ async function sel(fs){
|
|||||||
if(md && md.rejected){
|
if(md && md.rejected){
|
||||||
x.measurementError=md.reason; x.pct=null; pintaFolha(); return;
|
x.measurementError=md.reason; x.pct=null; pintaFolha(); return;
|
||||||
}
|
}
|
||||||
|
if(md && md.larguraErrada){
|
||||||
|
if(folhas.includes(x)){
|
||||||
|
folhas=folhas.filter(y=>y!==x);
|
||||||
|
pintaFolha();
|
||||||
|
recusaLargura(x.f.name, md.larguraErrada);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(md && md.dpiFolha!=null && md.dpiFolha<DPI_RECUSA) return recusaFolha(x, md);
|
if(md && md.dpiFolha!=null && md.dpiFolha<DPI_RECUSA) return recusaFolha(x, md);
|
||||||
x.med=md; if(md) x.m=md.alt/100; x.pct=55; pintaFolha();
|
x.med=md; if(md) x.m=md.alt/100; x.pct=55; pintaFolha();
|
||||||
if(md && md.grande){
|
if(md && md.grande){
|
||||||
|
|||||||
Reference in New Issue
Block a user