Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug (pdf reader): unknown base font #295

Open
reycn opened this issue Dec 19, 2024 · 1 comment
Open

bug (pdf reader): unknown base font #295

reycn opened this issue Dec 19, 2024 · 1 comment
Labels
bug Something isn't working enhancement New feature or request

Comments

@reycn
Copy link
Collaborator

reycn commented Dec 19, 2024

Bug

If the font name of a PDF file is unknown, the program will raise a KeyError: <PDFType1Font: basefont='unknown'>, as follows:

Traceback (most recent call last):
  File "/Users/rey/miniconda3/envs/pdf/bin/pdf2zh", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/rey/Developer/PDFMathTranslate.Origin/pdf2zh/pdf2zh.py", line 192, in main
    translate(**vars(parsed_args))
  File "/Users/rey/Developer/PDFMathTranslate.Origin/pdf2zh/high_level.py", line 359, in translate
    s_mono, s_dual = translate_stream(
                     ^^^^^^^^^^^^^^^^^
  File "/Users/rey/Developer/PDFMathTranslate.Origin/pdf2zh/high_level.py", line 234, in translate_stream
    obj_patch: dict = translate_patch(fp, prompt=kwarg["prompt"], **locals())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rey/Developer/PDFMathTranslate.Origin/pdf2zh/high_level.py", line 165, in translate_patch
    interpreter.process_page(page)
  File "/Users/rey/Developer/PDFMathTranslate.Origin/pdf2zh/pdfinterp.py", line 270, in process_page
    ops_new = self.device.end_page(page)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rey/Developer/PDFMathTranslate.Origin/pdf2zh/converter.py", line 61, in end_page
    return self.receive_layout(self.cur_item)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rey/Developer/PDFMathTranslate.Origin/pdf2zh/converter.py", line 429, in receive_layout
    ops += f"/{self.fontid[vch.font]} {vch.size:f} Tf 1 0 0 1 {x + vch.x0 - var[vid][0].x0:f} {fix + y + vch.y0 - var[vid][0].y0:f} Tm [<{raw_string(self.fontid[vch.font], vc)}>] TJ "
               ~~~~~~~~~~~^^^^^^^^^^
KeyError: <PDFType1Font: basefont='unknown'>

The program itself runs well, passing all tests and translating other documents.

Sample Document

translate.cli.font.unknown.pdf

@reycn reycn added bug Something isn't working enhancement New feature or request labels Dec 19, 2024
@reycn
Copy link
Collaborator Author

reycn commented Dec 19, 2024

A corresponding test case has been written in CI, yet not active before fixing the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant