From a33f7f1b37782f3ea7ce3185b3a9fc744b7ec60a Mon Sep 17 00:00:00 2001 From: Fey Naomi Schrewe Date: Thu, 10 Sep 2026 06:41:06 +0200 Subject: [PATCH] feat: initial commit --- .gitignore | 1 + Cargo.lock | 210 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 16 ++++ examples/linebreak.rs | 11 +++ src/lib.rs | 21 +++++ 5 files changed, 259 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 examples/linebreak.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..34fc137 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,210 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "az" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be5eb007b7cacc6c660343e96f650fedf4b5a77512399eb952ca6642cf8d13f7" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytemuck" +version = "1.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" + +[[package]] +name = "cc" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "005ec2760ca554fae18df7a11195552ec576cd665632a881bc011d5bb2fd4d80" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "find-msvc-tools" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" + +[[package]] +name = "fixed" +version = "1.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9af2cbf772fa6d1c11358f92ef554cb6b386201210bcf0e91fb7fba8a907fb40" +dependencies = [ + "az", + "bytemuck", + "half", + "typenum", +] + +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] + +[[package]] +name = "hypher" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef68590049bab63a464eee1a1158ac04c6f6613a546d8d90f78636b8b94f171" + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "lua-hyphenate" +version = "0.1.0" +dependencies = [ + "hypher", + "libc", + "mlua-sys", + "text_layout", + "unicode-linebreak", + "unicode-segmentation", + "unicode-width", +] + +[[package]] +name = "mlua-sys" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b806d7ade031f5d6607eae3e283fb034cb795a76247dd0d1ba753c8c42debccf" +dependencies = [ + "cc", + "cfg-if", + "libc", + "pkg-config", +] + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "text_layout" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19cf731187ce440962b4bb166e2bce3c69375f7022500447a84a3cc050d90f7" +dependencies = [ + "bumpalo", + "fixed", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + +[[package]] +name = "unicode-segmentation" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "zerocopy" +version = "0.8.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e015f26 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "lua-hyphenate" +version = "0.1.0" +edition = "2024" + +[lib] +crate-type = [ "cdylib", "lib" ] + +[dependencies] +hypher = "0.1.7" +libc = "0.2.189" +mlua-sys = { version = "0.12.0", features = ["luajit"] } +text_layout = "0.3.0" +unicode-linebreak = "0.1.5" +unicode-segmentation = "1.13.3" +unicode-width = "0.2.2" diff --git a/examples/linebreak.rs b/examples/linebreak.rs new file mode 100644 index 0000000..68bbab0 --- /dev/null +++ b/examples/linebreak.rs @@ -0,0 +1,11 @@ +use lua_hyphenate::layout; + +pub fn main() { + println!( + "{}", + layout( + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tincidunt, lectus a fringilla fringilla, velit purus accumsan nulla, sed vehicula nunc eros eget nibh. Donec leo erat, efficitur vel faucibus sit amet, tristique nec ante. Quisque vestibulum lacinia nisl in iaculis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla ultricies blandit massa ut interdum. Nam non posuere velit. Curabitur magna lorem, eleifend eget tellus eu, accumsan pharetra arcu. Morbi consequat in sapien ut tincidunt. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam metus elit, cursus eu ornare quis, bibendum sollicitudin magna. Donec at ornare tellus. Proin sollicitudin dictum blandit. Duis at ornare felis. Cras lacus sem, congue vel nunc nec, condimentum convallis ex. Sed sed tincidunt justo.", + 30 + ) + ); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..1cdd642 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,21 @@ +use hypher::{Lang, hyphenate}; +use mlua_sys::lua51::lua_State; +use text_layout::{Item, KnuthPlass}; +use unicode_linebreak::linebreaks; + +pub fn layout(s: &str, width: usize) -> String { + let layout = KnuthPlass::::new(); + s.to_string() +} + +pub unsafe extern "C" fn break_line(state: *mut lua_State) -> isize { + 0 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() {} +}