Update example to show emojis and clipping

This commit is contained in:
grovesNL 2023-01-26 00:44:29 -03:30 committed by Josh Groves
parent 8c8cfba093
commit 07b04f511a
6 changed files with 21 additions and 3786 deletions

View file

@ -1,3 +0,0 @@
I like to render اللغة العربية in Rust!
عندما يريد العالم أن ‪يتكلّم ، فهو يتحدّث بلغة يونيكود. تسجّل الآن لحضور المؤتمر الدولي العاشر ليونيكود (Unicode Conference)، الذي سيعقد في 10-12 آذار 1997 بمدينة مَايِنْتْس، ألمانيا. و سيجمع المؤتمر بين خبراء من كافة قطاعات الصناعة على الشبكة العالمية انترنيت ويونيكود، حيث ستتم، على الصعيدين الدولي والمحلي على حد سواء مناقشة سبل استخدام يونكود في النظم القائمة وفيما يخص التطبيقات الحاسوبية، الخطوط، تصميم النصوص والحوسبة متعددة اللغات.

View file

@ -1 +0,0 @@
I want more terminals to be able to handle ZWJ sequence emoji characters. For example, the service dog emoji 🐕‍🦺 is actually 3 Unicode characters. Kitty handles this fairly well. All VTE-based terminals, however, show "🐶🦺".

File diff suppressed because it is too large Load diff

View file

@ -70,13 +70,14 @@ async fn run() {
let mut atlas = TextAtlas::new(&device, &queue, swapchain_format);
let mut buffer = Buffer::new(
unsafe { FONT_SYSTEM.as_ref().unwrap() },
Metrics::new(14, 20),
);
buffer.set_size((width as f64 * scale_factor) as i32, (height as f64) as i32);
buffer.set_text(
include_str!("./emoji-zjw.txt"),
Attrs::new().monospaced(true).family(Family::Monospace),
Metrics::new(30, 42),
);
let physical_width = (width as f64 * scale_factor) as i32;
let physical_height = (height as f64 * scale_factor) as i32;
buffer.set_size(physical_width, physical_height);
buffer.set_text("Hello world! 👋\nThis is rendered with 🦅 glyphon 🦁\nThe text below should be partially clipped.\na b c d e f g h i j k l m n o p q r s t u v w x y z", Attrs::new().family(Family::SansSerif));
buffer.shape_until_scroll();
event_loop.run(move |event, _, control_flow| {
@ -105,11 +106,13 @@ async fn run() {
},
&[TextArea {
buffer: &buffer,
left: 10,
top: 10,
bounds: TextBounds {
left: 10,
top: 10,
right: 500,
bottom: 50,
left: 0,
top: 0,
right: 600,
bottom: 160,
},
}],
Color::rgb(255, 255, 255),

View file

@ -86,6 +86,11 @@ impl Default for TextBounds {
pub struct TextArea<'a> {
/// The buffer containing the text to be rendered.
pub buffer: &'a cosmic_text::Buffer<'a>,
/// The bounds of the text area.
/// The left edge of the buffer.
pub left: i32,
/// The top edge of the buffer.
pub top: i32,
/// The visible bounds of the text area. This is used to clip the text and doesn't have to
/// match the `left` and `top` values.
pub bounds: TextBounds,
}

View file

@ -252,8 +252,8 @@ impl TextRenderer {
let details = atlas.glyph(&glyph.cache_key).unwrap();
let mut x = glyph.x_int + details.left as i32;
let mut y = line_y + glyph.y_int - details.top as i32;
let mut x = glyph.x_int + details.left as i32 + text_area.left;
let mut y = line_y + glyph.y_int - details.top as i32 + text_area.top;
let (mut atlas_x, mut atlas_y, content_type) = match details.gpu_cache {
GpuCacheStatus::InAtlas { x, y, content_type } => (x, y, content_type),