>>106866954
>>106867001
>>106867476
you get EVERYTHING with cosmic-text, including advanced shaping of course.
cargo new render-cosmic
cargo add image --no-default-features --features=png
cargo add cosmic-text
main
use cosmic_text::{Attrs, Buffer, Color, Family, FontSystem, Metrics, Shaping, SwashCache, Weight};
use image::{RgbaImage, GenericImage, ImageFormat, Rgba};
fn main() {
let mut font_system = FontSystem::new();
let mut swash_cache = SwashCache::new();
let metrics = Metrics::new(128.0, 128.0);
let mut buffer = Buffer::new(&mut font_system, metrics);
let mut buffer = buffer.borrow_with(&mut font_system);
let (w,h) = (1400, 400);
let mut image = RgbaImage::new(w, h);
buffer.set_size(Some(w as f32), Some(h as f32));
let attrs = Attrs::new()
.family(Family::Name("Noto Sans"))
.weight(Weight::MEDIUM);
buffer.set_text(" 0 1 2 3 4 5 6 7 8 9 0 -+=\n Joined RTL text below:\n اللغة العربية\n", &attrs, Shaping::Advanced);
buffer.shape_until_scroll(true);
let def_color = Color::rgb(0xFF, 0x00, 0x00);
buffer.draw(&mut swash_cache, def_color, |x, y, w, h, c| {
if x >= 0 && y >= 0 {
let c = Rgba([c.r(), c.g(), c.b(), c.a()]);
let (x, y) = (u32::try_from(x).unwrap(), u32::try_from(y).unwrap());
let mut sub_image = image.sub_image(x, y, w, h);
(0..w) .for_each(|i_x| {
(0..h).for_each(|i_y| {
sub_image.put_pixel(i_x, i_y, c)
})
});
}
});
image.save_with_format("cosmic.png", ImageFormat::Png)
.expect("save gray image as png");
}
and sizes
cargo build --release
% du -sh target
161M target
% du -sh target/release/render-cosmic
3.3M target/release/render-cosmic
% strip target/release/render-cosmic
% du -sh target/release/render-cosmic
2.8M target/release/render-cosmic
loaded libraries...