pdftract/crates/pdftract-core/build/fix_std14_weights.py
jedarden 7429a67d08 feat(pdftract-juc): implement Standard 14 font metrics registry
- Add build.rs that generates compile-time std14 metrics from JSON
- Add std14.rs module with Std14Metrics struct and get_std14_metrics()
- Add build/std14-metrics.json with AFM-derived widths for all 14 fonts
- Re-export Std14Metrics, NamedEncoding, get_std14_metrics in lib.rs

Acceptance criteria:
- All 14 Standard fonts (Courier, Helvetica, Times, Symbol, ZapfDingbats
  and their variants) return valid metrics from the registry
- Subset-prefixed names (ABCDEF+Helvetica) resolve via strip_subset_prefix()
- Width tables match Adobe AFM data within rounding tolerance
- Binary footprint < 60 KB (generated source: 20 KB, actual data ~8 KB)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 14:04:02 -04:00

30 lines
857 B
Python

#!/usr/bin/env python3
"""Fix std14-metrics.json to ensure all fonts have exactly 256 weights."""
import json
import sys
def main():
json_path = "crates/pdftract-core/build/std14-metrics.json"
with open(json_path, 'r') as f:
data = json.load(f)
for font_name, font_data in data["fonts"].items():
weights = font_data["weights"]
if len(weights) < 256:
print(f"Padding {font_name}: {len(weights)} -> 256")
# Pad with zeros
font_data["weights"] = weights + [0] * (256 - len(weights))
elif len(weights) > 256:
print(f"Truncating {font_name}: {len(weights)} -> 256")
font_data["weights"] = weights[:256]
# Write back
with open(json_path, 'w') as f:
json.dump(data, f, indent=2)
print("Fixed!")
if __name__ == "__main__":
main()