-
Notifications
You must be signed in to change notification settings - Fork 250
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
Non-breaking space support in multi_cell()
and write_html()
#834
Comments
Some hot-fix for both methods. File HARD_SPACE = "\u00a0"
class Fragment:
...
def add_character(...):
...
if character == SPACE:
...
elif character == HARD_SPACE:
character = SPACE
self.fragments.append(Fragment("", graphics_state, k, url))
# changing active fragment is not necessary I guess,
# space can be at end of the last fragment or first in the new fragment as well
# active_fragment = self.fragments[-1] # TODO: delete me
self.number_of_spaces += 1
elif character == SOFT_HYPHEN and not self.print_sh:
... |
@gmischler : as you have previously worked on this subject, could you have a look this please? 😊 |
Thanks. I have some commit to test, see rysson@db0625a I added For string like with and with I wanted to create PR, but git hooks failed (see #835). |
@rysson, it took me quite a while to figure out that you're actually talking about whitespace getting stretched when justifying text. I can conclude that from a single line of code, but explicitly explaining that at the start might have been helpful... This appears to be a "feature" of how PDF viewers are applying the If we didn't rely on NBSP = "\u00a0"
class CurrentLine:
...
def add_character(...):
...
if character == SPACE:
...
elif character == NBSP:
# PDF viewers ignore NBSP for word spacing with "Tw".
character = SPACE
self.number_of_spaces += 1
elif character == SOFT_HYPHEN and not self.print_sh:
... |
Thank you @gmischler for investigating this |
It's why I told about fixed-width spaces. Sure, I should write it's important in justify, sorry.
I'm totally newbie in PDF, I'm sorry.
Great! Simpler and working :-) So, what next? |
just update your PR accordingly. With regards to that, I recommend to stick with standard terminology (eg. NON_BREAK_SPACE or NBSP instead of HARD_SPACE). |
Thanks, than I create new PR based on @gmischler notes. |
Error details
Incorrect support for non-breaking space (NBSP, hard-space, 0x00a0).
Non-breaking space prevents line breaking and it works fine.
Non-breaking space is not fixed-width at all. I know some old systems still use fixed-width NBSP but all modern browsers not.
NBSP (as Unicode character or
entity) should be variable width space (SpaceHint
?) in theFPDF.write_html()
.The same in the
pdf.multi_cell()
. It could be a compatibility problem if users use it as fixed-width space. Maybe extra option (fixed_width_nbsp=True
)?Minimal code
Environment
Please provide the following information:
fpdf2
version used: 2.7.4 (pip)Also check on GitHub
master
branch.The text was updated successfully, but these errors were encountered: