#!/usr/bin/env python3 """Independent actual PDF device/mag/true oracle; unchanged physical tolerances. Every synthetic input is identical for native and reference execution. External TeX is used only here, never by the product. Retain all source/PDF/aux evidence. """ import argparse import hashlib import importlib.util import json import os import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] def module(name, file): spec = importlib.util.spec_from_file_location(name, ROOT/'scripts'/file) result = importlib.util.module_from_spec(spec) spec.loader.exec_module(result) return result INK = module('native_page_ink', 'check-native-pages.py') WORDS = module('native_page_words', 'check-native-paragraphs.py') def cases(): fixture = ROOT/'examples/native-bootstrap/device.tex' yield 'original-device-fixture', fixture.read_text(), fixture.parent, 3, ['cmr10', 'cmmi7'] fonts = (ROOT/'examples/native-bootstrap/math-fonts.tex').read_text() for mag in [500, 1000, 1095, 1200, 2000, 4096]: for unit in ['pt', 'truept']: source = (fonts + f'\\mag={mag}\\pdfpagewidth=180{unit}\\pdfpageheight=140{unit}' + f'\\pdfhorigin=10{unit}\\pdfvorigin=12{unit}' + r'\hoffset=2pt\voffset=3pt\count0=1\immediate\openout1=device.aux' + r'\setbox0=\vbox{\hbox{Native AV office $x_i^j+y$}\kern2pt\hrule height1pt depth2pt' + r'\write1{SHIP=\number\count0;MAG=\number\mag}}\shipout\copy0' + r'{\pdfpagewidth=0pt\pdfpageheight=0pt\hoffset=-1pt\voffset=2pt' + r'\count0=2\shipout\box0}' + r'\pdfpagewidth=999pt\pdfpageheight=888pt\pdfhorigin=123pt' + '\\immediate\\closeout1\\end\n') yield f'mag-{mag}-{unit}', source, fixture.parent, 2, ['cmr10', 'cmmi7'] for mag in [1, 32768]: # Keep the actual TeX font size below its 2048pt limit at mag=1. font_size = 2 if mag == 1 else 10 source = (r'\catcode123=1\catcode125=2' + f'\\mag={mag}' + f'\\font\\physical=cmr10 at{font_size}truept\\physical' + r'\pdfpagewidth=12truept\pdfpageheight=12truept' + r'\pdfhorigin=1truept\pdfvorigin=1truept\count0=1' + r'\immediate\openout1=device.aux\shipout\hbox{A' + r'\vrule width1truept height2truept depth.5truept' + r'\write1{SHIP=\number\count0;MAG=\number\mag}}' + '\\immediate\\closeout1\\end\n') yield f'mag-boundary-{mag}', source, fixture.parent, 1, ['cmr10'] def mediaboxes(path): # Poppler resolves both classic and compressed object/xref layouts. text = INK.run(['pdftotext', '-bbox', path, '-'], path.parent) return [[0.0, 0.0, float(w), float(h)] for w, h in re.findall( r'