feat(dom): multi-width unicode character support#121
feat(dom): multi-width unicode character support#121Wybxc wants to merge 1 commit intoratatui:mainfrom
Conversation
|
neat, i'll take a closer look at it tomorrow.
are you positive these glyphs are actually coming from Maple Mono CN and not a fallback? i've had similar issues when processing fonts - when the requested glyph doesn't exist, it'll look it up in related fonts (and this tends to result in mismatched font metrics). |
Well, Maple Mono CN does not contain glyphs for Korean Hangul or emojis, which is the real cause of the misalignment. However, it still highlights the issue that users must choose fonts carefully to ensure proper font metrics. |
junkdog
left a comment
There was a problem hiding this comment.
thanks for submitting! this is indeed addressing a pretty severe shortcoming in ratzilla.
i left a couple of comments, but overall it looks good!
| thiserror = "2.0.12" | ||
| bitvec = { version = "1.0.1", default-features = false, features = ["alloc", "std"] } | ||
| beamterm-renderer = "0.1.1" | ||
| unicode-width = "0.2.0" |
There was a problem hiding this comment.
there's a 0.2.1 release of unicode-width
| } | ||
|
|
||
| pre { | ||
| font-family: "Maple Mono NF CN", monospace; |
| "你好,世界!", | ||
| "世界、こんにちは。", | ||
| // "헬로우 월드!", | ||
| // "👨💻👋🌐", |
There was a problem hiding this comment.
ah, ofc "As a result, misalignment may occur when displaying Korean text or emojis." - what about enforcing the width as width * 2 for double-width symbols instead of calculating it from metrics - how does it look?
| // "헬로우 월드!", | ||
| // "👨💻👋🌐", | ||
| ] | ||
| .join("\n"), |
| let mut line_cells: Vec<Element> = Vec::new(); | ||
| let mut hyperlink: Vec<Cell> = Vec::new(); | ||
| let mut hyperlink: Vec<(Cell, bool)> = Vec::new(); | ||
| let mut skip = 0; |
There was a problem hiding this comment.
shouldn't skip be a boolean value ? either the next cell renders as usual or it is skipped/hidden.
are there any symbols extending more than double-width - if we stick to terminals?
| } | ||
| } else { | ||
| let span = create_span(&self.document, cell)?; | ||
| let span = create_span(&self.document, cell, overwritten)?; |
There was a problem hiding this comment.
maybe it would be clearer to have the old create_span() as-is and add a create_hidden_span(document); it also doesn't require a ref to cell, since it's only used for reading Cell::symbol. what do you think?
| let mut skip = 0; | ||
| for (i, cell) in line.iter().enumerate() { | ||
| let overwritten = skip > 0; | ||
| skip = std::cmp::max(skip, cell.symbol().width()).saturating_sub(1); |
There was a problem hiding this comment.
would it make sense to cache the width of all encountered symbols? cell.symbol().width() looks like it's could be fairly expensive if, for example, scrolling large portions of text at once.
| /// accordingly. | ||
| fn update_grid(&mut self) -> Result<(), Error> { | ||
| for (y, line) in self.buffer.iter().enumerate() { | ||
| let mut skip = 0; |
There was a problem hiding this comment.
same comment applies here about skip maybe being a boolean
does this behavior only trigger when there are double-width symbols? would be nice if we could get it resolved before merging. |
* wip: fix missalignement and glitch with fullwidth char for DOM back see #135 (comment) * fix: multiple width glyph support for DomBackend for now, breaking cursor and resize #135 * feat: get buffer size from utils * fix: fix resize for DomBackend #135 * fix: cursor for DomBackend * feat(examples): add fullwidth glyph in demo2 emails * feat: unicode example from #121 * chore: don't mind hyperlinks - expand unicode example * fix: avoiding vertical flickering * fix: unicode example name and removing external css * fix: removing unecessary cursor attribute * refactor: custom type for css attribute * perf: avoid calling width method for ascii char * fix: prevent OOB access * style: update rustdoc comment * refactor: remove unecessary temp vector * refactor: simplify the update_css_field function * test: update_css_field util function * ops: test targetting wasm32 using wasm-pack * fix build for unicode example * style: style test * ops: install wasm-pack from source * refactor: remove unnecessary import * ops: install wasm-pack with taiki-e install action * style: import to the top, docstrings * build: don't specify a version range for unicode-width * refactor: get cells by reference instead of cloning them

This Pull Request introduces functionality to properly display multi-width Unicode characters (such as Chinese characters and Japanese kana) in
DomBackend. It sets the cell following a multi-width Unicode character todisplay: none, ensuring the correct width is maintained.Limitations: