remove cluster from GlyphPosition
This simplifies the code and avoids a call to reverse the cluster to the cell index.
This commit is contained in:
1 parent
fc4c165ca3
commit
313d130deb
2 files changed
+20
-53
No files matched your search
@@ -16,7 +16,6 @@ pub struct ShapeCacheKey {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct GlyphPosition {
|
||||
pub glyph_idx: u32,
|
||||
pub cluster: u32,
|
||||
pub num_cells: u8,
|
||||
pub x_offset: PixelLength,
|
||||
pub bearing_x: f32,
|
||||
@@ -66,7 +65,6 @@ where
|
||||
.texture
|
||||
.as_ref()
|
||||
.map_or(0, |t| t.coords.width() as u32),
|
||||
cluster: info.cluster,
|
||||
num_cells: info.num_cells,
|
||||
x_offset: info.x_offset,
|
||||
bearing_x: glyph.bearing_x.get() as f32,
|
||||
@@ -141,12 +139,6 @@ where
|
||||
} else {
|
||||
info.num_cells
|
||||
};
|
||||
let cluster = if num_cells > info.num_cells {
|
||||
info.cluster
|
||||
.saturating_sub((num_cells - info.num_cells) as u32)
|
||||
} else {
|
||||
info.cluster
|
||||
};
|
||||
let bearing_x = if num_cells > info.num_cells && glyph.bearing_x.get() < 0. {
|
||||
((num_cells - info.num_cells) as f64 * render_metrics.cell_size.width as f64)
|
||||
+ glyph.bearing_x.get()
|
||||
@@ -157,7 +149,6 @@ where
|
||||
glyph: Rc::clone(&glyph),
|
||||
pos: GlyphPosition {
|
||||
glyph_idx: info.glyph_pos,
|
||||
cluster,
|
||||
num_cells,
|
||||
x_offset: info.x_offset,
|
||||
bearing_x: bearing_x as f32,
|
||||
@@ -172,7 +163,6 @@ where
|
||||
.texture
|
||||
.as_ref()
|
||||
.map_or(0, |t| t.coords.width() as u32),
|
||||
cluster: info.cluster,
|
||||
num_cells: info.num_cells,
|
||||
x_offset: info.x_offset,
|
||||
bearing_x: glyph.bearing_x.get() as f32,
|
||||
@@ -351,7 +341,6 @@ mod test {
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 180,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -359,7 +348,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 637,
|
||||
cluster: 1,
|
||||
num_cells: 3,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 4.0,
|
||||
@@ -438,7 +426,6 @@ mod test {
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 180,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -446,7 +433,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 205,
|
||||
cluster: 1,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -460,7 +446,6 @@ mod test {
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 180,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -468,7 +453,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 686,
|
||||
cluster: 1,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -476,7 +460,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 205,
|
||||
cluster: 2,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -490,7 +473,6 @@ mod test {
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 180,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -498,7 +480,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 637,
|
||||
cluster: 1,
|
||||
num_cells: 3,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 4.0,
|
||||
@@ -512,7 +493,6 @@ mod test {
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 216,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -520,7 +500,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 610,
|
||||
cluster: 1,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -528,7 +507,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 279,
|
||||
cluster: 2,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -536,7 +514,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 308,
|
||||
cluster: 3,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -544,7 +521,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 610,
|
||||
cluster: 4,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -558,7 +534,6 @@ mod test {
|
||||
vec![
|
||||
GlyphPosition {
|
||||
glyph_idx: 180,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -566,7 +541,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 686,
|
||||
cluster: 1,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -574,7 +548,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 686,
|
||||
cluster: 2,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -582,7 +555,6 @@ mod test {
|
||||
},
|
||||
GlyphPosition {
|
||||
glyph_idx: 205,
|
||||
cluster: 3,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -595,7 +567,6 @@ mod test {
|
||||
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "<-"),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 1065,
|
||||
cluster: 0,
|
||||
num_cells: 2,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -607,7 +578,6 @@ mod test {
|
||||
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "<>"),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 1089,
|
||||
cluster: 0,
|
||||
num_cells: 2,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 2.0,
|
||||
@@ -619,7 +589,6 @@ mod test {
|
||||
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "|=>"),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 1040,
|
||||
cluster: 0,
|
||||
num_cells: 3,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 2.0,
|
||||
@@ -638,7 +607,6 @@ mod test {
|
||||
),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 790,
|
||||
cluster: 0,
|
||||
num_cells: 1,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.0,
|
||||
@@ -657,7 +625,6 @@ mod test {
|
||||
),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 32,
|
||||
cluster: 0,
|
||||
num_cells: 2,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 7.0,
|
||||
@@ -669,7 +636,6 @@ mod test {
|
||||
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "<!--"),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 1071,
|
||||
cluster: 0,
|
||||
num_cells: 4,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0,
|
||||
@@ -692,7 +658,6 @@ mod test {
|
||||
),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 298,
|
||||
cluster: 0,
|
||||
num_cells: 2,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 1.0666667,
|
||||
@@ -712,7 +677,6 @@ mod test {
|
||||
),
|
||||
vec![GlyphPosition {
|
||||
glyph_idx: 1583,
|
||||
cluster: 0,
|
||||
num_cells: 2,
|
||||
x_offset: PixelLength::new(0.0),
|
||||
bearing_x: 0.,
|
||||
|
||||
@@ -660,6 +660,7 @@ impl super::TermWindow {
|
||||
);
|
||||
|
||||
let mut last_cell_idx = 0;
|
||||
let mut current_idx = 0;
|
||||
|
||||
// Basic cache of computed data from prior cluster to avoid doing the same
|
||||
// work for space separated clusters with the same style
|
||||
@@ -744,7 +745,6 @@ impl super::TermWindow {
|
||||
self.cached_cluster_shape(style_params.style, &cluster, &gl_state, params.line)?;
|
||||
|
||||
for info in glyph_info.iter() {
|
||||
let cell_idx = cluster.byte_to_cell_idx(info.pos.cluster as usize);
|
||||
let glyph = &info.glyph;
|
||||
|
||||
let top = ((PixelLength::new(self.render_metrics.cell_size.height as f64)
|
||||
@@ -759,7 +759,7 @@ impl super::TermWindow {
|
||||
// a single cell per glyph but combining characters, ligatures
|
||||
// and emoji can be 2 or more cells wide.
|
||||
for glyph_idx in 0..info.pos.num_cells as usize {
|
||||
let cell_idx = cell_idx + glyph_idx;
|
||||
let cell_idx = current_idx + glyph_idx;
|
||||
|
||||
if cell_idx >= num_cols {
|
||||
// terminal line data is wider than the window.
|
||||
@@ -768,7 +768,7 @@ impl super::TermWindow {
|
||||
break;
|
||||
}
|
||||
|
||||
last_cell_idx = cell_idx;
|
||||
last_cell_idx = current_idx;
|
||||
|
||||
let ComputeCellFgBgResult {
|
||||
fg_color: glyph_color,
|
||||
@@ -807,20 +807,22 @@ impl super::TermWindow {
|
||||
}
|
||||
|
||||
if self.config.custom_block_glyphs && glyph_idx == 0 {
|
||||
if let Some(block) = BlockKey::from_cell(¶ms.line.cells()[cell_idx]) {
|
||||
self.populate_block_quad(
|
||||
block,
|
||||
gl_state,
|
||||
quads,
|
||||
cell_idx,
|
||||
¶ms,
|
||||
hsv,
|
||||
cursor_shape,
|
||||
glyph_color,
|
||||
style_params.underline_color,
|
||||
bg_color,
|
||||
)?;
|
||||
continue;
|
||||
if let Some(cell) = params.line.cells().get(cell_idx) {
|
||||
if let Some(block) = BlockKey::from_cell(cell) {
|
||||
self.populate_block_quad(
|
||||
block,
|
||||
gl_state,
|
||||
quads,
|
||||
cell_idx,
|
||||
¶ms,
|
||||
hsv,
|
||||
cursor_shape,
|
||||
glyph_color,
|
||||
style_params.underline_color,
|
||||
bg_color,
|
||||
)?;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -890,6 +892,7 @@ impl super::TermWindow {
|
||||
params.cursor_border_color
|
||||
});
|
||||
}
|
||||
current_idx += info.pos.num_cells as usize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user