Skip to content

Commit 2d325dd

Browse files
committed
fix clippy
1 parent 6b3c0cb commit 2d325dd

13 files changed

Lines changed: 453 additions & 46 deletions

File tree

Cargo.lock

Lines changed: 105 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ default = []
1616
serialization = ["dep:serde"]
1717

1818
[dependencies]
19-
cosmic-text = "0.14"
19+
cosmic-text = "0.16.0"
2020
ahash = "0.8.12"
2121
smol_str = "0.3"
2222
serde = { version = "1.0.219", features = ["derive"], optional = true }

examples/text.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ impl<'a> App<'a> {
133133
horizontal_alignment: HorizontalTextAlignment::Start,
134134
vertical_alignment: VerticalTextAlignment::Start,
135135
wrap: Some(TextWrap::Wrap),
136-
font_family: FontFamily::SansSerif,
136+
font_family: FontFamily::Name("Arial".into()),
137+
weight: protextinator::style::Weight::NORMAL,
138+
letter_spacing: None,
137139
};
138140

139141
// Create or update the text state
@@ -191,6 +193,8 @@ impl<'a> App<'a> {
191193
vertical_alignment: VerticalTextAlignment::Start,
192194
wrap: Some(TextWrap::Wrap),
193195
font_family: FontFamily::Serif,
196+
weight: protextinator::style::Weight::NORMAL,
197+
letter_spacing: None,
194198
};
195199

196200
// Create or update the stats text state
@@ -262,11 +266,11 @@ impl<'a> App<'a> {
262266
}
263267
let upload_time = t_upload_start.elapsed();
264268

265-
println!(
266-
"rasterize: {} µs, load_texture: {} µs",
267-
raster_time.as_micros(),
268-
upload_time.as_micros()
269-
);
269+
// println!(
270+
// "rasterize: {} µs, load_texture: {} µs",
271+
// raster_time.as_micros(),
272+
// upload_time.as_micros()
273+
// );
270274

271275
// TODO: cache shapes
272276
let text_shape_id = renderer.add_shape(

src/buffer_utils.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::byte_cursor::ByteCursor;
22
use crate::math::{Point, Rect, Size};
3-
use crate::style::{TextStyle, TextWrap, VerticalTextAlignment};
3+
use crate::style::{FontFamily, TextStyle, TextWrap, VerticalTextAlignment};
44
use crate::text_params::TextParams;
55
use cosmic_text::{Attrs, Buffer, Cursor, Edit, Editor, FontSystem, Shaping};
66

@@ -120,13 +120,15 @@ pub(crate) fn update_buffer(
120120
params: &TextParams,
121121
buffer: &mut Buffer,
122122
font_system: &mut FontSystem,
123+
font_family: &FontFamily,
123124
) -> Size {
124125
let text_style = &params.style();
125126
let font_color = text_style.font_color;
126127
let horizontal_alignment = text_style.horizontal_alignment;
127128
let wrap = text_style.wrap.unwrap_or_default();
128129
let text_area_size = params.size();
129-
let font_family = &text_style.font_family;
130+
let weight = text_style.weight;
131+
let letter_spacing = text_style.letter_spacing;
130132
let metadata = params.metadata();
131133
let old_scroll = buffer.scroll();
132134

@@ -140,14 +142,37 @@ pub(crate) fn update_buffer(
140142
// Apply scale for shaping to device pixels
141143
buffer.set_size(font_system, Some(text_area_size.x * scale_factor), None);
142144

145+
// match font_family {
146+
// FontFamily::Name(name) => {
147+
// println!("Using font family: {:?}", name);
148+
// }
149+
// FontFamily::SansSerif => {}
150+
// FontFamily::Serif => {}
151+
// FontFamily::Monospace => {}
152+
// FontFamily::Cursive => {}
153+
// FontFamily::Fantasy => {}
154+
// }
155+
156+
if params.original_text() == "Filobus" {
157+
println!("Font family: {:?}", font_family);
158+
}
159+
160+
let mut attrs = Attrs::new()
161+
.color(font_color.into())
162+
.family(font_family.to_fontdb_family())
163+
.weight(weight.into())
164+
.metadata(metadata);
165+
166+
if let Some(letter_spacing) = letter_spacing {
167+
attrs = attrs.letter_spacing(letter_spacing.0 * scale_factor);
168+
}
169+
143170
buffer.set_text(
144171
font_system,
145172
params.text_for_internal_use(),
146-
&Attrs::new()
147-
.color(font_color.into())
148-
.family(font_family.to_fontdb_family())
149-
.metadata(metadata),
173+
&attrs,
150174
Shaping::Advanced,
175+
None,
151176
);
152177

153178
let mut buffer_measurement = Size::default();
@@ -162,12 +187,14 @@ pub(crate) fn update_buffer(
162187
None,
163188
// TODO: what is the default tab width? Make it configurable?
164189
2,
190+
cosmic_text::Hinting::Enabled,
165191
)
166192
.iter()
167193
{
168-
buffer_measurement.y += layout_line
194+
let line_height = layout_line
169195
.line_height_opt
170196
.unwrap_or(text_style.line_height_pt() * scale_factor);
197+
buffer_measurement.y += line_height;
171198
buffer_measurement.x = buffer_measurement.x.max(layout_line.w);
172199
}
173200
}
@@ -187,6 +214,7 @@ pub(crate) fn update_buffer(
187214
None,
188215
// TODO: what is the default tab width? Make it configurable?
189216
2,
217+
cosmic_text::Hinting::Enabled,
190218
);
191219
}
192220
}

0 commit comments

Comments
 (0)