dfrg / swash

Font introspection, complex text shaping and glyph rendering.
Apache License 2.0
657 stars 38 forks source link

Tab ('\t') doesn't match `ClusterInfo` #49

Open s0l0ist opened 7 months ago

s0l0ist commented 7 months ago

I am trying to match on the whitespace enum, but it appears that parsing any kind of tab (unicode, control, etc) doesn't appear to match the Whitespace::Tab variant.

Code to reproduce:

let font_size = 16.;
let mut shape_context = ShapeContext::new();
let mut shaper = shape_context
    .builder(*font_ref)
    .script(Script::Latin)
    .size(font_size)
    .direction(Direction::LeftToRight)
    .build();

// 4 variants of how to input a `tab`
shaper.add_str("\t\u{0009}  \u{2B7E}");

shaper.shape_with(|glyph_cluster| {
    let info = glyph_cluster.info;
    println!("got INFO: '{:?}'", info.0);
    println!("got whitespace: '{:?}'", info.whitespace());
});

What it does:

got INFO: '0'
got whitespace: 'None'
got INFO: '0'
got whitespace: 'None'
got INFO: '0'
got whitespace: 'None'
got INFO: '0'
got whitespace: 'None'

What I expect it to do:

got INFO: '7'
got whitespace: 'Tab'
got INFO: '7'
got whitespace: 'Tab'
got INFO: '7'
got whitespace: 'Tab'
got INFO: '7'
got whitespace: 'Tab'

I am using the Roboto-Regular.ttf font.