Skip to content

Commit 98c6768

Browse files
committed
update cosmic-text to 0.10.0
1 parent cc771a0 commit 98c6768

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

crates/bevy_text/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.12.0-dev" }
2626

2727
# other
2828
anyhow = "1.0.4"
29-
cosmic-text = "0.8.0"
29+
cosmic-text = "0.10.0"
3030
thiserror = "1.0"
3131
serde = {version = "1", features = ["derive"]}
3232
sys-locale = "0.3.0"

crates/bevy_text/src/font_atlas_set.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ impl FontAtlasSet {
9393
swash_cache: &mut cosmic_text::SwashCache,
9494
layout_glyph: &cosmic_text::LayoutGlyph,
9595
) -> Result<GlyphAtlasInfo, TextError> {
96+
let physical_glyph = layout_glyph.physical((0., 0.), 1.0);
97+
9698
let font_atlases = self
9799
.font_atlases
98-
.entry(layout_glyph.cache_key.font_size_bits)
100+
.entry(physical_glyph.cache_key.font_size_bits)
99101
.or_insert_with(|| {
100102
vec![FontAtlas::new(
101103
textures,
@@ -105,12 +107,12 @@ impl FontAtlasSet {
105107
});
106108

107109
let (glyph_texture, offset) =
108-
Self::get_outlined_glyph_texture(font_system, swash_cache, layout_glyph);
110+
Self::get_outlined_glyph_texture(font_system, swash_cache, &physical_glyph);
109111
let add_char_to_font_atlas = |atlas: &mut FontAtlas| -> bool {
110112
atlas.add_glyph(
111113
textures,
112114
texture_atlases,
113-
layout_glyph.cache_key,
115+
physical_glyph.cache_key,
114116
&glyph_texture,
115117
offset,
116118
)
@@ -132,15 +134,17 @@ impl FontAtlasSet {
132134
if !font_atlases.last_mut().unwrap().add_glyph(
133135
textures,
134136
texture_atlases,
135-
layout_glyph.cache_key,
137+
physical_glyph.cache_key,
136138
&glyph_texture,
137139
offset,
138140
) {
139-
return Err(TextError::FailedToAddGlyph(layout_glyph.cache_key.glyph_id));
141+
return Err(TextError::FailedToAddGlyph(
142+
physical_glyph.cache_key.glyph_id,
143+
));
140144
}
141145
}
142146

143-
Ok(self.get_glyph_atlas_info(layout_glyph.cache_key).unwrap())
147+
Ok(self.get_glyph_atlas_info(physical_glyph.cache_key).unwrap())
144148
}
145149

146150
pub fn get_glyph_atlas_info(
@@ -173,10 +177,10 @@ impl FontAtlasSet {
173177
pub fn get_outlined_glyph_texture(
174178
font_system: &mut cosmic_text::FontSystem,
175179
swash_cache: &mut cosmic_text::SwashCache,
176-
layout_glyph: &cosmic_text::LayoutGlyph,
180+
physical_glyph: &cosmic_text::PhysicalGlyph,
177181
) -> (Image, IVec2) {
178182
let image = swash_cache
179-
.get_image_uncached(font_system, layout_glyph.cache_key)
183+
.get_image_uncached(font_system, physical_glyph.cache_key)
180184
// TODO: don't unwrap
181185
.unwrap();
182186

crates/bevy_text/src/pipeline.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,20 @@ impl TextPipeline {
196196
let prev_attrs_list =
197197
std::mem::replace(&mut attrs_list, AttrsList::new(Attrs::new()));
198198
let prev_line_string = std::mem::take(&mut line_string);
199-
buffer
200-
.lines
201-
.push(BufferLine::new(prev_line_string, prev_attrs_list));
199+
//TODO: is basic the correct way?
200+
buffer.lines.push(BufferLine::new(
201+
prev_line_string,
202+
prev_attrs_list,
203+
cosmic_text::Shaping::Basic,
204+
));
202205
} else {
203206
// finalize the final line
204-
buffer.lines.push(BufferLine::new(line_string, attrs_list));
207+
//TODO: is basic the correct way?
208+
buffer.lines.push(BufferLine::new(
209+
line_string,
210+
attrs_list,
211+
cosmic_text::Shaping::Basic,
212+
));
205213
break;
206214
}
207215
}
@@ -304,8 +312,10 @@ impl TextPipeline {
304312
}
305313
};
306314

315+
let physical_glyph = layout_glyph.physical((0.,0.),1. );
316+
307317
let atlas_info = font_atlas_set
308-
.get_glyph_atlas_info(layout_glyph.cache_key)
318+
.get_glyph_atlas_info(physical_glyph.cache_key)
309319
.map(Ok)
310320
.unwrap_or_else(|| {
311321
font_atlas_set.add_glyph_to_atlas(texture_atlases, textures, font_system, swash_cache, layout_glyph)
@@ -327,8 +337,8 @@ impl TextPipeline {
327337
let glyph_size = Vec2::new(glyph_rect.width(), glyph_rect.height());
328338

329339
// offset by half the size because the origin is center
330-
let x = glyph_size.x / 2.0 + left + layout_glyph.x_int as f32;
331-
let y = line_y + layout_glyph.y_int as f32 - top + glyph_size.y / 2.0;
340+
let x = glyph_size.x / 2.0 + left + physical_glyph.x as f32;
341+
let y = line_y + physical_glyph.y as f32 - top + glyph_size.y / 2.0;
332342
// TODO: use cosmic text's implementation (per-BufferLine alignment) as it will be editor aware
333343
// see https://github.com/pop-os/cosmic-text/issues/130 (currently bugged)
334344
let x = x + match text_alignment {

0 commit comments

Comments
 (0)