"""Read font layout and packed font links from saved native Main artifacts.""" import hashlib import json from pathlib import Path import sys import bpy directory = Path(sys.argv[sys.argv.index("--") + 1]) result = {} for blend in sorted(directory.glob("*.blend")): bpy.ops.wm.open_mainfile(filepath=str(blend), load_ui=False) texts = [] for obj in sorted(bpy.data.objects, key=lambda value: value.name): if obj.type != "FONT": continue curve = obj.data texts.append({ "object": obj.name, "data": curve.name, "body": curve.body, "boxes": [{"x": box.x, "y": box.y, "width": box.width, "height": box.height} for box in curve.text_boxes], "characters": [{"kern": char.kerning, "material": char.material_index, "bold": char.use_bold, "italic": char.use_italic, "underline": char.use_underline} for char in curve.body_format], "links": {name: getattr(curve, name).name if getattr(curve, name) else None for name in ("font", "font_bold", "font_italic", "font_bold_italic")}, }) fonts = [{"name": font.name, "packedSha256": hashlib.sha256(bytes(font.packed_file.data)).hexdigest() if font.packed_file else None} for font in sorted(bpy.data.fonts, key=lambda value: value.name)] result[blend.stem] = {"texts": texts, "fonts": fonts} (directory / "native-font-snapshots.json").write_text(json.dumps(result, sort_keys=True, separators=(",", ":")), encoding="utf-8")