Skip to content

Commit 2805284

Browse files
committed
Updated to latest cosmic-text
2 parents ae29d42 + e2adc1e commit 2805284

File tree

14 files changed

+866
-726
lines changed

14 files changed

+866
-726
lines changed

Cargo.toml

+61-60
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,61 @@
1-
[package]
2-
name = "cosmic-text"
3-
description = "Pure Rust multi-line text handling"
4-
version = "0.9.0"
5-
authors = ["Jeremy Soller <[email protected]>"]
6-
edition = "2021"
7-
license = "MIT OR Apache-2.0"
8-
documentation = "https://docs.rs/cosmic-text/latest/cosmic_text/"
9-
repository = "https://github.com/pop-os/cosmic-text"
10-
11-
[dependencies]
12-
fontdb = { version = "0.14.1", default-features = false }
13-
libm = "0.2.6"
14-
log = "0.4.17"
15-
aliasable = "0.1.3"
16-
rustybuzz = { version = "0.8.0", default-features = false, features = ["libm"] }
17-
swash = { version = "0.1.6", optional = true }
18-
syntect = { version = "5.0.0", optional = true }
19-
sys-locale = { version = "0.3.0", optional = true }
20-
unicode-linebreak = "0.1.4"
21-
unicode-script = "0.5.5"
22-
unicode-segmentation = "1.10.0"
23-
rangemap = "1.2.0"
24-
hashbrown = { version = "0.14.0", optional = true, default-features = false }
25-
rustc-hash = { version = "1.1.0", default-features = false }
26-
27-
[dependencies.unicode-bidi]
28-
version = "0.3.8"
29-
default-features = false
30-
features = ["hardcoded-data"]
31-
32-
[features]
33-
default = ["std", "swash"]
34-
no_std = [
35-
"rustybuzz/libm",
36-
"hashbrown",
37-
]
38-
std = [
39-
"fontdb/std",
40-
"fontdb/fs",
41-
"rustybuzz/std",
42-
"sys-locale",
43-
"unicode-bidi/std",
44-
]
45-
vi = ["syntect"]
46-
wasm-web = ["sys-locale?/js"]
47-
warn_on_missing_glyphs = []
48-
fontconfig = ["fontdb/fontconfig"]
49-
50-
[[bench]]
51-
name = "layout"
52-
harness = false
53-
54-
[workspace]
55-
members = [
56-
"examples/*",
57-
]
58-
59-
[dev-dependencies]
60-
criterion = { version = "0.5.1", default-features = false, features = ["cargo_bench_support"] }
1+
[package]
2+
name = "cosmic-text"
3+
description = "Pure Rust multi-line text handling"
4+
version = "0.9.0"
5+
authors = ["Jeremy Soller <[email protected]>"]
6+
edition = "2021"
7+
license = "MIT OR Apache-2.0"
8+
documentation = "https://docs.rs/cosmic-text/latest/cosmic_text/"
9+
repository = "https://github.com/pop-os/cosmic-text"
10+
rust-version = "1.65"
11+
12+
[dependencies]
13+
fontdb = { version = "0.14.1", default-features = false }
14+
libm = "0.2.7"
15+
log = "0.4.20"
16+
rustybuzz = { version = "0.10.0", default-features = false, features = ["libm"] }
17+
swash = { version = "0.1.8", optional = true }
18+
syntect = { version = "5.1.0", optional = true }
19+
sys-locale = { version = "0.3.1", optional = true }
20+
unicode-linebreak = "0.1.5"
21+
unicode-script = "0.5.5"
22+
unicode-segmentation = "1.10.1"
23+
rangemap = "1.3.0"
24+
hashbrown = { version = "0.14.0", optional = true, default-features = false }
25+
rustc-hash = { version = "1.1.0", default-features = false }
26+
self_cell = "1.0.1"
27+
28+
[dependencies.unicode-bidi]
29+
version = "0.3.13"
30+
default-features = false
31+
features = ["hardcoded-data"]
32+
33+
[features]
34+
default = ["std", "swash"]
35+
no_std = ["rustybuzz/libm", "hashbrown"]
36+
std = [
37+
"fontdb/std",
38+
"fontdb/fs",
39+
"rustybuzz/std",
40+
"sys-locale",
41+
"unicode-bidi/std",
42+
]
43+
vi = ["syntect"]
44+
wasm-web = ["sys-locale?/js"]
45+
warn_on_missing_glyphs = []
46+
fontconfig = ["fontdb/fontconfig"]
47+
48+
[[bench]]
49+
name = "layout"
50+
harness = false
51+
52+
[workspace]
53+
members = ["examples/*"]
54+
55+
[dev-dependencies]
56+
criterion = { version = "0.5.1", default-features = false, features = [
57+
"cargo_bench_support",
58+
] }
59+
60+
[profile.test]
61+
opt-level = 1

examples/editor-libcosmic/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ impl Application for Window {
269269

270270
let mut editor = self.editor.lock().unwrap();
271271

272+
#[cfg(not(feature = "vi"))]
272273
// Update the syntax color theme
273274
match theme {
274275
"Light" => editor.update_theme("base16-ocean.light"),

examples/rich-text/src/main.rs

+70-95
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

33
use cosmic_text::{
4-
Action, Attrs, AttrsList, Buffer, BufferLine, Color, Edit, Editor, Family, FontSystem, Metrics,
5-
Shaping, Style, SwashCache, Weight,
4+
Action, Attrs, Buffer, Color, Edit, Editor, Family, FontSystem, Metrics, Shaping, Style,
5+
SwashCache, Weight,
66
};
77
use orbclient::{EventOption, Renderer, Window, WindowFlag};
88
use std::{
@@ -36,8 +36,7 @@ fn main() {
3636
)
3737
.unwrap();
3838

39-
let mut editor = Editor::new(Buffer::new(
40-
&mut font_system,
39+
let mut editor = Editor::new(Buffer::new_empty(
4140
Metrics::new(32.0, 44.0).scale(display_scale),
4241
));
4342

@@ -52,99 +51,75 @@ fn main() {
5251
let mono_attrs = attrs.family(Family::Monospace);
5352
let comic_attrs = attrs.family(Family::Name("Comic Neue"));
5453

55-
editor.buffer_mut().lines.clear();
56-
57-
let lines: &[&[(&str, Attrs)]] = &[
58-
&[
59-
("B", attrs.weight(Weight::BOLD)),
60-
("old ", attrs),
61-
("I", attrs.style(Style::Italic)),
62-
("talic ", attrs),
63-
("f", attrs),
64-
("i ", attrs),
65-
("f", attrs.weight(Weight::BOLD)),
66-
("i ", attrs),
67-
("f", attrs.style(Style::Italic)),
68-
("i ", attrs),
69-
],
70-
&[
71-
("Sans-Serif Normal ", attrs),
72-
("Sans-Serif Bold ", attrs.weight(Weight::BOLD)),
73-
("Sans-Serif Italic ", attrs.style(Style::Italic)),
74-
(
75-
"Sans-Serif Bold Italic",
76-
attrs.weight(Weight::BOLD).style(Style::Italic),
77-
),
78-
],
79-
&[
80-
("Serif Normal ", serif_attrs),
81-
("Serif Bold ", serif_attrs.weight(Weight::BOLD)),
82-
("Serif Italic ", serif_attrs.style(Style::Italic)),
83-
(
84-
"Serif Bold Italic",
85-
serif_attrs.weight(Weight::BOLD).style(Style::Italic),
86-
),
87-
],
88-
&[
89-
("Mono Normal ", mono_attrs),
90-
("Mono Bold ", mono_attrs.weight(Weight::BOLD)),
91-
("Mono Italic ", mono_attrs.style(Style::Italic)),
92-
(
93-
"Mono Bold Italic",
94-
mono_attrs.weight(Weight::BOLD).style(Style::Italic),
95-
),
96-
],
97-
&[
98-
("Comic Normal ", comic_attrs),
99-
("Comic Bold ", comic_attrs.weight(Weight::BOLD)),
100-
("Comic Italic ", comic_attrs.style(Style::Italic)),
101-
(
102-
"Comic Bold Italic",
103-
comic_attrs.weight(Weight::BOLD).style(Style::Italic),
104-
),
105-
],
106-
&[
107-
("R", attrs.color(Color::rgb(0xFF, 0x00, 0x00))),
108-
("A", attrs.color(Color::rgb(0xFF, 0x7F, 0x00))),
109-
("I", attrs.color(Color::rgb(0xFF, 0xFF, 0x00))),
110-
("N", attrs.color(Color::rgb(0x00, 0xFF, 0x00))),
111-
("B", attrs.color(Color::rgb(0x00, 0x00, 0xFF))),
112-
("O", attrs.color(Color::rgb(0x4B, 0x00, 0x82))),
113-
("W ", attrs.color(Color::rgb(0x94, 0x00, 0xD3))),
114-
("Red ", attrs.color(Color::rgb(0xFF, 0x00, 0x00))),
115-
("Orange ", attrs.color(Color::rgb(0xFF, 0x7F, 0x00))),
116-
("Yellow ", attrs.color(Color::rgb(0xFF, 0xFF, 0x00))),
117-
("Green ", attrs.color(Color::rgb(0x00, 0xFF, 0x00))),
118-
("Blue ", attrs.color(Color::rgb(0x00, 0x00, 0xFF))),
119-
("Indigo ", attrs.color(Color::rgb(0x4B, 0x00, 0x82))),
120-
("Violet ", attrs.color(Color::rgb(0x94, 0x00, 0xD3))),
121-
("U", attrs.color(Color::rgb(0x94, 0x00, 0xD3))),
122-
("N", attrs.color(Color::rgb(0x4B, 0x00, 0x82))),
123-
("I", attrs.color(Color::rgb(0x00, 0x00, 0xFF))),
124-
("C", attrs.color(Color::rgb(0x00, 0xFF, 0x00))),
125-
("O", attrs.color(Color::rgb(0xFF, 0xFF, 0x00))),
126-
("R", attrs.color(Color::rgb(0xFF, 0x7F, 0x00))),
127-
("N", attrs.color(Color::rgb(0xFF, 0x00, 0x00))),
128-
],
129-
&[(
130-
"生活,삶,जिंदगी 😀 FPS",
54+
let spans: &[(&str, Attrs)] = &[
55+
("B", attrs.weight(Weight::BOLD)),
56+
("old ", attrs),
57+
("I", attrs.style(Style::Italic)),
58+
("talic ", attrs),
59+
("f", attrs),
60+
("i ", attrs),
61+
("f", attrs.weight(Weight::BOLD)),
62+
("i ", attrs),
63+
("f", attrs.style(Style::Italic)),
64+
("i \n", attrs),
65+
("Sans-Serif Normal ", attrs),
66+
("Sans-Serif Bold ", attrs.weight(Weight::BOLD)),
67+
("Sans-Serif Italic ", attrs.style(Style::Italic)),
68+
(
69+
"Sans-Serif Bold Italic\n",
70+
attrs.weight(Weight::BOLD).style(Style::Italic),
71+
),
72+
("Serif Normal ", serif_attrs),
73+
("Serif Bold ", serif_attrs.weight(Weight::BOLD)),
74+
("Serif Italic ", serif_attrs.style(Style::Italic)),
75+
(
76+
"Serif Bold Italic\n",
77+
serif_attrs.weight(Weight::BOLD).style(Style::Italic),
78+
),
79+
("Mono Normal ", mono_attrs),
80+
("Mono Bold ", mono_attrs.weight(Weight::BOLD)),
81+
("Mono Italic ", mono_attrs.style(Style::Italic)),
82+
(
83+
"Mono Bold Italic\n",
84+
mono_attrs.weight(Weight::BOLD).style(Style::Italic),
85+
),
86+
("Comic Normal ", comic_attrs),
87+
("Comic Bold ", comic_attrs.weight(Weight::BOLD)),
88+
("Comic Italic ", comic_attrs.style(Style::Italic)),
89+
(
90+
"Comic Bold Italic\n",
91+
comic_attrs.weight(Weight::BOLD).style(Style::Italic),
92+
),
93+
("R", attrs.color(Color::rgb(0xFF, 0x00, 0x00))),
94+
("A", attrs.color(Color::rgb(0xFF, 0x7F, 0x00))),
95+
("I", attrs.color(Color::rgb(0xFF, 0xFF, 0x00))),
96+
("N", attrs.color(Color::rgb(0x00, 0xFF, 0x00))),
97+
("B", attrs.color(Color::rgb(0x00, 0x00, 0xFF))),
98+
("O", attrs.color(Color::rgb(0x4B, 0x00, 0x82))),
99+
("W ", attrs.color(Color::rgb(0x94, 0x00, 0xD3))),
100+
("Red ", attrs.color(Color::rgb(0xFF, 0x00, 0x00))),
101+
("Orange ", attrs.color(Color::rgb(0xFF, 0x7F, 0x00))),
102+
("Yellow ", attrs.color(Color::rgb(0xFF, 0xFF, 0x00))),
103+
("Green ", attrs.color(Color::rgb(0x00, 0xFF, 0x00))),
104+
("Blue ", attrs.color(Color::rgb(0x00, 0x00, 0xFF))),
105+
("Indigo ", attrs.color(Color::rgb(0x4B, 0x00, 0x82))),
106+
("Violet ", attrs.color(Color::rgb(0x94, 0x00, 0xD3))),
107+
("U", attrs.color(Color::rgb(0x94, 0x00, 0xD3))),
108+
("N", attrs.color(Color::rgb(0x4B, 0x00, 0x82))),
109+
("I", attrs.color(Color::rgb(0x00, 0x00, 0xFF))),
110+
("C", attrs.color(Color::rgb(0x00, 0xFF, 0x00))),
111+
("O", attrs.color(Color::rgb(0xFF, 0xFF, 0x00))),
112+
("R", attrs.color(Color::rgb(0xFF, 0x7F, 0x00))),
113+
("N\n", attrs.color(Color::rgb(0xFF, 0x00, 0x00))),
114+
(
115+
"生活,삶,जिंदगी 😀 FPS\n",
131116
attrs.color(Color::rgb(0xFF, 0x00, 0x00)),
132-
)],
117+
),
133118
];
134-
for &line in lines {
135-
let mut line_text = String::new();
136-
let mut attrs_list = AttrsList::new(attrs);
137-
for &(text, attrs) in line {
138-
let start = line_text.len();
139-
line_text.push_str(text);
140-
let end = line_text.len();
141-
attrs_list.add_span(start..end, attrs);
142-
}
143-
editor
144-
.buffer_mut()
145-
.lines
146-
.push(BufferLine::new(line_text, attrs_list, Shaping::Advanced));
147-
}
119+
120+
editor
121+
.buffer_mut()
122+
.set_rich_text(spans.iter().copied(), Shaping::Advanced);
148123

149124
let mut swash_cache = SwashCache::new();
150125

0 commit comments

Comments
 (0)