Try to ensure that using "the width computed during an unconstrained layout" as the width constraint during a relayout produces the same layout. This is useful for certain UI layout algorithms. See https://github.com/pop-os/cosmic-text/issues/134 * Instead of computing the LayoutLine width from the positioned and aligned glyphs, we pass through width computed during line wrapping (unless justified alignment is used, in this case we use the old approach because the use case for measuring the width isn't really applicable to justified text since that will just expand to the provided width). For the produced width to later give the same wrapping results when passed in as the `line_width` it needs to use the same exact float arithmatic that was used to compute the width that is compared against `line_width` when making line wrapping choices. Passing this width through as the LayoutLine width is the most covenient option without making more major changse to the API. Nevertheless, I am imagining that if we get a dedicated measurement method (i.e. that doesn't do the final positioning and alignment of glyphs and which caches `Vec<VisualLine>`), then this width can just be exposed there instead of preservering it in LayoutLine. * Incidentally, this fixes https://github.com/pop-os/cosmic-text/issues/169. * Switch substraction from `fit_x` to checking whether potential addition to the current line width would exceed the `line_width`. This avoids the float error being dependent on the provided `line_width` value. * When eliminating trailing space from the line width, we avoid backtracking with subtraction (which would not give the same exact value due to float error) and instead save the previous width and use that. * If the previous word did not exceed the line_width, we now include a single blank word even if it would cross the width limit since its width won't be counted. This is necessary to get the same wrapping behavior when re-using the measured width (which doesn't count a single trailing blank word). Note, this whitespace logic may be reworked anyway if <https://github.com/pop-os/cosmic-text/issues/155> is addressed. * Change tests to use `opt-level=1` to keep test runtime down. * Add `fonts` folder for fonts used in tests. * Fix an issue where a non-breaking whitespace was assumed to be the start of a section of spaces which included characters that weren't even whitespace. * Add some TODOs about incongruencies between `is_whitespace`, justification, and line breaks. |
||
|---|---|---|
| .github/workflows | ||
| benches | ||
| examples | ||
| fonts | ||
| sample | ||
| screenshots | ||
| src | ||
| tests | ||
| .gitattributes | ||
| .gitignore | ||
| Cargo.toml | ||
| CHANGELOG.md | ||
| ci.sh | ||
| deny.toml | ||
| editor-libcosmic.sh | ||
| editor-orbclient.sh | ||
| editor-test.sh | ||
| LICENSE-APACHE | ||
| LICENSE-MIT | ||
| 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 rustybuzz, 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

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 rustybuzz)
- 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.