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

Ligatures (possibly character joiners in general) broken in 3.13.x #2028

Closed
Eugeny opened this issue Apr 28, 2019 · 14 comments · Fixed by #2035
Closed

Ligatures (possibly character joiners in general) broken in 3.13.x #2028

Eugeny opened this issue Apr 28, 2019 · 14 comments · Fixed by #2035
Assignees
Labels
type/bug Something is misbehaving

Comments

@Eugeny
Copy link
Member

Eugeny commented Apr 28, 2019

Since 3.13.0-beta1, xterm-addon-ligatures produces weird spacing instead of actual joined chars - often in a different location too:

image

vs

image

xterm-addon-ligatures's joiner implementation still returns correct indexes, so there must be something going on in xterm itself.

@jerch
Copy link
Member

jerch commented Apr 28, 2019

@Eugeny This is prolly related to the new CellData type that comes with true color support. Can you debug it and give us the raw data sent from the pty?

@Eugeny
Copy link
Member Author

Eugeny commented Apr 28, 2019

Here it is (JSON):

"\u001b[1m\u001b[7m%\u001b[27m\u001b[1m\u001b[0m                                                                                \r \r\u001b]2;~\u0007\u001b]1;~\u0007\r\u001b[0m\u001b[27m\u001b[24m\u001b[J\u001b[39m\u001b[0m\u001b[49m\u001b[40m\u001b[39m eugene@Eugenes-MBP \u001b[44m\u001b[30m\u001b[30m ~ \u001b[49m\u001b[34m\u001b[39m \u001b[K\u001b[?1h\u001b=\u001b[?2004h"

@Eugeny
Copy link
Member Author

Eugeny commented Apr 28, 2019

It starts breaking down in simplest outputs actually:

"\u001b[?1034hEugenes-MBP:~ eugene$ ->"

@jerch
Copy link
Member

jerch commented Apr 28, 2019

And which one should join? Only the -> sequence I guess?

@Eugeny
Copy link
Member Author

Eugeny commented Apr 28, 2019

In this case, only ->.
The font is Fira Code Regular

@Eugeny
Copy link
Member Author

Eugeny commented Apr 28, 2019

The text segment given to the joiner is " ->", and the range returned is [1, 3]

@jerch
Copy link
Member

jerch commented Apr 28, 2019

Hmm weird, cannot repro it, also the returned range seems good to me (I dont have this font installed thus I can only test the returned range in the renderer phase) Which renderer are you using? Imho only the canvas renderer supports the joiner atm.

@Eugeny
Copy link
Member Author

Eugeny commented Apr 28, 2019

I'm using canvas renderer. I know it's not exactly the minimal reproducible example, but you can grab the latest Terminus build (https://github.com/Eugeny/terminus/releases/tag/v1.0.75)

@jerch
Copy link
Member

jerch commented Apr 28, 2019

@Eugeny With your latest build v1.0.75 the screen stays blank if I enable ligature support. Not sure if I am doing it wrong...

Edit: Installing FiraCode fixed it.

@jerch
Copy link
Member

jerch commented Apr 28, 2019

@Eugeny Found the bug - joined chars are not handled by the atlas, this line needs an additional check for joined chars to enter the uncached path:

if (cell.isFgRGB() || cell.isBgRGB()) {

Can you check if this works after adding a || cell.combinedData clause? Note that this is not yet the real fix, for a real fix we might have to carry forward a joined flag. @Tyriar How does the cache currently deal with combined chars? Are they always drawn uncached? If so we might get away with this simple check against cell.combinedData.

@jerch jerch added area/renderer type/bug Something is misbehaving labels Apr 28, 2019
@jerch
Copy link
Member

jerch commented Apr 28, 2019

Just saw that the old implementation without CellData used Infinity as value for code to tell the atlas that it cannot be cached. With CellData thats not possible anymore (as it relies on integer conversions under the hood). Thus I replaced Infinity with 0xFFFFFF, but now the atlas thinks that it has a cache value for it.
I see several ways from here to fix it, either:

  • explicit cast 0xFFFFFF to Infinity on cell.getCode()
  • tell the atlas to skip 0xFFFFFF
  • carry an explicit join flag forward to the cached/uncached code (maybe as member on CellData?)
  • stick with the cell.combinedData test (only works if the atlas never tries to cache combined things)

@Tyriar Any thoughts on this, which way to go?

@Tyriar
Copy link
Member

Tyriar commented Apr 29, 2019

Doesn't it just cache ascii?

private _isCached(glyph: IGlyphIdentifier, colorIndex: number): boolean {
const isAscii = glyph.code < 256;

private _canCache(glyph: IGlyphIdentifier): boolean {
// Only cache ascii and extended characters for now, to be safe. In the future, we could do
// something more complicated to determine the expected width of a character.
//
// If we switch the renderer over to webgl at some point, we may be able to use blending modes
// to draw overlapping glyphs from the atlas:
// https://github.com/servo/webrender/issues/464#issuecomment-255632875
// https://webglfundamentals.org/webgl/lessons/webgl-text-texture.html
return glyph.code < 256;
}

@jerch
Copy link
Member

jerch commented Apr 29, 2019

@Tyriar Yeah just rechecked - the problem is caused by a simplification I have done in CellData.setFromCharData for easier test writing (0xFFFFFF is not applied, instead code is calculated from the first char in cell.getChars()). In fact the CharData to CellData conversion was meant to be removed from the active code base and only stay in tests, must have overlooked it for the joiner in TextRenderLayer._forEachCell.

@Eugeny
Copy link
Member Author

Eugeny commented May 6, 2019

@Tyriar let me know when you'll push the next beta to NPM and I'll add it to Terminus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is misbehaving
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants