py-pdf / fpdf2

Simple PDF generation for Python
https://py-pdf.github.io/fpdf2/
GNU Lesser General Public License v3.0
1.12k stars 253 forks source link

Text shaping does not work with `text()` #1265

Closed bmiklautz closed 1 month ago

bmiklautz commented 2 months ago

When using text() with shaping enabled like documented in https://py-pdf.github.io/fpdf2/Text.html and https://py-pdf.github.io/fpdf2/TextShaping.html the created text isn't shaped.

Minimal code

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font('khmer', '', 'NotoSansKhmer-Regular.ttf')
pdf.set_font('khmer', size=32)
pdf.set_text_shaping(True)
pdf.text(20,100, text="ភាសាខ្មែរ")

pdf.set_xy(20,110)
pdf.cell(text="ភាសាខ្មែរ")

pdf.set_xy(20,130)
pdf.write(None, text="ភាសាខ្មែរ")

pdf.output("hello_world.pdf")

In the example Noto Sans Khmer was used (can be downloaded from https://fonts.google.com/noto/specimen/Noto+Sans+Khmer) but the problem occurs with other fonts as well.

The following screenshot shows the output of the example. Text placed with write() and cell() is represented correctly but text() (first line) isn't. Screenshot 2024-09-20 at 12 19 23

Environment Please provide the following information:

Thank you for your efforts and work on fpdf2.

andersonhc commented 1 month ago

Hi @bmiklautz,

The text() method is kept on the codebase for backwards compatibility, but it lacks many of the features available in write(), cell(), and multicell() like markdown and text shaping.

We could definitely add this information on our documentation to avoid confusion. Let me know if you're interested in submitting a PR.

bmiklautz commented 1 month ago

@andersonhc thank you for your answer. I've created #1266.