py-pdf / fpdf2

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

Handle multilingual strings to improve text shaping results (fix #1187) #1193

Closed andersonhc closed 3 weeks ago

andersonhc commented 3 weeks ago

As pointed in #1187, if the text has different languages, harfbuzz will auto-detect and shape using the first script found.

This change includes the Unicode Scripts table into fpdf2 and breaks the input string into different fragments that are shaped individually if multiple scripts are found.

Having fragments being "script aware" will also be useful in the future to implement automatic text wrapping.

Checklist:

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

codecov-commenter commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 99.46524% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.29%. Comparing base (2b866d8) to head (acb6af1). Report is 15 commits behind head on master.

:exclamation: Current head acb6af1 differs from pull request most recent head 45074fd

Please upload reports for the commit 45074fd to get more accurate results.

Files Patch % Lines
fpdf/unicode_script.py 99.43% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1193 +/- ## ========================================== + Coverage 93.25% 93.29% +0.03% ========================================== Files 30 31 +1 Lines 9253 9524 +271 Branches 2104 2135 +31 ========================================== + Hits 8629 8885 +256 - Misses 385 393 +8 - Partials 239 246 +7 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.