import os
import subprocess

# Define the Unicode range for Extended Latin
UNICODE_RANGE = "U+0020-024F"

# Get all .otf files in the current directory
otf_files = [f for f in os.listdir() if f.endswith(".otf")]

if not otf_files:
    print("No .otf files found in the current directory.")
    exit()

# Process each .otf file
for otf_file in otf_files:
    output_file = otf_file.replace(".otf", "-Subset.otf")
    command = [
        "pyftsubset",
        otf_file,
        f"--unicodes={UNICODE_RANGE}",
        f"--output-file={output_file}"
    ]

    print(f"Subsetting {otf_file}...")
    try:
        subprocess.run(command, check=True)
        print(f"✅ Successfully created {output_file}")
    except subprocess.CalledProcessError:
        print(f"❌ Failed to process {otf_file}")

print("✅ All files processed!")
