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

Support for striketrough text on write_html function #1322

Open
viniciustozzi opened this issue Dec 9, 2024 · 2 comments
Open

Support for striketrough text on write_html function #1322

viniciustozzi opened this issue Dec 9, 2024 · 2 comments

Comments

@viniciustozzi
Copy link

viniciustozzi commented Dec 9, 2024

Please explain your intent
It would be greate to have support for striketrough text on write_html function. Currently it already works for bold, italic and underline.

Describe the solution you'd like
When using write_html() function it is already possible to use tag_styles argument to map the tag <s> to a TextStyle or FontFace, but unfortunately there is no way to set the emphasis to striketrough. Maybe adding a new Text Emphasis for striketrough ("S") would be enough. However I am not sure how to actually render this on the PDF itself.

Additional context
With the following snippet it's possible to see that <b> tag works just fine but when I try with <s> tag it does not work:

from fpdf import FPDF

pdf = FPDF()
pdf.write_html(
    text="<b>Bold Text works </b> <s> but strikethrough does not </s>.",
)
pdf.output("issue_1322.pdf")
@Lucas-C
Copy link
Member

Lucas-C commented Dec 9, 2024

Hi @viniciustozzi

Sure, this an excellent suggestion for a feature!

Pull Requests are welcome to implement this 🙂

First, we could either implement this in HTML2FPDF, or else in the base FPDF class, similarly to how "underlined text" is implemented.

If we chose the second option, "strikethrough" should be part of the GraphicsState.
But another question arise: should it be included in TextEmphasis, that currently combines bold, italics & underline text styling?

IMHO, yes, we should implement strikethrough in exactly the same way that underline is currently implemented.
But it would be very interesting to have other people view on this 🙂
Ping other maintainers @andersonhc & @gmischler

@andersonhc
Copy link
Collaborator

I agree it would be a nice addition and we should implement strikethrough like underline.

We load underline thickness and position from the font's "post" table - with hardcoded values for the core fonts.
I believe the equivalent for strikethrough would be yStrikeoutPosition and yStrikeoutSize on the OS/2 table.

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

No branches or pull requests

3 participants