Files
LLeMbas-TTY/wezterm-gui/src/shapecache.rs
T
Wez Furlong 0324ff66f0 wezterm: add experimental_bidi config option and very basic bidi
This commit is larger than it appears to due fanout from threading
through bidi parameters.  The main changes are:

* When clustering cells, add an additional phase to resolve embedding
  levels and further sub-divide a cluster based on the resolved bidi
  runs; this is where we get the direction for a run and this needs
  to be passed through to the shaper.
* When doing bidi, the forced cluster boundary hack that we use to
  de-ligature when cursoring through text needs to be disabled,
  otherwise the cursor appears to push/rotate the text in that
  cluster when moving through it! We'll need to find a different
  way to handle shading the cursor that eliminates the original
  cursor/ligature/black issue.
* In the shaper, the logic for coalescing unresolved runs for font
  fallback assumed LTR and needed to be adjusted to cluster RTL.
  That meant also computing a little index of codepoint lengths.
* Added `experimental_bidi` boolean option that defaults to false.
  When enabled, it activates the bidi processing phase in clustering
  with a strong hint that the paragraph is LTR.

This implementation is incomplete and/or wrong for a number of cases:

* The config option should probably allow specifying the paragraph
  direction hint to use by default.
* https://terminal-wg.pages.freedesktop.org/bidi/recommendation/paragraphs.html
  recommends that bidi be applied to logical lines, not physical
  lines (or really: ranges within physical lines) that we're doing
  at the moment
* The paragraph direction hint should be overridden by cell attributes
  and other escapes; see 85a6b178cf

and probably others.

However, as of this commit, if you `experimental_bidi=true` then

```
echo This is RTL -> عربي فارسی bidi
```

(that text was sourced from:
https://github.com/microsoft/terminal/issues/538#issuecomment-677017322)

then wezterm will display the text in the same order as the text
renders in Chrome for that github comment.

```
; ./target/debug/wezterm --config experimental_bidi=false ls-fonts --text "عربي فارسی ->"
LeftToRight
 0 ع    \u{639}      x_adv=8  glyph=300  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 2 ر    \u{631}      x_adv=3.78125 glyph=273  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 4 ب    \u{628}      x_adv=4  glyph=244  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 6 ي    \u{64a}      x_adv=4  glyph=363  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 8      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 9 ف    \u{641}      x_adv=11 glyph=328  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
11 ا    \u{627}      x_adv=4  glyph=240  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
13 ر    \u{631}      x_adv=3.78125 glyph=273  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
15 س    \u{633}      x_adv=10 glyph=278  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
17 ی    \u{6cc}      x_adv=4  glyph=664  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
19      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
20 -    \u{2d}       x_adv=8  glyph=276  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
21 >    \u{3e}       x_adv=8  glyph=338  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
```

```
; ./target/debug/wezterm --config experimental_bidi=true ls-fonts --text "عربي فارسی ->"
RightToLeft
17 ی    \u{6cc}      x_adv=9  glyph=906  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
15 س    \u{633}      x_adv=10 glyph=277  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
13 ر    \u{631}      x_adv=4.78125 glyph=272  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
11 ا    \u{627}      x_adv=4  glyph=241  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 9 ف    \u{641}      x_adv=5  glyph=329  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 8      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 6 ي    \u{64a}      x_adv=9  glyph=904  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 4 ب    \u{628}      x_adv=4  glyph=243  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 2 ر    \u{631}      x_adv=5  glyph=273  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
 0 ع    \u{639}      x_adv=6  glyph=301  wezterm.font(".Geeza Pro Interface", {weight="Regular", stretch="Normal", italic=false})
                                      /System/Library/Fonts/GeezaPro.ttc index=2 variation=0, CoreText
LeftToRight
 0      \u{20}       x_adv=8  glyph=2    wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 1 -    \u{2d}       x_adv=8  glyph=480  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
 2 >    \u{3e}       x_adv=8  glyph=470  wezterm.font("Operator Mono SSm Lig", {weight="DemiLight", stretch="Normal", italic=false})
                                      /Users/wez/.fonts/OperatorMonoSSmLig-Medium.otf, FontDirs
;
```

refs: https://github.com/wez/wezterm/issues/784
2022-01-25 09:00:53 -07:00

704 lines
23 KiB
Rust

use crate::glyphcache::CachedGlyph;
use crate::utilsprites::RenderMetrics;
use ::window::bitmaps::Texture2d;
use config::TextStyle;
use std::rc::Rc;
use termwiz::cellcluster::CellCluster;
use wezterm_font::shaper::GlyphInfo;
use wezterm_font::units::*;
#[derive(PartialEq, Eq, Hash)]
pub struct ShapeCacheKey {
pub style: TextStyle,
pub text: String,
}
#[derive(Debug, PartialEq)]
pub struct GlyphPosition {
pub glyph_idx: u32,
pub num_cells: u8,
pub x_offset: PixelLength,
pub bearing_x: f32,
pub bitmap_pixel_width: u32,
}
#[derive(Debug)]
pub struct ShapedInfo<T>
where
T: Texture2d,
T: std::fmt::Debug,
{
pub glyph: Rc<CachedGlyph<T>>,
pub pos: GlyphPosition,
}
impl<T> ShapedInfo<T>
where
T: Texture2d,
T: std::fmt::Debug,
{
/// Process the results from the shaper.
/// Ideally this would not be needed, but the shaper doesn't
/// merge certain forms of ligatured cluster, and won't merge
/// certain combining sequences for which no glyph could be
/// found for the resultant grapheme.
/// This function's goal is to handle those two cases.
pub fn process(
render_metrics: &RenderMetrics,
cluster: &CellCluster,
infos: &[GlyphInfo],
glyphs: &[Rc<CachedGlyph<T>>],
) -> Vec<ShapedInfo<T>> {
let mut pos: Vec<Option<ShapedInfo<T>>> = Vec::with_capacity(infos.len());
let mut x = 0.;
let mut prior_info: Option<&GlyphInfo> = None;
let cell_width = render_metrics.cell_size.width as f64;
let simple_mode = !config::configuration().experimental_shape_post_processing;
for (info, glyph) in infos.iter().zip(glyphs.iter()) {
// info.num_cells accounts for ligatures that have combined
// two or more single width cells into one glyph
let info_num_cells = info
.num_cells
.max(cluster.byte_to_cell_width(info.cluster as usize));
if simple_mode {
pos.push(Some(ShapedInfo {
pos: GlyphPosition {
glyph_idx: info.glyph_pos,
bitmap_pixel_width: glyph
.texture
.as_ref()
.map_or(0, |t| t.coords.width() as u32),
num_cells: info_num_cells,
x_offset: info.x_offset,
bearing_x: glyph.bearing_x.get() as f32,
},
glyph: Rc::clone(glyph),
}));
continue;
}
let glyph_width = (info.x_advance - glyph.bearing_x).get().ceil();
let x_offset = info.x_offset.get();
let bearing_x = glyph.bearing_x.get();
let idx = (((x + x_offset)
// Only jump cells if the width of this one is large enough.
// This is important because operator mono italic's `_`
// glyph is 1 pixel wider than the computed cell width
+ (if bearing_x.abs() > cell_width {
bearing_x
} else {
0.
}))
/ cell_width)
.floor() as usize;
if idx >= pos.len() {
pos.resize_with(idx + 1, || None);
}
if let Some(prior) = prior_info.take() {
if prior.cluster == info.cluster {
// This is a tricky case: if we have a cluster such as
// 1F470 1F3FF 200D 2640 (woman with veil: dark skin tone)
// and the font doesn't define a glyph for it, the shaper
// may give us a sequence of three output clusters, each
// comprising: veil, skin tone and female respectively.
// Those all have the same info.cluster which
// means that they all resolve to the same cell_idx.
// In this case, the cluster is logically a single cell,
// and the best presentation is of the veil, so we pick
// that one and ignore the rest of the glyphs that map to
// this same cell.
// Ideally we'd overlay this with a "something is broken"
// glyph in the corner.
prior_info.replace(info);
continue;
}
}
prior_info.replace(info);
if glyph.texture.is_some() {
if let Some(Some(existing)) = pos.get(idx) {
log::warn!(
"idx={} is already assigned to {:#?} in: {:#?}. infos={:#?}, glyphs={:#?}",
idx,
existing,
pos,
infos,
glyphs
);
}
let bitmap_pixel_width = glyph
.texture
.as_ref()
.map_or(0, |t| t.coords.width() as u32);
let num_cells = if info_num_cells == 1
// Only adjust the cell count if this glyph is wide enough
&& glyph_width > (1.5 * render_metrics.cell_size.width as f64)
{
(glyph_width / render_metrics.cell_size.width as f64).ceil() as u8
} else {
info_num_cells
};
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()
} else {
glyph.bearing_x.get()
};
pos[idx].replace(ShapedInfo {
glyph: Rc::clone(&glyph),
pos: GlyphPosition {
glyph_idx: info.glyph_pos,
num_cells,
x_offset: info.x_offset,
bearing_x: bearing_x as f32,
bitmap_pixel_width,
},
});
} else if info.is_space {
pos[idx].replace(ShapedInfo {
pos: GlyphPosition {
glyph_idx: info.glyph_pos,
bitmap_pixel_width: glyph
.texture
.as_ref()
.map_or(0, |t| t.coords.width() as u32),
num_cells: info_num_cells,
x_offset: info.x_offset,
bearing_x: glyph.bearing_x.get() as f32,
},
glyph: Rc::clone(glyph),
});
}
x += info.x_advance.get();
}
// log::info!("{:#?}\n{:#?}\n{:#?}", infos, glyphs, pos);
pos.into_iter().filter_map(|n| n).collect()
}
}
/// We'd like to avoid allocating when resolving from the cache
/// so this is the borrowed version of ShapeCacheKey.
/// It's a bit involved to make this work; more details can be
/// found in the excellent guide here:
/// <https://github.com/sunshowers/borrow-complex-key-example/blob/master/src/lib.rs>
#[derive(Copy, Debug, Clone, PartialEq, Eq, Hash)]
pub struct BorrowedShapeCacheKey<'a> {
pub style: &'a TextStyle,
pub text: &'a str,
}
impl<'a> BorrowedShapeCacheKey<'a> {
pub fn to_owned(&self) -> ShapeCacheKey {
ShapeCacheKey {
style: self.style.clone(),
text: self.text.to_owned(),
}
}
}
pub trait ShapeCacheKeyTrait {
fn key<'k>(&'k self) -> BorrowedShapeCacheKey<'k>;
}
impl ShapeCacheKeyTrait for ShapeCacheKey {
fn key<'k>(&'k self) -> BorrowedShapeCacheKey<'k> {
BorrowedShapeCacheKey {
style: &self.style,
text: &self.text,
}
}
}
impl<'a> ShapeCacheKeyTrait for BorrowedShapeCacheKey<'a> {
fn key<'k>(&'k self) -> BorrowedShapeCacheKey<'k> {
*self
}
}
impl<'a> std::borrow::Borrow<dyn ShapeCacheKeyTrait + 'a> for ShapeCacheKey {
fn borrow(&self) -> &(dyn ShapeCacheKeyTrait + 'a) {
self
}
}
impl<'a> std::borrow::Borrow<dyn ShapeCacheKeyTrait + 'a> for lru::KeyRef<ShapeCacheKey> {
fn borrow(&self) -> &(dyn ShapeCacheKeyTrait + 'a) {
let k: &ShapeCacheKey = self.borrow();
k
}
}
impl<'a> PartialEq for (dyn ShapeCacheKeyTrait + 'a) {
fn eq(&self, other: &Self) -> bool {
self.key().eq(&other.key())
}
}
impl<'a> Eq for (dyn ShapeCacheKeyTrait + 'a) {}
impl<'a> std::hash::Hash for (dyn ShapeCacheKeyTrait + 'a) {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.key().hash(state)
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::glyphcache::GlyphCache;
use crate::shapecache::{GlyphPosition, ShapedInfo};
use crate::utilsprites::RenderMetrics;
use config::{FontAttributes, TextStyle};
use k9::assert_equal as assert_eq;
use std::rc::Rc;
use termwiz::cell::CellAttributes;
use termwiz::surface::{Line, SEQ_ZERO};
use wezterm_bidi::Direction;
use wezterm_font::{FontConfiguration, LoadedFont};
fn cluster_and_shape<T>(
render_metrics: &RenderMetrics,
glyph_cache: &mut GlyphCache<T>,
style: &TextStyle,
font: &Rc<LoadedFont>,
text: &str,
) -> Vec<GlyphPosition>
where
T: Texture2d,
T: std::fmt::Debug,
{
let line = Line::from_text(text, &CellAttributes::default(), SEQ_ZERO);
eprintln!("{:?}", line);
let cell_clusters = line.cluster(None, None);
assert_eq!(cell_clusters.len(), 1);
let cluster = &cell_clusters[0];
let infos = font
.shape(&cluster.text, || {}, |_| {}, None, Direction::LeftToRight)
.unwrap();
let glyphs = infos
.iter()
.map(|info| {
let cell_idx = cluster.byte_to_cell_idx(info.cluster as usize);
let num_cells = cluster.byte_to_cell_width(info.cluster as usize);
let followed_by_space = match line.cells().get(cell_idx + 1) {
Some(cell) => cell.str() == " ",
None => false,
};
glyph_cache
.cached_glyph(
info,
&style,
followed_by_space,
font,
render_metrics,
num_cells,
)
.unwrap()
})
.collect::<Vec<_>>();
eprintln!("infos: {:#?}", infos);
eprintln!("glyphs: {:#?}", glyphs);
ShapedInfo::process(render_metrics, &cluster, &infos, &glyphs)
.into_iter()
.map(|p| p.pos)
.collect()
}
#[test]
fn ligatures_fira() {
config::use_test_configuration();
let _ = pretty_env_logger::formatted_builder()
.is_test(true)
.filter_level(log::LevelFilter::Trace)
.try_init();
let config = config::configuration();
if !config.experimental_shape_post_processing {
return;
}
let mut config: config::Config = (*config).clone();
config.font = TextStyle {
font: vec![FontAttributes::new("Fira Code")],
foreground: None,
};
config.font_rules.clear();
config.compute_extra_defaults(None);
config::use_this_configuration(config.clone());
let fonts = Rc::new(
FontConfiguration::new(
None,
config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize,
)
.unwrap(),
);
let render_metrics = RenderMetrics::new(&fonts).unwrap();
let mut glyph_cache = GlyphCache::new_in_memory(&fonts, 128).unwrap();
let style = TextStyle::default();
let font = fonts.resolve_font(&style).unwrap();
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "a..."),
vec![
GlyphPosition {
glyph_idx: 180,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 7,
},
GlyphPosition {
glyph_idx: 637,
num_cells: 3,
x_offset: PixelLength::new(0.0),
bearing_x: 4.0,
bitmap_pixel_width: 16,
},
]
);
}
#[test]
fn bench_shaping() {
config::use_test_configuration();
// let mut glyph_cache = GlyphCache::new_in_memory(&fonts, 128, &render_metrics).unwrap();
// let render_metrics = RenderMetrics::new(&fonts).unwrap();
benchmarking::warm_up();
for &n in &[100, 1000, 10_000] {
let bench_result = benchmarking::measure_function(move |measurer| {
let text: String = (0..n).map(|_| ' ').collect();
let fonts = Rc::new(
FontConfiguration::new(
None,
config::configuration()
.dpi
.unwrap_or_else(|| ::window::default_dpi())
as usize,
)
.unwrap(),
);
let style = TextStyle::default();
let font = fonts.resolve_font(&style).unwrap();
let line = Line::from_text(&text, &CellAttributes::default(), SEQ_ZERO);
let cell_clusters = line.cluster(None, None);
let cluster = &cell_clusters[0];
measurer.measure(|| {
let _x = font
.shape(&cluster.text, || {}, |_| {}, None, Direction::LeftToRight)
.unwrap();
// println!("{:?}", &x[0..2]);
});
})
.unwrap();
println!("{}: {:?}", n, bench_result.elapsed());
}
}
#[test]
fn ligatures_jetbrains() {
config::use_test_configuration();
let _ = pretty_env_logger::formatted_builder()
.is_test(true)
.filter_level(log::LevelFilter::Trace)
.try_init();
let config = config::configuration();
if !config.experimental_shape_post_processing {
return;
}
let fonts = Rc::new(
FontConfiguration::new(
None,
config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize,
)
.unwrap(),
);
let render_metrics = RenderMetrics::new(&fonts).unwrap();
let mut glyph_cache = GlyphCache::new_in_memory(&fonts, 128).unwrap();
let style = TextStyle::default();
let font = fonts.resolve_font(&style).unwrap();
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "ab"),
vec![
GlyphPosition {
glyph_idx: 180,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 7,
},
GlyphPosition {
glyph_idx: 205,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 6,
},
]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "a b"),
vec![
GlyphPosition {
glyph_idx: 180,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 7,
},
GlyphPosition {
glyph_idx: 686,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 0,
},
GlyphPosition {
glyph_idx: 205,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 6,
},
]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "a..."),
vec![
GlyphPosition {
glyph_idx: 180,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 7,
},
GlyphPosition {
glyph_idx: 637,
num_cells: 3,
x_offset: PixelLength::new(0.0),
bearing_x: 4.0,
bitmap_pixel_width: 16,
},
]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "e_or_"),
vec![
GlyphPosition {
glyph_idx: 216,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 6,
},
GlyphPosition {
glyph_idx: 610,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 8,
},
GlyphPosition {
glyph_idx: 279,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 6,
},
GlyphPosition {
glyph_idx: 308,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 6,
},
GlyphPosition {
glyph_idx: 610,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 8,
},
]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "a b"),
vec![
GlyphPosition {
glyph_idx: 180,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 7,
},
GlyphPosition {
glyph_idx: 686,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 0,
},
GlyphPosition {
glyph_idx: 686,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 0,
},
GlyphPosition {
glyph_idx: 205,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 6,
},
]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "<-"),
vec![GlyphPosition {
glyph_idx: 1065,
num_cells: 2,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 14,
}]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "<>"),
vec![GlyphPosition {
glyph_idx: 1089,
num_cells: 2,
x_offset: PixelLength::new(0.0),
bearing_x: 2.0,
bitmap_pixel_width: 12,
}]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "|=>"),
vec![GlyphPosition {
glyph_idx: 1040,
num_cells: 3,
x_offset: PixelLength::new(0.0),
bearing_x: 2.0,
bitmap_pixel_width: 21,
}]
);
let block_bottom_one_eighth = "\u{2581}";
assert_eq!(
cluster_and_shape(
&render_metrics,
&mut glyph_cache,
&style,
&font,
block_bottom_one_eighth
),
vec![GlyphPosition {
glyph_idx: 790,
num_cells: 1,
x_offset: PixelLength::new(0.0),
bearing_x: 0.0,
bitmap_pixel_width: 8,
}]
);
let powerline_extra_honeycomb = "\u{e0cc}";
assert_eq!(
cluster_and_shape(
&render_metrics,
&mut glyph_cache,
&style,
&font,
powerline_extra_honeycomb,
),
vec![GlyphPosition {
glyph_idx: 32,
num_cells: 2,
x_offset: PixelLength::new(0.0),
bearing_x: 7.0,
bitmap_pixel_width: 15,
}]
);
assert_eq!(
cluster_and_shape(&render_metrics, &mut glyph_cache, &style, &font, "<!--"),
vec![GlyphPosition {
glyph_idx: 1071,
num_cells: 4,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0,
bitmap_pixel_width: 30,
}]
);
let deaf_man_medium_light_skin_tone = "\u{1F9CF}\u{1F3FC}\u{200D}\u{2642}\u{FE0F}";
println!(
"deaf_man_medium_light_skin_tone: {}",
deaf_man_medium_light_skin_tone
);
assert_eq!(
cluster_and_shape(
&render_metrics,
&mut glyph_cache,
&style,
&font,
deaf_man_medium_light_skin_tone
),
vec![GlyphPosition {
glyph_idx: 298,
num_cells: 2,
x_offset: PixelLength::new(0.0),
bearing_x: 1.0666667,
bitmap_pixel_width: 14,
}]
);
let england_flag = "\u{1F3F4}\u{E0067}\u{E0062}\u{E0065}\u{E006E}\u{E0067}\u{E007F}";
println!("england_flag: {}", england_flag);
assert_eq!(
cluster_and_shape(
&render_metrics,
&mut glyph_cache,
&style,
&font,
england_flag
),
vec![GlyphPosition {
glyph_idx: 1583,
num_cells: 2,
x_offset: PixelLength::new(0.0),
bearing_x: 0.,
bitmap_pixel_width: 14,
}]
);
}
}