feat: the print PDF footer starts with Dropstar's logo
All checks were successful
Build and deploy / Validate source (push) Successful in 15s
Build and deploy / Integration suite on a real stack (push) Successful in 4m25s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 1m49s

Dropstar sent the logo on 2026-10-23: black on transparent, so the room's
white-base profile prints nothing around it. It is drawn 1,3 cm high at
the start of the footer band, in place of the brand's name, followed by
"Pedido DTF-123 · Item 1/2 · date · metres". Without the file, the footer
falls back to the name in bold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-23 14:15:23 -03:00
parent 56e5462647
commit c21497d71b
4 changed files with 34 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

View File

@@ -403,16 +403,28 @@ def check_layout(item, sizes, vector=()):
FOOTER_CM = Decimal('1.5')
FOOTER_PT = 18
FOOTER_FONTS = {'F1': 'Helvetica-Bold', 'F2': 'Helvetica'}
# 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):
"""The footer's line, its first part (the brand) in bold, 0,5 cm from the left."""
def footer_commands(text, logo_size=None):
"""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."""
brand, _, rest = text.partition(' · ')
def literal(value):
raw = value.encode('cp1252', 'replace')
return b'(' + raw.replace(b'\\', b'\\\\').replace(b'(', b'\\(').replace(b')', b'\\)') + b')'
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]
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 ET Q\n'
% (FOOTER_PT, serialize(x + width + 0.4 * PT_PER_CM), serialize(y), literal(rest)))
return (b'q 0 g BT /F1 %d Tf %s %s Td %s Tj /F2 %d Tf %s Tj ET Q\n'
% (FOOTER_PT, serialize(x), serialize(y), literal(brand), FOOTER_PT, literal(' · ' + rest if rest else '')))
@@ -483,7 +495,11 @@ def write_rasters(production, sources, out, title, width_pt, height_pt, unit, fo
b' cm /Im%d Do Q\n' % placement['source_index'])
resources = {'XObject': {f'Im{index}': ref for index, ref in images.items()}}
if footer:
commands.append(footer_commands(footer))
logo = SourceImage(FOOTER_LOGO, 'logo') if os.path.exists(FOOTER_LOGO) else None
if logo:
resources['XObject']['Logo'] = logo.embed(pdf)
logo.close()
commands.append(footer_commands(footer, logo.size if logo else None))
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))

View File

@@ -356,7 +356,7 @@ 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-<Kanban number> · Item 1/2 · date · billed metres" in black
Helvetica (the logo waits for Dropstar's file). An original used whole as its
Helvetica, after Dropstar's logo (app/assets). 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

View File

@@ -10,6 +10,7 @@ import re
import tempfile
import unittest
import zlib
from unittest import mock
from PIL import Image
@@ -99,11 +100,20 @@ class PrintFileTests(unittest.TestCase):
self.assertAlmostEqual(height, 11.5 * PT_PER_CM, places=2)
self.assertEqual((detail['height_cm'], detail['page_height_cm'], detail['footer']), ('10', '11.5', line))
content = self.content(pdf)
self.assertIn(b'/F1 18 Tf', content)
self.assertIn(b'(DROPSTAR) Tj', content)
self.assertIn(' · Pedido DTF-7 · Item 1/2 · 21/10/2026 · 1,00 m'.encode('cp1252'), content)
# Dropstar's logo first (black on transparent: a soft mask), then the line.
self.assertIn(b' cm /Logo Do Q', content)
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('(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
self.assertIn(b'/BaseFont /Helvetica-Bold', pdf)
# Without the logo file, the brand's name in bold.
with mock.patch('app.printfile.FOOTER_LOGO', os.path.join(self.dir.name, 'none.png')):
bare = io.BytesIO()
render(spec, {0: (path, 'a.png')}, bare, 'test', footer=line)
self.assertIn(b'(DROPSTAR) Tj', self.content(bare.getvalue()))
self.assertIn(b'/BaseFont /Helvetica-Bold', bare.getvalue())
# The artwork keeps its place from the top: the band is below it.
matrix = re.search(rb'q ([\d. -]+) cm /Im0 Do Q', content).group(1).split()
self.assertAlmostEqual(float(matrix[5]), 1.5 * PT_PER_CM, places=2)