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

Safari does not connect scripts / apply opentype font features / kerning to text created with createTextNode #216

Open
kontur opened this issue Mar 28, 2024 · 1 comment

Comments

@kontur
Copy link

kontur commented Mar 28, 2024

Unlike other browser, Safari seems to create a separate text renderer element for each text node when created with document.createTextNode, with the result that kerning or opentype font features do not get applied to any typed out text. This also means connected scripts (like Arabic) or complex scripts (like Devanagari) will render as individual glyphs instead of properly shaping :(

The subsequent onCreateTextNode cannot be used to circumvent this (e.g. with node.innerText += ...) because the node is created either way.

After typing states:

Arabic in Firefox/Chrome connected properly:
Screenshot 2024-03-28 at 11 37 13

Arabic in Safari rendered as individual letters:
Screenshot 2024-03-28 at 11 37 33

Stylistic set transformations applied in Firefox/Chrome correctly:
Screenshot 2024-03-28 at 11 37 55

Stylistic sets failing to render in Safari because they are evaluated as individual letters:
Screenshot 2024-03-28 at 11 37 46

A "naive" solution would be use of innerText:

if (textNodeToUse) {
  if (node) {
    node.innerHTML += character;
  } else {
    _this.state.elements.wrapper.innerHTML += character
  }
}

I do not know how or what is the reasoning for using textNodes otherwise, but as long as Safari mistreats the text the current approach is fatal.

@kontur
Copy link
Author

kontur commented Mar 28, 2024

At the very least, output with innerText instead of createTextNode should be an option, or a custom method could be passed to overwrite the default method of appending text to the wrapper node.

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