fix: the server refuses stacked pieces and files laid out at other proportions, and never cuts a strip with ink
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
The price came from the layout the browser sent, checked only in part: - Pieces on top of each other passed: 100 copies stacked in one place bill 10 cm and print over each other. The layout validator now refuses any overlap. - A file laid out at proportions it does not have (a 5 m sheet sent as 10 cm) was found only by the print file, after payment. The quote now checks each raster file's proportions from the bytes it already reads. - The empty strips the Site cuts from a ready sheet were cut on its word. The print file now reads them: a strip with ink sends the item to hand preparation with the reason, instead of printing the art cut off. Test fixtures that laid real images out at impossible proportions now keep the image's own. 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.models import QuoteRequest
|
||||
from .. import quote_review
|
||||
from ..grade_check import Files, mismatch, resolution_issue, source_dpi
|
||||
from ..grade_check import Files, mismatch, proportion_issue, resolution_issue, source_dpi
|
||||
from ..runtime import freight, payment, quote_view, require_delivery_available, storage, upload_row
|
||||
from ..scanning import require_clean
|
||||
|
||||
@@ -79,7 +79,7 @@ def create_quote(body: QuoteRequest, session_id=Depends(owner)):
|
||||
dpis.append(dpi)
|
||||
if dpis:
|
||||
draft_item['source_dpi'] = round(min(dpis))
|
||||
issue = resolution_issue(files, draft['items'], rows)
|
||||
issue = proportion_issue(files, draft['items'], rows) or resolution_issue(files, draft['items'], rows)
|
||||
if issue:
|
||||
raise HTTPException(422, issue)
|
||||
note = mismatch(files, draft['items'], rows) if reason is None else None
|
||||
|
||||
@@ -291,6 +291,17 @@ class Item(StrictModel):
|
||||
raise ValueError('Finished sheets must retain their original orientation')
|
||||
if placed != expected:
|
||||
raise ValueError('Production layout does not cover every source copy')
|
||||
# No piece on top of another: stacked pieces bill less film than they
|
||||
# print on, and print over each other. Swept down the film, so only
|
||||
# the pieces still open at each row are compared.
|
||||
boxes = sorted((p.y_cm, p.y_cm + p.length_cm, p.x_cm, p.x_cm + p.width_cm)
|
||||
for p in self.production.placements)
|
||||
open_boxes = []
|
||||
for top, bottom, left, right in boxes:
|
||||
open_boxes = [b for b in open_boxes if b[0] > top + tolerance]
|
||||
if any(l < right - tolerance and left < r - tolerance for _, l, r in open_boxes):
|
||||
raise ValueError('Duas peças da montagem ficaram uma sobre a outra. Monte o pedido de novo.')
|
||||
open_boxes.append((bottom, left, right))
|
||||
if self.quality_status == 'warning' and not self.quality_acknowledged:
|
||||
raise ValueError('Resolution warning must be acknowledged')
|
||||
return self
|
||||
|
||||
@@ -227,6 +227,35 @@ def resolution_issue(files, items, rows):
|
||||
return None
|
||||
|
||||
|
||||
def proportion_issue(files, items, rows):
|
||||
"""Why a cart's layout cannot be priced, or None: a raster file laid out
|
||||
at proportions it does not have (a 5 m sheet sent as 10 cm, say). The
|
||||
print file refuses the same thing (app/printfile.py check_layout), but
|
||||
only after payment; here it is refused before. A PDF, or a file whose
|
||||
size the first bytes do not tell, is left to that later check."""
|
||||
from .printfile import ASPECT_TOLERANCE
|
||||
for index, item in enumerate(items, 1):
|
||||
for number, source in enumerate(item['production']['sources'], 1):
|
||||
row = rows.get(str(source['upload_id']))
|
||||
if not row or row['name'].lower().endswith('.pdf'):
|
||||
continue
|
||||
size = image_size(files.head(row))
|
||||
if not size or not all(size):
|
||||
continue
|
||||
width_px, height_px = size
|
||||
if source.get('rotation_degrees') in (90, 270):
|
||||
width_px, height_px = height_px, width_px
|
||||
# A ready sheet's empty strips were cut from its length: the file
|
||||
# is the length plus both strips (app/core/models.py).
|
||||
length = (float(source['length_cm']) + float(source.get('trim_top_cm') or 0)
|
||||
+ float(source.get('trim_bottom_cm') or 0))
|
||||
drift = abs((width_px / height_px) / (float(source['width_cm']) / length) - 1)
|
||||
if drift > ASPECT_TOLERANCE:
|
||||
return (f'Item {index}: o arquivo {number} foi montado com {source["width_cm"]} × '
|
||||
f'{source["length_cm"]} cm, que não são as proporções dele. Monte o pedido de novo.')
|
||||
return None
|
||||
|
||||
|
||||
def mismatch(files, items, rows):
|
||||
"""Why a cart's grades cannot be approved at checkout, or None."""
|
||||
for item in items:
|
||||
|
||||
@@ -48,6 +48,8 @@ PART_CM = Decimal(os.environ.get('PRINT_PART_CM', '1000'))
|
||||
# A cut through artwork only when no gap between pieces is this close to the limit.
|
||||
CUT_SEARCH_CM = Decimal('200')
|
||||
BAND_ROWS = 512
|
||||
# A pixel above this alpha takes ink (web/site-sheet.js ALFA_TINTA).
|
||||
INK_ALPHA = 10
|
||||
# Above this a source is read band by band instead of decoded whole.
|
||||
STREAM_ABOVE_PIXELS = 40_000_000
|
||||
FOOTER_TEXT_CM = 1.1
|
||||
@@ -268,9 +270,44 @@ class Source:
|
||||
top, bottom = round(height * top_cm / full_cm), round(height * bottom_cm / full_cm)
|
||||
if top + bottom >= height:
|
||||
raise Unsupported(f'"{self.name}": o corte das faixas vazias tiraria o arquivo inteiro')
|
||||
self._require_clear(top, bottom)
|
||||
self.cut = (top, bottom)
|
||||
self.size = (width, height - top - bottom)
|
||||
|
||||
def _require_clear(self, top, bottom):
|
||||
"""The strips the Site measured as empty must be: cut on a measure the
|
||||
file does not bear out, artwork would leave the print unseen. A pixel
|
||||
takes ink above INK_ALPHA, as the Site counts it. Not clear, or too
|
||||
big to read here: the item goes to hand preparation, with the reason."""
|
||||
width, height = self.size
|
||||
where = lambda first: 'do começo' if first else 'do fim'
|
||||
|
||||
def check(band, offset):
|
||||
for start, stop, first in ((0, top, True), (height - bottom, height, False)):
|
||||
a, b = max(start, offset), min(stop, offset + band.height)
|
||||
if a < b and rgba(band.crop((0, a - offset, band.width, b - offset))).getchannel('A').getextrema()[1] > INK_ALPHA:
|
||||
raise Unsupported(f'"{self.name}": a faixa que o site cortou {where(first)} do arquivo tem arte. '
|
||||
'Confira o arquivo e prepare a folha à mão')
|
||||
|
||||
if self.streamable:
|
||||
reader = PngRows(self.path)
|
||||
try:
|
||||
done = 0
|
||||
# Read in order to the end of the bottom strip (or of the top one).
|
||||
while done < (height if bottom else top):
|
||||
band = reader.band(BAND_ROWS)
|
||||
if done < top or done + band.height > height - bottom:
|
||||
check(band, done)
|
||||
done += band.height
|
||||
finally:
|
||||
reader.close()
|
||||
return
|
||||
if width * height > MAX_DECODED_PIXELS:
|
||||
raise Unsupported(f'"{self.name}" é grande demais para conferir as faixas cortadas; prepare a folha à mão')
|
||||
with Image.open(self.path) as image:
|
||||
image = ImageOps.exif_transpose(image) if self.orientation != 1 else image
|
||||
check(image, 0)
|
||||
|
||||
def decoded(self, width, height):
|
||||
"""The whole file at (width, height) px, upright, RGBA."""
|
||||
if self.pdf:
|
||||
|
||||
Reference in New Issue
Block a user