You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add snapshot test for the textkit layout engine
* Fix hyphenation algorithm
The hyphenation algorithm may change the string (e.g. by removing some characters, namely soft hyphens).
Therefore, calculating the glyphs must come after hyphenation, so that the glyphs match the final string.
Fixes#3018
This was probably broken in #2600.
* Change default hyphenation algorithm to more flexible paradigm
The Hyphenation algorithm should be able to leave soft hyphens in, to
indicate that a hyphen should be placed there if the word breaks there.
* Variable width penalty nodes
The line breaking algorithm needs to distinguish syllables which end with
a soft hyphen from syllables that do not, and only mark a syllable for
adding a hyphen in the former case.
* Ensure zero advanceWidth for soft hyphens in both font and pdfkit
For the line breaking algorithm, soft hyphens should be considered to
have a width of zero, since they are never printed directly (they can
only lead to an inserted hyphen if at the end of a line).
The font package was already doing this correctly, but the pdfkit
package considered the soft hyphen to be the same as a normal hyphen
with an advanceWidth of 333 in Helvetica. Without this change, in some
edge cases the pdfkit would break apart lines already broken apart by
the line breaking algorithm in textkit.
Added tests for both packages to make sure they remain compatible in the
future.
* Consider end-of-line hyphen width in bestFit algorithm
In the best fit line breaking algorithm, the width of the hyphen must
be taken into account, in case one is to be inserted at the end of the line.
This is the most readable change I was able to find to acheive the goal.
Maybe the bestFit algorithm could be optimized in the future, along with
writing extensive tests for corner cases.
* Soft hyphens in the text should not be rendered as hyphens
Therefore, we remove all soft hyphens from the attributed string after
linebreaking is completed, and recalculate the glyphs afterwards.
This way, pdfkit never sees the soft hyphens, and does not mistake them
for normal hyphens.
* Add another test for the textkit layout engine
Tests the functionality of custom word splitting functions
* Add changeset
* Pass builtin hyphenation callback to custom callback
This allows library users to avoid importing the callback themselves,
which probably most of the implementations will want to do.
Fix and rework the hyphenation algorithm, and allow custom word hyphenation algorithms to specify whether a hyphen should be inserted in case the word is wrapped.
7
+
8
+
**Caution**: If you have been using a custom hyphenation callback - which hasn't been working properly since at least version 2.0.21 - then you will need to change your implementation to leave a soft hyphen character (`'\u00AD'`) at the end of syllables where you want react-pdf to insert a hyphen when wrapping lines. Syllables without a final soft hyphen character will still be able to break, but will not produce a hyphen character at the end of the line.
9
+
10
+
This allows you to break correctly on normal hyphens or other special characters in your text. For example, to use the default english-language syllable breaking built into react-pdf, but also break after hyphens naturally occurring in your text (such as is often present in hyperlinks), you could use the following hyphenation callback:
0 commit comments