I rebuilt a question found in actual production source as independent synthetic code. The complete implementation, examples and tests are shared without connecting the original business program or material.
Make word and line boundaries explicit
Wrap accepts a measurement callback. A next word that exceeds the line starts a new line, but a word wider than the frame fails even after earlier text. Exceeding the line limit raises an error rather than silently truncating content.
The contract develops a word-preservation question found in an actual worksheet generator. The shared PDF uses a new English sentence and original shapes, with no copied worksheet, customer font or lesson photo. Other languages need their own segmentation policy.
Check text and cut lines in page points
Baselines derives text positions from a start and leading, rejecting a final baseline below reserved space. Dashes generates explicit A4-point segments and clips the last one at the endpoint. Invalid page bounds and zero progression fail.
The sample separates its text frame, cutting guide and footer notice. Attractive screen dashes do not establish physical cutting usability. Printer scaling and printable margins are not measured and require their own actual-output check.
Expose the generation boundary
Core tests use only the standard library. Creating a PDF through make_pdf requires ReportLab 4.4.9 and an explicitly supplied destination. The example runner returns geometry without writing files. The packaged sample is an actually generated and inspected fixed result.
Its single-page extraction and notice were checked, and the rendered image was visually reviewed for text, shape, cutting-line and footer separation. This does not establish physical printing behavior or every font-substitution environment. The original customer program was not run.
Explore the implementation
Complete independent synthetic implementation
"""Synthetic word layout and explicit PDF creation. Units are points."""
import math
A4=(595.2756,841.8898)
NOTICE='Synthetic original shapes - modify and reuse permitted - v1'
def positive(n):
if isinstance(n,bool) or not isinstance(n,(int,float)) or not math.isfinite(n) or n<=0:raise ValueError('finite positive geometry')
return n
def nonnegative(n):
if isinstance(n,bool) or not isinstance(n,(int,float)) or not math.isfinite(n) or n<0:raise ValueError('finite nonnegative coordinate')
return n
def wrap(text,width,measure,max_lines=100):
positive(width)
if not isinstance(text,str) or not text.strip() or not isinstance(max_lines,int) or isinstance(max_lines,bool) or max_lines<1:raise ValueError('text and bounded lines')
words=text.split();lines=[];line=''
for word in words:
if measure(word)>width:raise ValueError('unbreakable word exceeds width')
candidate=(line+' '+word).strip()
if measure(candidate)<=width:line=candidate
else:lines.append(line);line=word
if line:lines.append(line)
if len(lines)>max_lines:raise ValueError('layout needs more lines; no silent truncation')
return lines
def baselines(top,count,leading,bottom):
positive(top);positive(leading);nonnegative(bottom)
if not isinstance(count,int) or isinstance(count,bool) or count<1 or bottom<0:raise ValueError('baseline contract')
result=[top-i*leading for i in range(count)]
if result[-1]<bottom:raise ValueError('text crosses reserved bottom')
return result
def dashes(x1,x2,y,dash=5,gap=4):
nonnegative(x1)
for v in (x2,y,dash,gap):positive(v)
if x1<0 or x2<=x1 or x2>A4[0] or y>A4[1]:raise ValueError('line outside page')
segments=[];x=x1
while x<x2:
segments.append([x,min(x+dash,x2),y]);x+=dash+gap
return segments
def make_pdf(path):
from reportlab.pdfgen.canvas import Canvas
from reportlab.pdfbase.pdfmetrics import stringWidth
c=Canvas(str(path),pagesize=A4,invariant=1);c.setAuthor('Independent synthetic module');c.setCreator('Printable geometry example');c.setProducer('Synthetic geometry renderer');c.setTitle('Words and cutting lines - synthetic worksheet')
w,h=A4;c.setFillColorRGB(.08,.22,.24);c.setFont('Helvetica-Bold',25);c.drawString(42,h-62,'Words, shapes and space')
c.setFont('Helvetica',11);c.drawString(42,h-84,'A synthetic worksheet for inspecting line layout and cutting coordinates.')
c.setStrokeColorRGB(.67,.76,.73);c.roundRect(42,310,w-84,390,12,stroke=1,fill=0)
lines=wrap('Read each instruction before you cut. Match the circle to the square, then leave the triangle in the remaining space.',w-124,lambda t:stringWidth(t,'Helvetica',14))
ys=baselines(665,len(lines),22,580);c.setFont('Helvetica',14)
for text,y in zip(lines,ys):c.drawString(62,y,text)
c.setStrokeColorRGB(.10,.36,.35);c.setLineWidth(2);c.circle(126,470,35,stroke=1,fill=0);c.rect(250,435,70,70,stroke=1,fill=0);p=c.beginPath();p.moveTo(420,510);p.lineTo(380,435);p.lineTo(460,435);p.close();c.drawPath(p,stroke=1,fill=0)
c.setFont('Helvetica',11)
for x,t in [(105,'Circle'),(267,'Square'),(400,'Triangle')]:c.drawString(x,405,t)
c.setFont('Helvetica',10);c.drawString(42,265,'CUTTING GUIDE - dashed geometry is separate from the text frame')
c.setLineWidth(.8)
for x1,x2,y in dashes(42,w-42,245):c.line(x1,y,x2,y)
c.setFont('Helvetica',10);c.drawString(42,210,'Printer scaling can change physical size. Check actual print settings separately.')
c.setFillColorRGB(.30,.37,.37);c.setFont('Helvetica',9);c.drawString(42,54,NOTICE);c.drawRightString(w-42,35,'1 / 1');c.save()
return dict(page=A4,lines=lines,baselines=ys,cutting_y=245,text_bottom=310,notice=NOTICE)Move the long word after existing text
A short earlier word does not make an oversized next word fit. Testing only the first word would miss this case, so the suite also checks an already populated line. A future splitting policy needs language and educational intent; this version refuses to split silently.
The counterexample is inspectable through tests and saved execution records. Adoption requires checking input meaning and failure policy before changing labels. A small independent function does not replace an operational application.
Published code and ZIP use the same reviewed files. The central decision can be inspected without importing company records or running another system. Any added integration needs separate observed results; the existing package does not pre-certify its behavior.
Actual execution evidence and its boundary
The source folder and a fresh ZIP extraction each passed 12 tests. Actual example results are saved in records.json, and the published core can be compared with the download. Historical project completion messages and test totals were not reused as evidence of this execution.
The selector reads results saved by actual local runs; it does not execute Python or a server in the browser. These checks do not establish rendered-browser or physical-device behavior. An integrated service needs its own observed verification rather than inheriting a broader claim from these small tests.
Before adapting the download
The ZIP contains core implementation, tests, runner, saved results and guidance; live examples also include bilingual HTML. This is new synthetic code with permission to modify and reuse, without original customer images, operational records or credentials. It contains no instruction to execute the source business program or transmit its material.
Begin adoption by defining units, input provenance and failure messages for the actual workflow. Passing tests cannot certify all supplied facts or grant operational authority. Authentication, persistence, transmission and rendered-interface review remain outside the small contract. I share both a reusable implementation and the decisions an adopter still needs to make.
Additional boundary review now rejects nonfinite and boolean start or reserved-bottom coordinates. Counterexamples were added within the existing twelve test methods; the sample PDF and recorded examples are unchanged.