mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 22:01:47 +03:00
shaper: micro-optimize some of the harfbuzz stuff
Probably not super effective compared to all the Vec stuff going on in here, but it can't hurt.
This commit is contained in:
parent
2ed3cbe313
commit
70ec166076
@ -68,6 +68,7 @@ pub struct HarfbuzzShaper {
|
|||||||
lib: ftwrap::Library,
|
lib: ftwrap::Library,
|
||||||
metrics: RefCell<HashMap<MetricsKey, FontMetrics>>,
|
metrics: RefCell<HashMap<MetricsKey, FontMetrics>>,
|
||||||
features: Vec<harfbuzz::hb_feature_t>,
|
features: Vec<harfbuzz::hb_feature_t>,
|
||||||
|
lang: harfbuzz::hb_language_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
@ -112,6 +113,8 @@ impl HarfbuzzShaper {
|
|||||||
fonts.push(RefCell::new(None));
|
fonts.push(RefCell::new(None));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lang = harfbuzz::language_from_string("en")?;
|
||||||
|
|
||||||
let features: Vec<harfbuzz::hb_feature_t> = config
|
let features: Vec<harfbuzz::hb_feature_t> = config
|
||||||
.harfbuzz_features
|
.harfbuzz_features
|
||||||
.iter()
|
.iter()
|
||||||
@ -124,6 +127,7 @@ impl HarfbuzzShaper {
|
|||||||
lib,
|
lib,
|
||||||
metrics: RefCell::new(HashMap::new()),
|
metrics: RefCell::new(HashMap::new()),
|
||||||
features,
|
features,
|
||||||
|
lang,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +170,7 @@ impl HarfbuzzShaper {
|
|||||||
let mut buf = harfbuzz::Buffer::new()?;
|
let mut buf = harfbuzz::Buffer::new()?;
|
||||||
buf.set_script(harfbuzz::hb_script_t::HB_SCRIPT_LATIN);
|
buf.set_script(harfbuzz::hb_script_t::HB_SCRIPT_LATIN);
|
||||||
buf.set_direction(harfbuzz::hb_direction_t::HB_DIRECTION_LTR);
|
buf.set_direction(harfbuzz::hb_direction_t::HB_DIRECTION_LTR);
|
||||||
buf.set_language(harfbuzz::language_from_string("en")?);
|
buf.set_language(self.lang);
|
||||||
buf.add_str(s);
|
buf.add_str(s);
|
||||||
buf.set_cluster_level(
|
buf.set_cluster_level(
|
||||||
harfbuzz::hb_buffer_cluster_level_t::HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES,
|
harfbuzz::hb_buffer_cluster_level_t::HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES,
|
||||||
@ -223,18 +227,18 @@ impl HarfbuzzShaper {
|
|||||||
// and they're handy to have for debugging
|
// and they're handy to have for debugging
|
||||||
// purposes too.
|
// purposes too.
|
||||||
let mut info_clusters: Vec<Vec<Info>> = Vec::with_capacity(s.len());
|
let mut info_clusters: Vec<Vec<Info>> = Vec::with_capacity(s.len());
|
||||||
let mut info_iter = hb_infos.iter().enumerate().peekable();
|
let mut info_iter = hb_infos.iter().zip(positions.iter()).peekable();
|
||||||
while let Some((i, info)) = info_iter.next() {
|
while let Some((info, pos)) = info_iter.next() {
|
||||||
let next_pos = info_iter
|
let next_pos = info_iter
|
||||||
.peek()
|
.peek()
|
||||||
.map(|(_, info)| info.cluster as usize)
|
.map(|(info, _)| info.cluster as usize)
|
||||||
.unwrap_or(s.len());
|
.unwrap_or(s.len());
|
||||||
|
|
||||||
let info = Info {
|
let info = Info {
|
||||||
cluster: info.cluster as usize,
|
cluster: info.cluster as usize,
|
||||||
len: next_pos - info.cluster as usize,
|
len: next_pos - info.cluster as usize,
|
||||||
codepoint: info.codepoint,
|
codepoint: info.codepoint,
|
||||||
pos: &positions[i],
|
pos,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref mut cluster) = info_clusters.last_mut() {
|
if let Some(ref mut cluster) = info_clusters.last_mut() {
|
||||||
|
Loading…
Reference in New Issue
Block a user