From ac22f9a2f609e9325b4844712ffbfe076c073eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 28 Oct 2026 11:13:52 -0300 Subject: [PATCH] feat: the print file's footer line is about 1 cm tall (Dropstar, 2026-10-28) It was 18 pt, about 0,6 cm. Now 31 pt, shrunk only when the line would not fit the film's width (the 27 cm UV), measured with Helvetica's widths. Co-Authored-By: Claude Opus 5.5 --- app/printfile.py | 48 +++++++++++++++++++++++++++++++++-------- docs/CONTEXT.md | 6 +++++- tests/test_printfile.py | 15 +++++++++++-- 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/app/printfile.py b/app/printfile.py index 2229469..73acc85 100644 --- a/app/printfile.py +++ b/app/printfile.py @@ -401,36 +401,66 @@ def check_layout(item, sizes, vector=()): # the sheet is, so a sheet cut off or dropped in the room is still known. The band # is outside the billed length: the page grows by it and never covers artwork. FOOTER_CM = Decimal('1.5') -FOOTER_PT = 18 +# The line about 1 cm tall, from the top of a "d" to the bottom of a "p" +# (Dropstar, 2026-10-28; it was 18 pt, about 0,6 cm), smaller only when the +# line would not fit the film's width (the 27 cm UV). +FOOTER_PT = 31 FOOTER_FONTS = {'F1': 'Helvetica-Bold', 'F2': 'Helvetica'} +# Helvetica's widths (thousandths of the size), regular and bold, for the +# characters the line uses; anything else counts as wide. +_HELVETICA = dict(zip(' ,-./0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\xb7', + [278, 278, 333, 278, 278] + [556] * 10 + [278] + + [667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, + 722, 667, 944, 667, 667, 611] + + [556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, + 556, 500, 722, 500, 500, 500] + [278])) +_HELVETICA_BOLD = dict(zip(' ,-./0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\xb7', + [278, 278, 333, 278, 278] + [556] * 10 + [333] + + [722, 722, 722, 722, 667, 611, 778, 722, 278, 556, 722, 611, 833, 722, 778, 667, 778, 722, 667, 611, + 722, 667, 944, 667, 667, 611] + + [556, 611, 556, 611, 556, 333, 611, 611, 278, 278, 556, 278, 889, 611, 611, 611, 611, 389, 556, 333, + 611, 556, 778, 556, 556, 500] + [278])) + + +def text_width(text, bold=False): + """The width of `text` in Helvetica at size 1, in points.""" + widths = _HELVETICA_BOLD if bold else _HELVETICA + return sum(widths.get(ch, 1000) for ch in text) / 1000 # Dropstar's logo (sent 2026-10-23): black on transparent, so no white base is # printed around it. It takes the place of the brand's name at the line's start. FOOTER_LOGO = os.path.join(os.path.dirname(__file__), 'assets', 'logo-dropstar.png') FOOTER_LOGO_CM = 1.3 -def footer_commands(text, logo_size=None): +def footer_commands(text, logo_size=None, width_pt=57 * PT_PER_CM): """The footer's line, 0,5 cm from the left: the logo then the rest, or, - without a logo, the line's first part (the brand) in bold.""" + without a logo, the line's first part (the brand) in bold. It is + FOOTER_PT, or less when that would not fit `width_pt`, the film.""" brand, _, rest = text.partition(' · ') # A warning closing the line (ESPELHADO) goes in bold. rest, mark, _ = rest.rpartition(' · ESPELHADO') if rest.endswith(' · ESPELHADO') else (rest, '', '') def literal(value): raw = value.encode('cp1252', 'replace') return b'(' + raw.replace(b'\\', b'\\\\').replace(b'(', b'\\(').replace(b')', b'\\)') + b')' + def sized(room, line): + fit = room / max(sum(text_width(part, bold) for part, bold in line), 1e-9) + return int(min(FOOTER_PT, fit)) x = 0.5 * PT_PER_CM - y = (float(FOOTER_CM) * PT_PER_CM - FOOTER_PT * 0.7) / 2 if logo_size: height = FOOTER_LOGO_CM * PT_PER_CM width = height * logo_size[0] / logo_size[1] + start = x + width + 0.4 * PT_PER_CM + size = sized(width_pt - start - x, [(rest, False), (mark, True)]) + y = (float(FOOTER_CM) * PT_PER_CM - size * 0.7) / 2 bottom = (float(FOOTER_CM) * PT_PER_CM - height) / 2 return (b'q %s 0 0 %s %s %s cm /Logo Do Q\n' % (serialize(width), serialize(height), serialize(x), serialize(bottom)) + b'q 0 g BT /F2 %d Tf %s %s Td %s Tj /F1 %d Tf %s Tj ET Q\n' - % (FOOTER_PT, serialize(x + width + 0.4 * PT_PER_CM), serialize(y), literal(rest), - FOOTER_PT, literal(mark))) + % (size, serialize(start), serialize(y), literal(rest), size, literal(mark))) + middle = ' · ' + rest if rest else '' + size = sized(width_pt - 2 * x, [(brand, True), (middle, False), (mark, True)]) + y = (float(FOOTER_CM) * PT_PER_CM - size * 0.7) / 2 return (b'q 0 g BT /F1 %d Tf %s %s Td %s Tj /F2 %d Tf %s Tj /F1 %d Tf %s Tj ET Q\n' - % (FOOTER_PT, serialize(x), serialize(y), literal(brand), FOOTER_PT, literal(' · ' + rest if rest else ''), - FOOTER_PT, literal(mark))) + % (size, serialize(x), serialize(y), literal(brand), size, literal(middle), size, literal(mark))) def render(item, files, out, title, footer=None): @@ -503,7 +533,7 @@ def write_rasters(production, sources, out, title, width_pt, height_pt, unit, fo if logo: resources['XObject']['Logo'] = logo.embed(pdf) logo.close() - commands.append(footer_commands(footer, logo.size if logo else None)) + commands.append(footer_commands(footer, logo.size if logo else None, width_pt)) resources['Font'] = {key: {'Type': Name('Font'), 'Subtype': Name('Type1'), 'BaseFont': Name(font), 'Encoding': Name('WinAnsiEncoding')} for key, font in FOOTER_FONTS.items()} content = pdf.stream({'Filter': Name('FlateDecode')}, deflate(commands)) diff --git a/docs/CONTEXT.md b/docs/CONTEXT.md index 9b83304..0910896 100644 --- a/docs/CONTEXT.md +++ b/docs/CONTEXT.md @@ -404,7 +404,11 @@ pixels; every JPG) cannot be paid for; the preview circles each dot. PDFs over 150 MB and CDR/AI/PSD/TIFF are not checked. The generated print PDF ends in a 1,5 cm footer band below the layout, outside the billed length: "DROPSTAR · Pedido DTF- · Item 1/2 · date · billed metres" in black -Helvetica, after Dropstar's logo (app/assets). An original used whole as its +Helvetica, after Dropstar's logo (app/assets), about 1 cm tall (31 pt, Dropstar +2026-10-28; smaller only when it would not fit the 27 cm UV film). A sheet +longer than 5,08 m (PDF's page limit) is scaled with /UserUnit; CorelDRAW +ignores it and shows such a file at 1/UserUnit of its size (a 12,8 m sheet as +18,9 x 425 cm), while the page itself is right. An original used whole as its own print file (over 300 MB) has no footer. The print proof (app/proof.py): an order above 10 m, or one whose customer ticked "quero aprovar uma prova" at checkout (that one arrives marked Aguardando contato), cannot reach Finalizado diff --git a/tests/test_printfile.py b/tests/test_printfile.py index 1ae8891..304bc85 100644 --- a/tests/test_printfile.py +++ b/tests/test_printfile.py @@ -105,7 +105,7 @@ class PrintFileTests(unittest.TestCase): self.assertIn(b'/Logo ', pdf) self.assertIn(b'/SMask', pdf) self.assertNotIn(b'(DROPSTAR) Tj', content) - self.assertIn(b'/F2 18 Tf', content) + self.assertIn(b'/F2 31 Tf', content) self.assertIn('(Pedido DTF-7 · Item 1/2 · 21/10/2026 · 1,00 m) Tj'.encode('cp1252'), content) self.assertNotIn(b' re f', content) # no filled background # Without the logo file, the brand's name in bold. @@ -130,7 +130,18 @@ class PrintFileTests(unittest.TestCase): 'ordered_at': datetime(2026, 10, 23, 15, 0, tzinfo=timezone.utc)} line = footer(job, spec) self.assertEqual(line, 'DROPSTAR · Pedido DTF-7 · Item 2/2 · 23/10/2026 · 1,00 m · ESPELHADO') - self.assertIn(b'/F1 18 Tf ( \xb7 ESPELHADO) Tj', footer_commands(line, (100, 80))) + self.assertIn(b'/F1 31 Tf ( \xb7 ESPELHADO) Tj', footer_commands(line, (100, 80))) + # About 1 cm tall on the 57 cm film (Dropstar, 2026-10-28); on the 27 cm UV + # the line shrinks to fit the width instead of running off the film. + from app.printfile import PT_PER_CM, text_width + long_line = 'DROPSTAR · Pedido DTF-12345 · Item 10/12 · 28/10/2026 · 123,40 m · ESPELHADO' + uv = footer_commands(long_line, (100, 80), 27 * PT_PER_CM) + size = int(re.search(rb'/F2 (\d+) Tf', uv).group(1)) + self.assertLess(size, 31) + logo = 1.3 * 100 / 80 * PT_PER_CM + used = 0.5 * PT_PER_CM + logo + 0.4 * PT_PER_CM + size * ( + text_width('Pedido DTF-12345 · Item 10/12 · 28/10/2026 · 123,40 m') + text_width(' · ESPELHADO', True)) + self.assertLessEqual(used, 27 * PT_PER_CM - 0.5 * PT_PER_CM) self.assertNotIn(b'ESPELHADO', footer_commands(footer(job, item([placement(0, 0, 20, 10)], [source(20, 10)], 10)), (100, 80))) # The files start with the code the Kanban copies. self.assertEqual(file_prefix(7, 1), 'DTF-7-item-2')