* feat: add Ellipsize enum * chore: API changes needed for ellipsize Decided not to change "layout()" function for now to avoid breaking the interface. For now. * chore: shape ellipsis * feat: Ellipsize::Start Since it can only have 1 line, it's easier to implement. * DROPME: temporarily change rich-text for testing * test(ellipsize): Testing Ellipsize::Start Long text in small buffer should produce ellipsis glyphs * fix: do not need font_system anymore We moved ellipsis shaping elsewhere so no need to pass font_system to layout function (which also was recreating a new one in the tests every time making them take forever). * feat: Ellipsize::End * improv(ellipsize): use a single ellipsis shape * improv: Ellipsie::End && Wrap::None There is no need to layout the whole line if it's not going to fit. * fix: mixed bidi text when Ellipsize::End && Wrap::None * chore: clean up and simplify when line.RTL==span.RTL * fix(ellipsize): last word is not (word_count -1) if iter().rev() * refactor(layout): extract the layout algorithm to make it more readable * improv(ellipsize): Ellipsize::Start && Wrap::None we iterate in reverse and only layout what's going to be visible * Revert: delete the previous approach of post processing ellipsis * doc: explain the interaction between Ellipsize and Wrap * chore: lower the scope * feat: Ellipsize the last line of a paragraph For now only the number of lines is supported * fix: clear ellipsized field on visual lines This was causing ellipsis to show on random lines * chore: remove old tests will add better tests soon * chore: clean up changes from previous attempt * fix: consider the ellipsis width when doing alignment * feat(ellipsize): add `Height` limit to `Ellipsize` * fix: ellipsize the start of the last line correctly * fix: ellipsize at the start of mixed bidi lines * feat: Ellipsize::Middle * fix: consider ellipsize::middle when calculating alignment correction * refactor: improve readability * refactor: deduplicate "fit_glyphs" * refactor: combine backward and forward layout into one (wip) * fix: Backward works in the unified layout_spans * chore: clean up * fix: Ellipsize::Middle * fix: handle large words in bidi boundaries * chore: clean up and some refactoring * fix: ellipsis is now the same level as the surrounding text * fix: try to fit more when ellipsizing::middle * improv: ellipsis now have the same level as the neighbors This makes ellipsized RTL text inside a LTR line more readable. before: Hello سلام...خوبی؟ Hello خولی؟...سلام * fix: some extra words were being rendered in Ellipsize::Middle This was causing the last word (if it's not the same level as the rest) to be rendered outside the buffer. * test: a few test cases for ellipsize * fix: assign the correct byte range to ellipsis this should fix the panic when selecting or clicking on or near the ellipsis in the editor. |
||
|---|---|---|
| .github/workflows | ||
| benches | ||
| examples | ||
| fonts | ||
| sample | ||
| screenshots | ||
| src | ||
| tests | ||
| .gitattributes | ||
| .gitignore | ||
| Cargo.toml | ||
| CHANGELOG.md | ||
| ci.sh | ||
| deny.toml | ||
| editor-test.sh | ||
| editor.sh | ||
| LICENSE-APACHE | ||
| LICENSE-MIT | ||
| multiview.sh | ||
| README.md | ||
| redoxer.sh | ||
| rich-text.sh | ||
| terminal.sh | ||
| test.sh | ||
COSMIC Text
Pure Rust multi-line text handling.
COSMIC Text provides advanced text shaping, layout, and rendering wrapped up into a simple abstraction. Shaping is provided by HarfRust, and supports a wide variety of advanced shaping operations. Rendering is provided by swash, which supports ligatures and color emoji. Layout is implemented custom, in safe Rust, and supports bidirectional text. Font fallback is also a custom implementation, reusing some of the static fallback lists in browsers such as Chromium and Firefox. Linux, macOS, and Windows are supported with the full feature set. Other platforms may need to implement font fallback capabilities.
Screenshots
Arabic translation of Universal Declaration of Human Rights

Hindi translation of Universal Declaration of Human Rights

Simplified Chinese translation of Universal Declaration of Human Rights

View Universal Declaration of Human Rights on OHCHR
Roadmap
The following features must be supported before this is "ready":
- Font loading (using fontdb)
- Preset fonts
- System fonts
- Text styles (bold, italic, etc.)
- Per-buffer
- Per-span
- Font shaping (using HarfRust)
- Cache results
- RTL
- Bidirectional rendering
- Font fallback
- Choose font based on locale to work around "unification"
- Per-line granularity
- Per-character granularity
- Font layout
- Click detection
- Simple wrapping
- Wrapping with indentation
- No wrapping
- Ellipsize
- Font rendering (using swash)
- Cache results
- Font hinting
- Ligatures
- Color emoji
- Text editing
- Performance improvements
- Text selection
- Can automatically recreate https://unicode.org/udhr/ without errors (see below)
- Bidirectional selection
- Copy/paste
- no_std support (with
default-features = false)- no_std font loading
- no_std shaping
- no_std layout
- no_std rendering
The UDHR (Universal Declaration of Human Rights) test involves taking the entire
set of UDHR translations (almost 500 languages), concatenating them as one file
(which ends up being 8 megabytes!), then via the editor-test example,
automatically simulating the entry of that file into cosmic-text per-character,
with the use of backspace and delete tested per character and per line. Then,
the final contents of the buffer is compared to the original file. All of the
106746 lines are correct.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.