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

Bidirectional text overflows buffer instead of wrapping #252

Open
lucieleblanc opened this issue May 6, 2024 · 0 comments
Open

Bidirectional text overflows buffer instead of wrapping #252

lucieleblanc opened this issue May 6, 2024 · 0 comments

Comments

@lucieleblanc
Copy link

lucieleblanc commented May 6, 2024

cosmic-text version: 0.11.2
System info: Ubuntu 22.04, GNOME on Wayland

Hello! I'm an engineer working on Warp terminal, which uses cosmic-text for text layout on Linux. While working on custom prompt support, I noticed the layout_to_buffer function produces lines that overflow the buffer width when given bidirectional text.

I added a test with mixed English and Arabic text to tests/wrap_stability.rs that reproduces the issue on this branch. Here's the snippet:

#[test]
fn wrap_bidirectional() {
	let mut font_system = FontSystem::new();
	let font_size = 14.0;
	let line_height = 20.0;
	let buffer_width = 80.0;

	let metrics = Metrics::new(font_size, line_height);

	let mut plain_buffer = Buffer::new(&mut font_system, metrics);

	let mut buffer = plain_buffer.borrow_with(&mut font_system);

	// Add some text
	buffer.set_wrap(Wrap::WordOrGlyph);
	buffer.set_text("breakfast, إفطار, lunch (غداء) and dinner - عشاء", Attrs::new().family(cosmic_text::Family::Name("Inter")), Shaping::Advanced);

	// Set a size for the text buffer, in pixels
	buffer.set_size(buffer_width, 1000.0);

	let layout_line = buffer.line_layout(0).unwrap().first().unwrap();
	assert!(layout_line.w <= buffer_width, "layout line width ({}) was greater than buffer width ({})", layout_line.w, buffer_width);
}

When run, the above test fails with:

thread 'wrap_bidirectional' panicked at tests/wrap_stability.rs:135:5:
layout line width (97.90201) was greater than buffer width (80)

In Warp, this issue becomes visible when editing mixed-direction text in the input editor. Here's a screenshot with the same text from the test above, where the first Arabic word is cut off:
Screenshot from 2024-05-06 16-15-49

I haven't seen this issue with left-to-right text, only mixed text directions, but it could be related to #219. Is this a known bug? Thank you in advance for your help!

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