"""Original CC0 PDF fixtures, made 2026-10-18. Requires pypdf."""
from pathlib import Path
from pypdf import PdfWriter
from pypdf.generic import DictionaryObject,NameObject,DecodedStreamObject,RectangleObject
import json,hashlib,argparse
p=argparse.ArgumentParser();p.add_argument('--output',default='fixtures');a=p.parse_args();out=Path(a.output);out.mkdir(parents=True,exist_ok=True)
def make(name,pages,encrypt=False):
 w=PdfWriter(); f=w._add_object(DictionaryObject({NameObject('/Type'):NameObject('/Font'),NameObject('/Subtype'):NameObject('/Type1'),NameObject('/BaseFont'):NameObject('/Helvetica')}))
 for width,height,commands,rotation,crop in pages:
  page=w.add_blank_page(width=width,height=height);page[NameObject('/Resources')]=DictionaryObject({NameObject('/Font'):DictionaryObject({NameObject('/F1'):f})})
  st=DecodedStreamObject();st.set_data(commands.encode('ascii'));page[NameObject('/Contents')]=w._add_object(st)
  if rotation:page.rotate(rotation)
  if crop:page[NameObject('/CropBox')]=RectangleObject(crop)
 w.add_metadata({'/Title':'Filepetal original PDF to SVG test','/Subject':'CC0 synthetic geometric test; 2026-10-18'})
 if encrypt:w.encrypt('filepetal-test')
 with (out/(name+'.pdf')).open('wb') as fp:w.write(fp)
shapes='0.1 0.6 0.5 rg 20 20 70 70 re f 0.95 0.5 0.25 rg 120 40 80 45 re f'
make('shapes',[(240,160,shapes,0,None)])
make('text',[(240,120,'0 0 0 rg BT /F1 18 Tf 20 70 Td (EDIT ME 123) Tj ET',0,None)])
fine='0 0 0 RG '+' '.join(f'{v} w 30 {10+i*12} m 1170 {10+i*12} l S' for i,v in enumerate([.1,.25,.5,1,2]))
make('fine-lines',[(1200,80,fine,0,None)])
make('crop-rotate',[(240,160,shapes,0,[20,20,220,140]),(240,160,shapes,90,[20,20,220,140])])
make('blank',[(100,80,'',0,None)])
make('protected',[(240,160,shapes,0,None)],True)
(out/'corrupt.pdf').write_bytes(b'%PDF-1.7\nnot a complete PDF\n%%EOF')
(out/'wrong-header.pdf').write_bytes(b'This is not a PDF file')
rows=[{'file':q.name,'bytes':q.stat().st_size,'sha256':hashlib.sha256(q.read_bytes()).hexdigest()} for q in sorted(out.glob('*.pdf'))]
(out/'input-manifest.json').write_text(json.dumps({'date':'2026-10-18','license':'CC0-1.0','pypdf_version':__import__('pypdf').__version__,'files':rows},indent=2)+'\n',encoding='utf8')
print(json.dumps(rows))
