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: The font list order of pypdf.annotations.FreeText is different(#1435) #2893

Conversation

ssjkamei
Copy link
Contributor

@ssjkamei ssjkamei commented Oct 6, 2024

Close #1435

The order of the list was different.
image

It seems difficult to obtain the actual font size etc. Is it necessary to test?

@stefan6419846
Copy link
Collaborator

It seems difficult to obtain the actual font size etc.

Could you please elaborate?

Is it necessary to test?

Yes, in the best case we would check the correct output here as well covering some common combinations.

Copy link

codecov bot commented Oct 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.43%. Comparing base (96b46ad) to head (423876d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2893   +/-   ##
=======================================
  Coverage   96.43%   96.43%           
=======================================
  Files          52       52           
  Lines        8724     8726    +2     
  Branches     1721     1721           
=======================================
+ Hits         8413     8415    +2     
  Misses        182      182           
  Partials      129      129           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ssjkamei
Copy link
Contributor Author

ssjkamei commented Oct 6, 2024

It seems difficult to obtain the actual font size etc.

Could you please elaborate?

The problem is that it's difficult for me to capture in code that the font size has changed.
There was originally a test that asked you to see it with your own eyes, but is there any problem with this?


def test_free_text_annotation(pdf_file_path):
    # Arrange
    pdf_path = RESOURCE_ROOT / "crazyones.pdf"
    reader = PdfReader(pdf_path)
    page = reader.pages[0]
    writer = PdfWriter()
    writer.add_page(page)

    # Act
    free_text_annotation = FreeText(
        text="Hello World - bold and italic\nThis is the second line!",
        rect=(50, 550, 200, 650),
        font="Arial",
        bold=True,
        italic=True,
        font_size="20pt",
        font_color="00ff00",
        border_color=None,
        background_color=None,
    )
    writer.add_annotation(0, free_text_annotation)

    free_text_annotation = FreeText(
        text="Another free text annotation (not bold, not italic)",
        rect=(500, 550, 200, 650),
        font="Arial",
        bold=False,
        italic=False,
        font_size="20pt",
        font_color="00ff00",
        border_color="0000ff",
        background_color="cdcdcd",
    )
    writer.add_annotation(0, free_text_annotation)

    # Assert: You need to inspect the file manually
    with open(pdf_file_path, "wb") as fp:
        writer.write(fp)

@ssjkamei
Copy link
Contributor Author

ssjkamei commented Oct 6, 2024

#2084 can also be closed.

@stefan6419846
Copy link
Collaborator

In general, we prefer tests that are automated. Thus, for your change, I would prefer you to add a corresponding test which asserts that we indeed generate the correct font strings from the inputs. IMHO this case can be tested from code and does not need manual inspection.

@ssjkamei
Copy link
Contributor Author

ssjkamei commented Oct 6, 2024

Is it okay to delete the original test and create a new one?
In this case, as a test, do you mean read it with PDFReader after writing and check the input value as is?
Do you have any hints?

@stefan6419846
Copy link
Collaborator

It should not harm to keep the existing test nevertheless.

In my opinion, it would be sufficient to just create different FreeText instances and verify their /DS entry using assert "abc" == FreeText()["/DS"].

@ssjkamei
Copy link
Contributor Author

ssjkamei commented Oct 7, 2024

Thank you!
I've added this to the existing test, is this correct?

@ssjkamei
Copy link
Contributor Author

ssjkamei commented Oct 7, 2024

I think #2305 can be closed if there are no problems with the comments.

@stefan6419846
Copy link
Collaborator

I've added this to the existing test, is this correct?

Please move this to a dedicated test function, for example test_free_text_annotation__font_specifier or similar.

@ssjkamei
Copy link
Contributor Author

ssjkamei commented Oct 7, 2024

I changed it. Please help me if there are any problems with the input location.
Sorry for repeating the basic points. Thank you.

Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@stefan6419846 stefan6419846 merged commit 8245fbc into py-pdf:main Oct 7, 2024
16 checks passed
@ssjkamei
Copy link
Contributor Author

ssjkamei commented Oct 7, 2024

@stefan6419846 Please also check the following two issues.

#2084 It can simply be closed.
#2305 Advanced features that allow users to change the internal structure can be closed if that is not what the pypdf requires.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font family, size, and 'style' params not working/changing in AnnotationBuilder's free_text method
2 participants