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

Hyphenation on soft hyphens is broken #3018

Open
wojtekmaj opened this issue Dec 31, 2024 · 0 comments
Open

Hyphenation on soft hyphens is broken #3018

wojtekmaj opened this issue Dec 31, 2024 · 0 comments

Comments

@wojtekmaj
Copy link
Contributor

wojtekmaj commented Dec 31, 2024

Describe the bug

Text with unicode shy characters doesn't seem to be properly split, regardless whether custom hyphenation callback has been provided or not.

Furthermore, when custom hyphenator (splitting the text on shy) is provided, the text appears to be cut - and the number of characters cut from the text corresponds to the number of soft hyphens found in the text:

Font.registerHyphenationCallback(word => word.split('\u00ad'));

When hyphenation is disabled by providing an "empty" hyphenation callback, the text is rendered in one line with shy characters visible, which should not be the case:

Font.registerHyphenationCallback(word => [word])

After investigation I've noticed that the number of characters from the hyphenation callback must match the input length exactly in order for the text not to be cut. This, however, just like not providing custom hyphenation callback, causes double hyphens:

Font.registerHyphenationCallback(
  (word) => {
    const parts = [];
    let part = '';
    for (let i = 0; i < word.length; i++) {
      const char = word[i];
      if (char === '\u00ad') {
        parts.push(part + char);
        part = '';
      } else {
        part += char;
      }
    }
    if (part) {
      parts.push(part);
    }
    return parts;
  }
);

To Reproduce

const shy = '\u00ad';

const Test = () => (
  <Document>
    <Page style={styles.body}>
      <Text style={styles.text}>{`Potentieel broeikas${shy}gas${shy}emissie${shy}rapport`}</Text>
    </Page>
  </Document>
);

const styles = StyleSheet.create({
  body: { padding: 20 },
  text: {
    width: 100,
    border: '1px solid red',
  },
});

Font.registerHyphenationCallback(
  (word) => console.log(word, '=>', word.split('\u00ad')) || word.split('\u00ad'),
);

ReactPDF.render(<Test />);

https://v4.react-pdf.org/repl?code=3187b0760ce02e004101604f18178607200e815c00cb810c0137406e00a1cd1258015014da546002804a5403e57c98600780088860d802dbd30513af3e020028100e6f4e1444006de8a00ded13630074008c41144017c65cb9fc1800f58fab6ee746a3d47567400379203ca4012de9e834618c009c41e88201ac08200048f4902c951252112de8c482202042b2d32208001cca4122a07c2df801e81da564f81b1455ac05eb854424a464d828a9c098dc21980195d4b427e142a10d8123e8083c5875654dcc00b8607460cb888882c09576009970602c0069643d1d76366c01dc8288a1e1760119f0ee6d4c91223d122bb7437ccaf63808034ef1832c48ff6b9dc2c834a000c5c00b65929f21e488002510653998156417000184081a0d31808c0388b1642c17954881c14371a810187d10c1a1012959ec9b860b9e8315b2818608195615016160f084121b038001f0d4c1a544597ca828ae57e188e8361dcd1e400128ad805079209d186659818191161d918b07aa70d1400000

Expected behavior

image

Screenshots

Split hyphenation:

image

No hyphenation:

image

Fancy hyphenation:

image

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • React-pdf version: 4.1.6
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

No branches or pull requests

1 participant