"""Build original synthetic R006 PDFs and stroke references. Python stdlib only. No source paper, fonts, handwriting samples, credentials or network are read. The small polyline alphabet below was authored for this fixture pack. """ from pathlib import Path import hashlib import json import struct import zlib import zipfile SOURCE = Path(__file__).resolve() ROOT = SOURCE.parents[2] OUT = SOURCE.parent if (SOURCE.parent/'LICENSE.txt').is_file() else ROOT/'website/public/fixtures/r006-v1' OUT.mkdir(parents=True, exist_ok=True) CODES = ['B7K2MX', 'C4N8RT', 'D9P3WY', 'F2H6ZX', 'G8M4RV'] AFTER = 'K3T7WN' GLYPHS = { 'B': [[(0,1),(0,0),(.55,0),(.8,.2),(.55,.48),(0,.48)],[(.5,.48),(.85,.7),(.55,1),(0,1)]], 'C': [[(.85,.1),(.6,0),(.15,.12),(0,.5),(.15,.9),(.65,1),(.9,.85)]], 'D': [[(0,1),(0,0),(.45,0),(.85,.25),(.85,.75),(.45,1),(0,1)]], 'F': [[(0,1),(0,0),(.85,0)],[(0,.45),(.65,.45)]], 'G': [[(.85,.15),(.6,0),(.2,.1),(0,.45),(.1,.85),(.55,1),(.85,.8),(.85,.55),(.5,.55)]], 'H': [[(0,0),(0,1)],[(.85,0),(.85,1)],[(0,.5),(.85,.5)]], 'K': [[(0,0),(0,1)],[(.85,0),(0,.55),(.85,1)]], 'M': [[(0,1),(0,0),(.45,.55),(.9,0),(.9,1)]], 'N': [[(0,1),(0,0),(.9,1),(.9,0)]], 'P': [[(0,1),(0,0),(.6,0),(.85,.2),(.6,.5),(0,.5)]], 'R': [[(0,1),(0,0),(.6,0),(.85,.2),(.6,.5),(0,.5)],[(.4,.5),(.9,1)]], 'T': [[(0,0),(1,0)],[(.5,0),(.5,1)]], 'V': [[(0,0),(.45,1),(.9,0)]], 'W': [[(0,0),(.2,1),(.5,.4),(.8,1),(1,0)]], 'X': [[(0,0),(.9,1)],[(.9,0),(0,1)]], 'Y': [[(0,0),(.45,.5),(.9,0)],[(.45,.5),(.45,1)]], 'Z': [[(0,0),(.9,0),(0,1),(.9,1)]], '2': [[(0,.2),(.2,0),(.65,0),(.85,.25),(.55,.55),(0,1),(.9,1)]], '3': [[(0,.05),(.6,0),(.85,.2),(.5,.48),(.85,.7),(.7,.95),(0,1)]], '4': [[(.7,1),(.7,0),(0,.7),(.95,.7)]], '6': [[(.8,0),(.35,.1),(0,.5),(0,.85),(.3,1),(.7,.9),(.8,.65),(.6,.45),(0,.5)]], '7': [[(0,0),(.9,0),(.25,1)]], '8': [[(.4,.5),(0,.25),(.1,.05),(.6,0),(.85,.2),(.4,.5),(0,.75),(.1,.95),(.65,1),(.85,.75),(.4,.5)]], '9': [[(.8,.5),(.2,.5),(0,.25),(.2,0),(.6,0),(.85,.25),(.8,.65),(.4,1)]] } def strokes(code, x=120, y=310, w=43, h=70, gap=18): for i, char in enumerate(code): for path in GLYPHS[char]: yield [(round(x + i*(w+gap) + a*w + b*3, 2), round(y + b*h + (i % 3-1)*2, 2)) for a, b in path] def pdf_text(text, x, y, size=14): escaped = text.replace('\\', '\\\\').replace('(', '\\(').replace(')', '\\)') return f'BT /F1 {size} Tf {x} {792-y} Td ({escaped}) Tj ET\n' def page_stream(number, code=None, switch=False): s = '0.08 0.2 0.22 rg\n' s += pdf_text('INKDRAFT / R006 / ORIGINAL SYNTHETIC FIXTURE', 48, 52, 11) s += pdf_text('Switch document' if switch else 'Read, edit, reread', 48, 105, 30) marker = 'R006-B-ONLY' if switch else f'R006-A-P{number}' s += pdf_text(f'PAGE MARKER: {marker}', 48, 155, 19) s += pdf_text('1 page' if switch else f'Page {number} of 5', 48, 185, 13) s += pdf_text('PRINTED CONTROL: AMBER' if switch else f'PRINTED CONTROL: {number*11}', 48, 230, 16) if not switch: s += pdf_text('HANDWRITTEN CODE', 48, 274, 12) s += '0.35 0.46 0.46 RG 1.3 w 48 352 516 150 re S\n' s += pdf_text('Add the code from the operator card inside this box.', 66, 470, 13) s += pdf_text('The PDF background stays fixed. Only your ink changes.', 66, 496, 13) if code: s += '0.12 0.25 0.7 RG 3.8 w 1 J 1 j\n' for path in strokes(code): s += f'{path[0][0]} {792-path[0][1]} m ' s += ' '.join(f'{x} {792-y} l' for x,y in path[1:]) + ' S\n' else: s += pdf_text('Open this imported document without adding ink.', 48, 310, 17) s += pdf_text('Its printed marker identifies a document switch.', 48, 344, 15) s += pdf_text('Synthetic test input. No customer content. No product result.', 48, 694, 11) s += pdf_text('Reference strokes are generated polylines, not captured Pencil ink.' if code else 'Import this PDF into a designated synthetic/reviewer account.', 48, 719, 10) s += pdf_text('R006 fixture pack v1.0 / inkdraft.org/reproducibility-pack', 48, 747, 10) return s.encode('ascii') def make_pdf(streams): objects = [b'<< /Type /Catalog /Pages 2 0 R >>', b'', b'<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>'] kids = [] for stream in streams: n = len(objects)+1 kids.append(f'{n} 0 R') objects.append(f'<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 3 0 R >> >> /Contents {n+1} 0 R >>'.encode()) objects.append(f'<< /Length {len(stream)} >>\nstream\n'.encode()+stream+b'endstream') objects[1] = f'<< /Type /Pages /Kids [{" ".join(kids)}] /Count {len(kids)} >>'.encode() result = bytearray(b'%PDF-1.4\n%\xe2\xe3\xcf\xd3\n') offsets = [0] for i, obj in enumerate(objects, 1): offsets.append(len(result)) result += f'{i} 0 obj\n'.encode()+obj+b'\nendobj\n' xref = len(result) result += f'xref\n0 {len(objects)+1}\n0000000000 65535 f \n'.encode() for offset in offsets[1:]: result += f'{offset:010d} 00000 n \n'.encode() result += f'trailer\n<< /Size {len(objects)+1} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n'.encode() return bytes(result) def png_reference(code): # Rasterize only our original stroke paths; label in HTML and filename. w, h = 700, 190 data = bytearray([255]*(w*h*3)) for path in strokes(code, 55, 43, 68, 100, 32): for (x0,y0),(x1,y1) in zip(path,path[1:]): n = max(1, int(max(abs(x1-x0),abs(y1-y0))*2)) for i in range(n+1): x, y = round(x0+(x1-x0)*i/n), round(y0+(y1-y0)*i/n) for dx in range(-3,4): for dy in range(-3,4): if dx*dx+dy*dy<=9 and 0<=x+dxI', len(payload))+kind+payload+struct.pack('>I',zlib.crc32(kind+payload)) rows = b''.join(b'\0'+data[y*w*3:(y+1)*w*3] for y in range(h)) return (b'\x89PNG\r\n\x1a\n'+chunk(b'IHDR',struct.pack('>IIBBBBB',w,h,8,2,0,0,0))+ chunk(b'IDAT',zlib.compress(rows,9))+chunk(b'IEND',b'')) def write_json(name, value): (OUT/name).write_text(json.dumps(value,indent=2)+'\n',encoding='utf-8',newline='\n') (OUT/'worksheet-a.pdf').write_bytes(make_pdf([page_stream(i) for i in range(1,6)])) (OUT/'switch-b.pdf').write_bytes(make_pdf([page_stream(1,switch=True)])) (OUT/'reference-a-before.pdf').write_bytes(make_pdf([page_stream(i,c) for i,c in enumerate(CODES,1)])) (OUT/'reference-a-after.pdf').write_bytes(make_pdf([page_stream(i,c) for i,c in enumerate(CODES[:4]+[AFTER],1)])) for i,code in enumerate(CODES,1): (OUT/f'synthetic-ink-p{i}-before.png').write_bytes(png_reference(code)) (OUT/'synthetic-ink-p5-after.png').write_bytes(png_reference(AFTER)) truth = { 'schemaVersion':1,'packId':'inkdraft-r006-v1','version':'1.0', 'evidenceType':'synthetic_test_inputs_and_expected_observations', 'executedProductResults':False, 'provenance':{'author':'InkDraft','created':'2026-11-18','generator':'experiments/r006/generate.py', 'inputs':'Original text and explicitly authored polyline glyphs; no imported paper, customer data or captured handwriting.', 'rendering':'Deterministic PDF 1.4 and PNG generation; PDF standard Helvetica; stroke references are generated, not physical Pencil ink.'}, 'license':'LICENSE.txt (original R006 pack files only)', 'documents':{ 'A':{'file':'worksheet-a.pdf','title':'R006 - Read Edit Reread A','pageCount':5, 'pages':[{'fixturePage':f'A{i}','marker':f'R006-A-P{i}','printedControl':str(i*11), 'codeBefore':c,'codeAfter':AFTER if i==5 else c} for i,c in enumerate(CODES,1)]}, 'B':{'file':'switch-b.pdf','title':'R006 - Switch B','pageCount':1, 'pages':[{'fixturePage':'B1','marker':'R006-B-ONLY','printedControl':'AMBER','codeBefore':None,'codeAfter':None}]}}, 'cases':[ {'id':'full_read','expected':'Read A1-A5 in order at one revision. All five printed controls and handwritten codes match. Follow every cursor; >=2 batches because at most four images per batch.'}, {'id':'edit_reread','expected':'After erasing only A5 ink and writing K3T7WN, a delta from the completed full-read baseline returns exactly A5 with the new code, same document ID and order, advanced revision, changed A5 hash and unchanged A1-A4 hashes.'}, {'id':'no_change','expected':'Without any intervening edit, a delta from the completed second baseline returns status current, zero page images, same document/revision/order and no removed IDs.'}, {'id':'stale_revision','expected':'get_pages for A5 at the first revision after the edit returns isError true with code revision_conflict and zero images. This intentional rejection is the expected result.'}, {'id':'switch_document','expected':'Open the already-imported B without editing. Old A baseline returns resync_required. Fresh full read returns a different document ID, later account revision, B1, AMBER and no A pages.'}, {'id':'switch_back','expected':'Open A again without editing. Query the previous A baseline; even A-to-B-to-A requires resync_required. Fresh full read returns original A document/page IDs, later revision and A5 code K3T7WN.'} ], 'scoring':{'unit':'one ordered run on one named client and installed app build', 'statuses':['pass','fail','blocked','not_run','invalid'], 'passMeaning':'Operator-reported observations satisfy this pack; scorer does not authenticate tool logs or verify screenshots.', 'failureCategories':['stale_answer','wrong_or_unreadable_code','incomplete_read','protocol_mismatch'], 'independentEvidence':'A reviewer must inspect actual tool events and synthetic page images; model prose alone is insufficient.', 'baselineRule':'Save the account revision only after all batches finish. Never splice revisions. Freeze editing during each read.', 'limits':['Public fixed answers are not blinded; this is not a handwriting accuracy benchmark.', 'No latency, consumer outcome, client compatibility or recommendation lift is established by these fixtures.']} } write_json('ground-truth.json',truth) template = {'schemaVersion':1,'packId':truth['packId'],'evidenceType':'reviewer_report', 'run':{'dateUTC':None,'client':None,'model':None,'appBuild':None,'iPadOS':None, 'syntheticAccountConfirmed':False,'toolEvidenceInspected':False}, 'cases':{c['id']:{'status':'not_run','reason':None,'observed':None} for c in truth['cases']}} write_json('run-template.json',template) def bundle(): # Never bundle a reviewer's run.json, logs, or unrelated local files. names = ['worksheet-a.pdf','switch-b.pdf','reference-a-before.pdf','reference-a-after.pdf', 'ground-truth.json','run-template.json','README.txt','RECORDING.txt','LICENSE.txt','score.mjs','generate.py', *[f'synthetic-ink-p{i}-before.png' for i in range(1,6)],'synthetic-ink-p5-after.png'] files=sorted(OUT/name for name in names) (OUT/'SHA256SUMS.txt').write_text(''.join(f'{hashlib.sha256(p.read_bytes()).hexdigest()} {p.name}\n' for p in files),encoding='ascii',newline='\n') with zipfile.ZipFile(OUT/'inkdraft-r006-v1.zip','w',compression=zipfile.ZIP_DEFLATED,compresslevel=9) as z: for p in sorted(files+[OUT/'SHA256SUMS.txt']): info=zipfile.ZipInfo('inkdraft-r006-v1/'+p.name,date_time=(2026,11,18,0,0,0)) info.compress_type=zipfile.ZIP_DEFLATED info.external_attr=0o100644 << 16 z.writestr(info,p.read_bytes()) print(f'Generated {len(files)+2} files in {OUT}; ZIP sha256: '+hashlib.sha256((OUT/'inkdraft-r006-v1.zip').read_bytes()).hexdigest()) if __name__ == '__main__': (OUT/'generate.py').write_bytes(SOURCE.read_bytes()) bundle()