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

Supporting <text> tags from SVG files #1029

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Supporting <text> tags from SVG files #1029

wants to merge 3 commits into from

Conversation

Lucas-C
Copy link
Member

@Lucas-C Lucas-C commented Nov 20, 2023

This is a contribution towards #537

It also including a big refactoring of the text rendering logic,
by introducing a new TextRendererMixin class.
One of the main benefits of this is to reduce the size of fpdf/fpdf.py
and decouple the text rendering logic from FPDF.

Minimal script demonstrating the feature, that works with the current code:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.set_font("Times", size=16)
pdf.image("test/svg/svg_sources/text-samples.svg", w=pdf.epw)
print(pdf.pages[1].contents.decode())
pdf.output("pr_1029.pdf")

@Lucas-C
Copy link
Member Author

Lucas-C commented Nov 20, 2023

Currently this PR only contains a base unit test / SVG test sample file, and some minimal "glue" code.

@gmischler: I think we should wait for your work on TextRegions to be complete before tackling this.

Quoting a comment I made there: https://github.com/py-pdf/fpdf2/blob/svg-text/fpdf/svg.py#L1003:

We should reuse code from the line_break and/or text_region modules to implement this.
We could either:

  1. handle text regions in this module (svg), with a dedicated SVGText class.
  2. handle text regions in the drawing module, maybe by defining a PaintedPath.text() method.

This second option may be the best approach, as we would benefit from the global transformation performed in SVGObject.transform_to_rect_viewport().

But then, we will have to find a way to have PaintedPath objects from the drawing module to benefit from the text rendering logic implemented in other modules, including the font selection mechanism.

How difficult do you expect this to be?

@Lucas-C Lucas-C force-pushed the svg-text branch 2 times, most recently from 3f147c7 to 60c1251 Compare November 20, 2023 11:20
@Lucas-C Lucas-C force-pushed the svg-text branch 2 times, most recently from dddb6ce to 6e9328a Compare January 22, 2025 00:55
@Lucas-C Lucas-C force-pushed the svg-text branch 4 times, most recently from 6e004ee to 4256642 Compare January 24, 2025 11:38
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.

1 participant