"""Re-run translation with the new B3.5 code and save to disk."""
import sys
sys.path.insert(0, '.')
import shutil
from pathlib import Path
import fitz

src = Path('sample_files/test_corpus/test_pdf.pdf')
dst = Path('sample_files/test_corpus/test_pdf_translated.pdf')

from translators.pdf_translator import PDFTranslator
PDFTranslator().translate_file(src, dst, target_language='fr', source_language='en')

o = fitz.open(src)
n = fitz.open(dst)
print(f'Original:   {len(o)} pages, {src.stat().st_size} bytes')
print(f'Translated: {len(n)} pages, {dst.stat().st_size} bytes')
print()
print('Page 1 font sizes:')
o_sizes = set()
n_sizes = set()
for b in o[0].get_text("dict").get("blocks", []):
    for l in b.get("lines", []):
        for s in l.get("spans", []):
            o_sizes.add(round(s.get("size", 0), 1))
for b in n[0].get_text("dict").get("blocks", []):
    for l in b.get("lines", []):
        for s in l.get("spans", []):
            n_sizes.add(round(s.get("size", 0), 1))
print('  Original:  ', sorted(o_sizes))
print('  Translated:', sorted(n_sizes))
o.close()
n.close()
