pretext icon indicating copy to clipboard operation
pretext copied to clipboard

rich-inline: extra line for a split ZWJ, missing line after an oversized letter followed by SHY

Open ChuanfengZhang opened this issue 1 month ago • 0 comments

I'm seeing two line-count differences from Chrome at 0d102a5c:

Items, all in the same font Pretext lines Chrome lines / block height
['A', '\u200D'] 2 1 / 20.9609375px
['A\u200D'] (control) 1 1 / 20.9609375px
['A\u00AD'] 1 2 / 41.921875px

Moving the ZWJ into a second item adds a zero-width line in Pretext. Chrome keeps it on the line with A, whether it's in the same span or the next one.

For SHY, Chrome places it on a second line. There is no visible glyph there, but the block is two lines tall. Pretext returns one line.

Tested in headed Chromium 156 on macOS, DPR 2, 100% zoom, lang=en. Font: 400 16px Arial; width: 10px; line-height: 20.96px; white-space: pre-wrap. The measured width of A is 10.671875px, so it overflows the box.

The SHY case looks like a smaller reproduction of the known line-edge gap. Is the ZWJ case also covered by an existing item-edge entry?

Reproduction

Run this in a browser test at 0d102a5c, using the functions from that commit's src/rich-inline.ts. Each DOM span corresponds to one item.

const font = '400 16px Arial';
document.documentElement.lang = 'en';
await document.fonts.load(font);
await document.fonts.ready;

for (const parts of [['A', '\u200D'], ['A\u200D'], ['A\u00AD']]) {
  const prepared = prepareRichInline(
    parts.map(text => ({ text, font })), { whiteSpace: 'pre-wrap' },
  );
  const lines = [];
  walkRichInlineLineRanges(prepared, 10, range => {
    lines.push(materializeRichInlineLineRange(prepared, range));
  });

  const host = document.createElement('div');
  host.style.cssText = `font:${font};line-height:20.96px;width:10px;`
    + 'white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;'
    + 'margin:0;padding:0;border:0;';
  for (const text of parts) {
    const span = document.createElement('span');
    span.style.lineHeight = 'inherit';
    span.textContent = text;
    host.append(span);
  }
  document.body.append(host);
  console.log({
    parts: JSON.stringify(parts),
    pretextLineCount: lines.length, lines,
    domHeight: host.getBoundingClientRect().height,
  });
  host.remove();
}

ChuanfengZhang avatar Oct 27 '26 10:10 ChuanfengZhang